mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-06-22 06:41:46 +00:00
404981505c
Drive the client typecheck to zero without any/ts-ignore: convert the tripId route param to a number once at the page boundary so it matches the numeric props and store actions it feeds, fix trip.name -> trip.title (the wire field is title, so the old read rendered blank in the files/offline views), and tighten the scattered handler-arity, DOM-cast and untyped-payload sites. No runtime behaviour change.
39 lines
1.6 KiB
TypeScript
39 lines
1.6 KiB
TypeScript
import { http, HttpResponse } from 'msw';
|
|
import { buildBudgetItem } from '../../factories';
|
|
|
|
export const budgetHandlers = [
|
|
http.get('/api/trips/:id/budget', ({ params }) => {
|
|
return HttpResponse.json({
|
|
items: [buildBudgetItem({ trip_id: Number(params.id) })],
|
|
});
|
|
}),
|
|
|
|
http.post('/api/trips/:id/budget', async ({ params, request }) => {
|
|
const body = await request.json() as Record<string, unknown>;
|
|
const item = buildBudgetItem({ trip_id: Number(params.id), ...body });
|
|
return HttpResponse.json({ item });
|
|
}),
|
|
|
|
http.put('/api/trips/:id/budget/:itemId', async ({ params, request }) => {
|
|
const body = await request.json() as Record<string, unknown>;
|
|
const item = buildBudgetItem({ id: Number(params.itemId), trip_id: Number(params.id), ...body });
|
|
return HttpResponse.json({ item });
|
|
}),
|
|
|
|
http.delete('/api/trips/:id/budget/:itemId', () => {
|
|
return HttpResponse.json({ success: true });
|
|
}),
|
|
|
|
http.put('/api/trips/:id/budget/:itemId/members', async ({ params, request }) => {
|
|
const body = await request.json() as { user_ids: number[] };
|
|
const members = body.user_ids.map(uid => ({ user_id: uid, paid: 0, username: `user${uid}` }));
|
|
const item = buildBudgetItem({ id: Number(params.itemId), trip_id: Number(params.id), persons: body.user_ids.length, members });
|
|
return HttpResponse.json({ members, item });
|
|
}),
|
|
|
|
http.put('/api/trips/:id/budget/:itemId/members/:userId/paid', async ({ params, request }) => {
|
|
const body = await request.json() as { paid: boolean };
|
|
return HttpResponse.json({ success: true, paid: body.paid });
|
|
}),
|
|
];
|