mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-04 09:54:14 +00:00
feat(server): adopt zod DTOs for the reservation body contracts
ReservationsController's 4 grandfathered @Body() params now validate through the global ZodValidationPipe (createZodDto over the existing @trek/shared schemas); their allow-list entries are removed (the boot gate rejects stale entries). The bespoke 400 bodies (Title is required / positions must be an array / user_ids must be an array) become the pipe's field envelope, and non-numeric traveler ids now 400 instead of being silently dropped. reservationPositionsRequestSchema is loosened to the real wire contract: day_plan_position is optional (the legacy route never validated position items and an absent value binds NULL) — pinned by RESV-006. AccommodationsController stays grandfathered until the dayService migration.
This commit is contained in:
@@ -20,14 +20,17 @@ describe('reservationCreateRequestSchema', () => {
|
||||
});
|
||||
|
||||
describe('reservationPositionsRequestSchema', () => {
|
||||
it('requires positions with id + day_plan_position', () => {
|
||||
it('requires positions with an id; day_plan_position stays optional (legacy wire tolerance)', () => {
|
||||
expect(
|
||||
reservationPositionsRequestSchema.safeParse({
|
||||
positions: [{ id: 1, day_plan_position: 0 }],
|
||||
day_id: 3,
|
||||
}).success,
|
||||
).toBe(true);
|
||||
expect(reservationPositionsRequestSchema.safeParse({ positions: [{ id: 1 }] }).success).toBe(false);
|
||||
// The legacy route accepted items without day_plan_position (binds NULL) —
|
||||
// RESV-006 pins this on the server side.
|
||||
expect(reservationPositionsRequestSchema.safeParse({ positions: [{ id: 1 }] }).success).toBe(true);
|
||||
expect(reservationPositionsRequestSchema.safeParse({ positions: [{}] }).success).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -162,7 +162,10 @@ export const reservationTravelersRequestSchema = z.object({
|
||||
export type ReservationTravelersRequest = z.infer<typeof reservationTravelersRequestSchema>;
|
||||
|
||||
export const reservationPositionsRequestSchema = z.object({
|
||||
positions: z.array(z.object({ id: z.number(), day_plan_position: z.number() })),
|
||||
// day_plan_position is optional on the wire: the legacy route never
|
||||
// validated position items, and an absent value binds NULL (clears the
|
||||
// stored position) — pinned by the server integration suite (RESV-006).
|
||||
positions: z.array(z.object({ id: z.number(), day_plan_position: z.number().optional() })),
|
||||
day_id: z.union([z.number(), z.string()]).nullable().optional(),
|
||||
});
|
||||
export type ReservationPositionsRequest = z.infer<typeof reservationPositionsRequestSchema>;
|
||||
|
||||
Reference in New Issue
Block a user