fix: edit vehicle null fix
All checks were successful
Deploy to Staging / Build Images (push) Successful in 4m32s
Deploy to Staging / Deploy to Staging (push) Successful in 27s
Deploy to Staging / Verify Staging (push) Successful in 6s
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
2025-12-31 15:33:27 -06:00
parent d9cc604137
commit 52f9414fd4
5 changed files with 53 additions and 34 deletions

View File

@@ -39,16 +39,22 @@ export class VehiclesController {
async createVehicle(request: FastifyRequest<{ Body: CreateVehicleBody }>, reply: FastifyReply) {
try {
// Require either a valid 17-char VIN or a non-empty license plate
const vin = request.body?.vin?.trim();
const plate = request.body?.licensePlate?.trim();
const hasValidVin = !!vin && vin.length === 17;
const hasPlate = !!plate && plate.length > 0;
if (!hasValidVin && !hasPlate) {
return reply.code(400).send({
error: 'Bad Request',
message: 'Either a valid 17-character VIN or a license plate is required'
});
// Pre-1981 vehicles have no VIN/plate requirement
const year = request.body?.year;
const isPreModern = year && year < 1981;
if (!isPreModern) {
// Require either a valid 17-char VIN or a non-empty license plate
const vin = request.body?.vin?.trim();
const plate = request.body?.licensePlate?.trim();
const hasValidVin = !!vin && vin.length === 17;
const hasPlate = !!plate && plate.length > 0;
if (!hasValidVin && !hasPlate) {
return reply.code(400).send({
error: 'Bad Request',
message: 'Either a valid 17-character VIN or a license plate is required'
});
}
}
const userId = (request as any).user.sub;