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