UNPKG

ruch

Version:

Revolutionary React TypeScript CLI with hexagonal architecture & AI-powered development assistance. Create maintainable, scalable applications with domain-driven design and integrated AI tooling.

92 lines (75 loc) 2.51 kB
// Order Domain MSW Handlers // This file contains Mock Service Worker handlers for order domain API endpoints import { http, HttpResponse } from 'msw'; import { mockOrderData } from '../../../domains/order/mocks/mockData'; const API_BASE = '/api/order'; export const orderHandlers = [ // GET /order - List all order items http.get(`${API_BASE}`, () => { return HttpResponse.json(mockOrderData.getAll()); }), // GET /order/:id - Get single order item http.get(`${API_BASE}/:id`, ({ params }) => { const { id } = params; const item = mockOrderData.getById(id as string); if (!item) { return new HttpResponse(null, { status: 404, statusText: 'Order not found' }); } return HttpResponse.json(item); }), // POST /order - Create new order item http.post(`${API_BASE}`, async ({ request }) => { try { const newItem = await request.json(); const createdItem = mockOrderData.create(newItem); return HttpResponse.json(createdItem, { status: 201 }); } catch (error) { return new HttpResponse(null, { status: 400, statusText: 'Invalid order data' }); } }), // PUT /order/:id - Update order item http.put(`${API_BASE}/:id`, async ({ params, request }) => { const { id } = params; try { const updates = await request.json(); const updatedItem = mockOrderData.update(id as string, updates); if (!updatedItem) { return new HttpResponse(null, { status: 404, statusText: 'Order not found' }); } return HttpResponse.json(updatedItem); } catch (error) { return new HttpResponse(null, { status: 400, statusText: 'Invalid order data' }); } }), // DELETE /order/:id - Delete order item http.delete(`${API_BASE}/:id`, ({ params }) => { const { id } = params; const deleted = mockOrderData.delete(id as string); if (!deleted) { return new HttpResponse(null, { status: 404, statusText: 'Order not found' }); } return new HttpResponse(null, { status: 204 }); }), // Add more order-specific endpoints here // Example: GET /order/:id/relationships // http.get(`${API_BASE}/:id/relationships`, ({ params }) => { // const { id } = params; // const relationships = mockOrderData.getRelationships(id as string); // return HttpResponse.json(relationships); // }), ];