Photos for vehicles

This commit is contained in:
Eric Gullickson
2025-12-15 21:39:51 -06:00
parent e1c48b7a26
commit 263fc434b0
17 changed files with 745 additions and 58 deletions

View File

@@ -4,7 +4,7 @@
*/
import { Pool } from 'pg';
import { Vehicle, CreateVehicleRequest } from '../domain/vehicles.types';
import { Vehicle, CreateVehicleRequest, VehicleImageMeta } from '../domain/vehicles.types';
export class VehiclesRepository {
constructor(private pool: Pool) {}
@@ -156,11 +156,50 @@ export class VehiclesRepository {
SET is_active = false, deleted_at = NOW()
WHERE id = $1
`;
const result = await this.pool.query(query, [id]);
return (result.rowCount ?? 0) > 0;
}
async updateImageMeta(id: string, userId: string, meta: VehicleImageMeta | null): Promise<Vehicle | null> {
if (meta === null) {
const query = `
UPDATE vehicles SET
image_storage_bucket = NULL,
image_storage_key = NULL,
image_file_name = NULL,
image_content_type = NULL,
image_file_size = NULL,
updated_at = NOW()
WHERE id = $1 AND user_id = $2
RETURNING *
`;
const result = await this.pool.query(query, [id, userId]);
return result.rows[0] ? this.mapRow(result.rows[0]) : null;
}
const query = `
UPDATE vehicles SET
image_storage_bucket = $1,
image_storage_key = $2,
image_file_name = $3,
image_content_type = $4,
image_file_size = $5,
updated_at = NOW()
WHERE id = $6 AND user_id = $7
RETURNING *
`;
const result = await this.pool.query(query, [
meta.imageStorageBucket,
meta.imageStorageKey,
meta.imageFileName,
meta.imageContentType,
meta.imageFileSize,
id,
userId
]);
return result.rows[0] ? this.mapRow(result.rows[0]) : null;
}
private mapRow(row: any): Vehicle {
return {
@@ -183,6 +222,11 @@ export class VehiclesRepository {
deletedAt: row.deleted_at,
createdAt: row.created_at,
updatedAt: row.updated_at,
imageStorageBucket: row.image_storage_bucket,
imageStorageKey: row.image_storage_key,
imageFileName: row.image_file_name,
imageContentType: row.image_content_type,
imageFileSize: row.image_file_size,
};
}
}