mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-22 13:10:29 +00:00
5fcb307270
contractHandler() parses the request body against the shared request schema, answering 400 like the server's Zod pipe on a body it would refuse, and the mock's answer against the response schema, failing on a factory that drifted. The trips, budget, places, todo, tags and categories, day notes, packing, reservations and assignments handlers and the vacay plan and colour updates use it wherever shared has a schema; the offline bundle and the other vacay routes have none yet and stay plain. The typed bodies showed where the old handlers echoed request shapes back as stored rows: payers and members are no longer echoed into a budget item, and checked and is_private come back as 0/1 the way the server stores them.
47 lines
1.3 KiB
TypeScript
47 lines
1.3 KiB
TypeScript
import {
|
|
assignmentCreateRequestSchema,
|
|
assignmentMoveRequestSchema,
|
|
assignmentReorderRequestSchema,
|
|
assignmentSchema,
|
|
} from '@trek/shared';
|
|
import { HttpResponse } from 'msw';
|
|
import { z } from 'zod';
|
|
import { buildAssignment, buildPlace } from '../../factories';
|
|
import { contractHandler } from '../contract';
|
|
|
|
export const assignmentsHandlers = [
|
|
contractHandler(
|
|
'post',
|
|
'/api/trips/:id/days/:dayId/assignments',
|
|
{ request: assignmentCreateRequestSchema, response: z.object({ assignment: assignmentSchema }) },
|
|
({ params, body }) => {
|
|
const placeId = Number(body.place_id);
|
|
const place = buildPlace({ id: placeId, trip_id: Number(params.id) });
|
|
const assignment = buildAssignment({ day_id: Number(params.dayId), place_id: placeId, place, order_index: 0 });
|
|
return { assignment };
|
|
}
|
|
),
|
|
|
|
contractHandler('delete', '/api/trips/:id/days/:dayId/assignments/:assignmentId', {}, () =>
|
|
HttpResponse.json({ success: true })
|
|
),
|
|
|
|
contractHandler(
|
|
'put',
|
|
'/api/trips/:id/days/:dayId/assignments/reorder',
|
|
{ request: assignmentReorderRequestSchema },
|
|
() => ({
|
|
success: true,
|
|
})
|
|
),
|
|
|
|
contractHandler(
|
|
'put',
|
|
'/api/trips/:id/assignments/:assignmentId/move',
|
|
{ request: assignmentMoveRequestSchema },
|
|
() => ({
|
|
success: true,
|
|
})
|
|
),
|
|
];
|