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

@@ -13,7 +13,7 @@ import { VehicleImageUpload } from './VehicleImageUpload';
const vehicleSchema = z
.object({
vin: z.string().nullable().optional().transform(val => val ?? undefined),
vin: z.string().max(17).nullable().optional().transform(val => val ?? undefined),
year: z.number().min(1950).max(new Date().getFullYear() + 1).nullable().optional(),
make: z.string().nullable().optional(),
model: z.string().nullable().optional(),
@@ -30,11 +30,13 @@ const vehicleSchema = z
.refine(
(data) => {
// Pre-1981 vehicles have no VIN/plate requirement
if (data.year && data.year < 1981) return true;
if (data.year && data.year < 1981) {
return true;
}
const vin = (data.vin || '').trim();
const plate = (data.licensePlate || '').trim();
// Must have either a valid 17-char VIN or a non-empty license plate
// 1981+: Must have either a valid 17-char VIN or a non-empty license plate
if (vin.length === 17) return true;
if (plate.length > 0) return true;
return false;
@@ -46,12 +48,16 @@ const vehicleSchema = z
)
.refine(
(data) => {
// Pre-1981 vehicles have no VIN format requirement
if (data.year && data.year < 1981) return true;
// Pre-1981 vehicles accept any length VIN (1-17 chars)
if (data.year && data.year < 1981) {
const vin = (data.vin || '').trim();
// Empty is fine, or any length up to 17
return vin.length === 0 || (vin.length >= 1 && vin.length <= 17);
}
const vin = (data.vin || '').trim();
const plate = (data.licensePlate || '').trim();
// If VIN provided but not 17 and no plate, fail; if plate exists, allow any VIN (or empty)
// 1981+: If plate exists, allow any VIN (or empty); otherwise VIN must be exactly 17 or empty
if (plate.length > 0) return true;
return vin.length === 17 || vin.length === 0;
},

View File

@@ -41,6 +41,8 @@ export interface CreateVehicleRequest {
}
export interface UpdateVehicleRequest {
vin?: string;
year?: number;
make?: string;
model?: string;
engine?: string;