Fix Auth Errors

This commit is contained in:
Eric Gullickson
2025-09-22 10:27:10 -05:00
parent 3588372cef
commit 8fd7973656
19 changed files with 1342 additions and 174 deletions

View File

@@ -286,4 +286,90 @@ export class FuelLogsRepository {
);
return res.rows[0] || null;
}
async updateEnhanced(id: string, data: {
dateTime?: Date;
odometerReading?: number;
tripDistance?: number;
fuelType?: string;
fuelGrade?: string | null;
fuelUnits?: number;
costPerUnit?: number;
locationData?: any;
notes?: string;
}): Promise<any | null> {
const fields = [];
const values = [];
let paramCount = 1;
// Build dynamic update query for enhanced schema
if (data.dateTime !== undefined) {
fields.push(`date_time = $${paramCount++}`);
fields.push(`date = $${paramCount++}`);
values.push(data.dateTime);
values.push(data.dateTime.toISOString().slice(0, 10));
}
if (data.odometerReading !== undefined) {
fields.push(`odometer = $${paramCount++}`);
values.push(data.odometerReading);
}
if (data.tripDistance !== undefined) {
fields.push(`trip_distance = $${paramCount++}`);
values.push(data.tripDistance);
}
if (data.fuelType !== undefined) {
fields.push(`fuel_type = $${paramCount++}`);
values.push(data.fuelType);
}
if (data.fuelGrade !== undefined) {
fields.push(`fuel_grade = $${paramCount++}`);
values.push(data.fuelGrade);
}
if (data.fuelUnits !== undefined) {
fields.push(`fuel_units = $${paramCount++}`);
fields.push(`gallons = $${paramCount++}`); // legacy support
values.push(data.fuelUnits);
values.push(data.fuelUnits);
}
if (data.costPerUnit !== undefined) {
fields.push(`cost_per_unit = $${paramCount++}`);
fields.push(`price_per_gallon = $${paramCount++}`); // legacy support
values.push(data.costPerUnit);
values.push(data.costPerUnit);
}
if (data.locationData !== undefined) {
fields.push(`location_data = $${paramCount++}`);
values.push(data.locationData);
}
if (data.notes !== undefined) {
fields.push(`notes = $${paramCount++}`);
values.push(data.notes);
}
// Recalculate total cost if both fuelUnits and costPerUnit are present
if (data.fuelUnits !== undefined && data.costPerUnit !== undefined) {
fields.push(`total_cost = $${paramCount++}`);
values.push(data.fuelUnits * data.costPerUnit);
}
if (fields.length === 0) {
return this.findByIdEnhanced(id);
}
values.push(id);
const query = `
UPDATE fuel_logs
SET ${fields.join(', ')}, updated_at = NOW()
WHERE id = $${paramCount}
RETURNING *
`;
const result = await this.pool.query(query, values);
if (result.rows.length === 0) {
return null;
}
return result.rows[0];
}
}