fix: return raw rows from enhanced repository methods (refs #47)
All checks were successful
Deploy to Staging / Build Images (pull_request) Successful in 2m28s
Deploy to Staging / Deploy to Staging (pull_request) Successful in 29s
Deploy to Staging / Verify Staging (pull_request) Successful in 7s
Deploy to Staging / Notify Staging Ready (pull_request) Successful in 6s
Deploy to Staging / Notify Staging Failure (pull_request) Has been skipped
All checks were successful
Deploy to Staging / Build Images (pull_request) Successful in 2m28s
Deploy to Staging / Deploy to Staging (pull_request) Successful in 29s
Deploy to Staging / Verify Staging (pull_request) Successful in 7s
Deploy to Staging / Notify Staging Ready (pull_request) Successful in 6s
Deploy to Staging / Notify Staging Failure (pull_request) Has been skipped
Enhanced repository methods were incorrectly calling mapRow() which converts snake_case to camelCase, but the service's toEnhancedResponse() expects raw database rows with snake_case properties. This caused "Invalid time value" errors when calling new Date(row.created_at). Fixed methods: - createEnhanced - findByVehicleIdEnhanced - findByUserIdEnhanced - findByIdEnhanced - getPreviousLogByOdometer - getLatestLogForVehicle - updateEnhanced 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -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