mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-06 10:44:23 +00:00
feat(server): adopt zod DTOs for the day and accommodation body contracts
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import {
|
||||
reservationCreateRequestSchema,
|
||||
reservationPositionsRequestSchema,
|
||||
accommodationCreateBodySchema,
|
||||
accommodationCreateRequestSchema,
|
||||
} from './reservation.schema';
|
||||
|
||||
@@ -45,4 +46,11 @@ describe('accommodationCreateRequestSchema', () => {
|
||||
).toBe(true);
|
||||
expect(accommodationCreateRequestSchema.safeParse({ place_id: 2 }).success).toBe(false);
|
||||
});
|
||||
|
||||
it('body variant keeps missing refs schema-valid (bespoke controller 400)', () => {
|
||||
// The REST endpoint requires all three refs, but their absence is answered
|
||||
// by the controller's bespoke 400 body — the pipe must not pre-empt it.
|
||||
expect(accommodationCreateBodySchema.safeParse({ place_id: 2 }).success).toBe(true);
|
||||
expect(accommodationCreateBodySchema.safeParse({ check_in: 5 }).success).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -182,6 +182,20 @@ export const accommodationCreateRequestSchema = z.object({
|
||||
});
|
||||
export type AccommodationCreateRequest = z.infer<typeof accommodationCreateRequestSchema>;
|
||||
|
||||
/**
|
||||
* REST body variant of the create contract: the three refs are required by the
|
||||
* endpoint but optional on the wire — their absence answers with the bespoke
|
||||
* controller 400 ('place_id, start_day_id, and end_day_id are required'),
|
||||
* which the validation pipe must not pre-empt. The plugin RPC host keeps the
|
||||
* strict schema above (missing refs are BAD_PARAMS there).
|
||||
*/
|
||||
export const accommodationCreateBodySchema = accommodationCreateRequestSchema.partial({
|
||||
place_id: true,
|
||||
start_day_id: true,
|
||||
end_day_id: true,
|
||||
});
|
||||
export type AccommodationCreateBody = z.infer<typeof accommodationCreateBodySchema>;
|
||||
|
||||
export const accommodationUpdateRequestSchema = open;
|
||||
export type AccommodationUpdateRequest = z.infer<typeof accommodationUpdateRequestSchema>;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user