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