fix: Short VIN Storage - Issue #1
All checks were successful
Deploy to Staging / Build Images (push) Successful in 4m31s
Deploy to Staging / Deploy to Staging (push) Successful in 36s
Deploy to Staging / Verify Staging (push) Successful in 5s
Deploy to Staging / Notify Staging Ready (push) Successful in 5s
Deploy to Staging / Notify Staging Failure (push) Has been skipped

This commit is contained in:
Eric Gullickson
2026-01-01 10:05:56 -06:00
parent 7631d961c5
commit f79fda79b9
9 changed files with 109 additions and 29 deletions

View File

@@ -114,20 +114,29 @@ export class VehiclesController {
try {
const userId = (request as any).user.sub;
const { id } = request.params;
const vehicle = await this.vehiclesService.updateVehicle(id, request.body, userId);
return reply.code(200).send(vehicle);
} catch (error: any) {
logger.error('Error updating vehicle', { error, vehicleId: request.params.id, userId: (request as any).user?.sub });
if (error.message === 'Vehicle not found' || error.message === 'Unauthorized') {
return reply.code(404).send({
error: 'Not Found',
message: 'Vehicle not found'
});
}
if (error.message === 'Invalid VIN format' ||
error.message === 'Invalid VIN format for pre-1981 vehicle' ||
error.message === 'Vehicle with this VIN already exists') {
return reply.code(400).send({
error: 'Bad Request',
message: error.message
});
}
return reply.code(500).send({
error: 'Internal server error',
message: 'Failed to update vehicle'

View File

@@ -17,11 +17,20 @@ export const createVehicleSchema = z.object({
});
export const updateVehicleSchema = z.object({
vin: z.string().max(17).optional(),
year: z.number().min(1900).max(new Date().getFullYear() + 1).optional(),
make: z.string().max(100).optional(),
model: z.string().max(100).optional(),
engine: z.string().max(100).optional(),
transmission: z.string().max(100).optional(),
trimLevel: z.string().max(100).optional(),
driveType: z.string().max(50).optional(),
fuelType: z.string().max(50).optional(),
nickname: z.string().min(1).max(100).optional(),
color: z.string().min(1).max(50).optional(),
licensePlate: z.string().min(1).max(20).optional(),
odometerReading: z.number().min(0).max(9999999).optional(),
}).strict();
});
export const vehicleIdSchema = z.object({
id: z.string().uuid('Invalid vehicle ID format'),