mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-28 07:30:04 +00:00
feat(server): adopt zod DTOs for the day and accommodation body contracts
This commit is contained in:
@@ -6,11 +6,11 @@ import { z } from 'zod';
|
||||
* Day + day-note API contract — single source of truth for the
|
||||
* /api/trips/:tripId/days and /api/trips/:tripId/days/:dayId/notes endpoints.
|
||||
*
|
||||
* Trip-scoped, both gated by the 'day_edit' permission. The legacy routes
|
||||
* (server/src/routes/days.ts + routes/dayNotes.ts) wrap dayService /
|
||||
* dayNoteService. Day rows (with their assignments) are wide and DB-derived, so
|
||||
* list responses stay open. Day notes cap text at 500 and time at 150 chars
|
||||
* (the legacy validateStringLengths middleware) — reproduced in the controller.
|
||||
* Trip-scoped, both gated by the 'day_edit' permission. Served by the Nest
|
||||
* DaysController / DayNotesController (server/src/nest/days/). Day rows (with
|
||||
* their assignments) are wide and DB-derived, so list responses stay open. Day
|
||||
* notes cap text at 500 and time at 150 chars (the legacy
|
||||
* validateStringLengths middleware) — reproduced in the controller.
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -68,6 +68,16 @@ export const dayUpdateRequestSchema = z.object({
|
||||
});
|
||||
export type DayUpdateRequest = z.infer<typeof dayUpdateRequestSchema>;
|
||||
|
||||
/**
|
||||
* Whole-day default route mode (#1281). The client always sends
|
||||
* `{ transport_mode: string | null }`; null clears the default. Kept loose (no
|
||||
* enum, no max) — the legacy raw-body route accepted any string.
|
||||
*/
|
||||
export const dayTransportRequestSchema = z.object({
|
||||
transport_mode: z.string().nullable().optional(),
|
||||
});
|
||||
export type DayTransportRequest = z.infer<typeof dayTransportRequestSchema>;
|
||||
|
||||
// `time`/`icon` accept null on the wire: the client's moveDayNote re-sends the
|
||||
// entity fields (both nullable on dayNoteSchema) through create, and an explicit
|
||||
// null time on update means "clear" (the legacy raw-body route accepted both).
|
||||
|
||||
@@ -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