MVP Build
This commit is contained in:
32
backend/src/features/vehicles/api/vehicles.validation.ts
Normal file
32
backend/src/features/vehicles/api/vehicles.validation.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* @ai-summary Request validation schemas for vehicles API
|
||||
* @ai-context Uses Zod for runtime validation and type safety
|
||||
*/
|
||||
|
||||
import { z } from 'zod';
|
||||
import { isValidVIN } from '../../../shared-minimal/utils/validators';
|
||||
|
||||
export const createVehicleSchema = z.object({
|
||||
vin: z.string()
|
||||
.length(17, 'VIN must be exactly 17 characters')
|
||||
.refine(isValidVIN, 'Invalid VIN format'),
|
||||
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(),
|
||||
});
|
||||
|
||||
export const updateVehicleSchema = z.object({
|
||||
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'),
|
||||
});
|
||||
|
||||
export type CreateVehicleInput = z.infer<typeof createVehicleSchema>;
|
||||
export type UpdateVehicleInput = z.infer<typeof updateVehicleSchema>;
|
||||
export type VehicleIdInput = z.infer<typeof vehicleIdSchema>;
|
||||
Reference in New Issue
Block a user