fix: Fuel Logs API 500 error - repository snake_case mismatch (#47) #48
@@ -293,7 +293,7 @@ export class FuelLogsRepository {
|
|||||||
data.notes ?? null
|
data.notes ?? null
|
||||||
];
|
];
|
||||||
const res = await this.pool.query(query, values);
|
const res = await this.pool.query(query, values);
|
||||||
return res.rows[0] ? this.mapRow(res.rows[0]) : null;
|
return res.rows[0] ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
async findByVehicleIdEnhanced(vehicleId: string): Promise<any[]> {
|
async findByVehicleIdEnhanced(vehicleId: string): Promise<any[]> {
|
||||||
@@ -301,7 +301,7 @@ export class FuelLogsRepository {
|
|||||||
`SELECT * FROM fuel_logs WHERE vehicle_id = $1 ORDER BY date_time DESC NULLS LAST, date DESC NULLS LAST, created_at DESC`,
|
`SELECT * FROM fuel_logs WHERE vehicle_id = $1 ORDER BY date_time DESC NULLS LAST, date DESC NULLS LAST, created_at DESC`,
|
||||||
[vehicleId]
|
[vehicleId]
|
||||||
);
|
);
|
||||||
return res.rows.map(row => this.mapRow(row));
|
return res.rows;
|
||||||
}
|
}
|
||||||
|
|
||||||
async findByUserIdEnhanced(userId: string): Promise<any[]> {
|
async findByUserIdEnhanced(userId: string): Promise<any[]> {
|
||||||
@@ -309,12 +309,12 @@ export class FuelLogsRepository {
|
|||||||
`SELECT * FROM fuel_logs WHERE user_id = $1 ORDER BY date_time DESC NULLS LAST, date DESC NULLS LAST, created_at DESC`,
|
`SELECT * FROM fuel_logs WHERE user_id = $1 ORDER BY date_time DESC NULLS LAST, date DESC NULLS LAST, created_at DESC`,
|
||||||
[userId]
|
[userId]
|
||||||
);
|
);
|
||||||
return res.rows.map(row => this.mapRow(row));
|
return res.rows;
|
||||||
}
|
}
|
||||||
|
|
||||||
async findByIdEnhanced(id: string): Promise<any | null> {
|
async findByIdEnhanced(id: string): Promise<any | null> {
|
||||||
const res = await this.pool.query(`SELECT * FROM fuel_logs WHERE id = $1`, [id]);
|
const res = await this.pool.query(`SELECT * FROM fuel_logs WHERE id = $1`, [id]);
|
||||||
return res.rows[0] ? this.mapRow(res.rows[0]) : null;
|
return res.rows[0] ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
async getPreviousLogByOdometer(vehicleId: string, odometerReading: number): Promise<any | null> {
|
async getPreviousLogByOdometer(vehicleId: string, odometerReading: number): Promise<any | null> {
|
||||||
@@ -322,7 +322,7 @@ export class FuelLogsRepository {
|
|||||||
`SELECT * FROM fuel_logs WHERE vehicle_id = $1 AND odometer IS NOT NULL AND odometer < $2 ORDER BY odometer DESC LIMIT 1`,
|
`SELECT * FROM fuel_logs WHERE vehicle_id = $1 AND odometer IS NOT NULL AND odometer < $2 ORDER BY odometer DESC LIMIT 1`,
|
||||||
[vehicleId, odometerReading]
|
[vehicleId, odometerReading]
|
||||||
);
|
);
|
||||||
return res.rows[0] ? this.mapRow(res.rows[0]) : null;
|
return res.rows[0] ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
async getLatestLogForVehicle(vehicleId: string): Promise<any | null> {
|
async getLatestLogForVehicle(vehicleId: string): Promise<any | null> {
|
||||||
@@ -330,7 +330,7 @@ export class FuelLogsRepository {
|
|||||||
`SELECT * FROM fuel_logs WHERE vehicle_id = $1 ORDER BY date_time DESC NULLS LAST, date DESC NULLS LAST, created_at DESC LIMIT 1`,
|
`SELECT * FROM fuel_logs WHERE vehicle_id = $1 ORDER BY date_time DESC NULLS LAST, date DESC NULLS LAST, created_at DESC LIMIT 1`,
|
||||||
[vehicleId]
|
[vehicleId]
|
||||||
);
|
);
|
||||||
return res.rows[0] ? this.mapRow(res.rows[0]) : null;
|
return res.rows[0] ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
async updateEnhanced(id: string, data: {
|
async updateEnhanced(id: string, data: {
|
||||||
@@ -416,6 +416,6 @@ export class FuelLogsRepository {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.mapRow(result.rows[0]);
|
return result.rows[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user