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
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:
@@ -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;
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user