UNPKG

synapse-react-client

Version:

[![npm version](https://badge.fury.io/js/synapse-react-client.svg)](https://badge.fury.io/js/synapse-react-client) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettie

76 lines (75 loc) 2.53 kB
import { http as c, HttpResponse as a } from "msw"; import { forumSubscriptions as m, threadSubscriptions as j } from "../../mockSubscription.js"; import { MOCK_USER_ID as f } from "../../user/mock_user_profile.js"; import v from "../util/BasicMockedCrudService.js"; const p = new v({ initialData: [...m, ...j], idField: "subscriptionId", autoGenerateId: !0 }); function l(r, e = "ASC", t = 0, o = 10, n) { const s = p.getAll().filter((i) => r ? i.objectType === r : !0).filter((i) => n ? n.includes(i.objectId) : !0).sort((i, b) => { const d = new Date(b.createdOn).getTime() - new Date(i.createdOn).getTime(); return e === "ASC" ? d : -1 * d; }), u = s.length; return { results: s.slice(t, t + o), totalNumberOfResults: u }; } function g(r) { return [ c.get(`${r}/repo/v1/subscription/all`, ({ request: e }) => { const t = new URL(e.url).searchParams.get( "objectType" ) ?? void 0, o = new URL(e.url).searchParams.get( "sortDirection" ) ?? void 0, n = new URL(e.url).searchParams.get("offset"), s = n ? parseInt(n) : void 0, u = new URL(e.url).searchParams.get("limit"), i = u ? parseInt(u) : void 0, b = l(t ?? void 0, o, s, i); return a.json(b, { status: 200 }); }), c.post( `${r}/repo/v1/subscription/list`, async ({ request: e }) => { const t = await e.json(), o = l( t.objectType, t.sortDirection, void 0, void 0, t.idList ); return a.json(o, { status: 200 }); } ), c.post( `${r}/repo/v1/subscription`, async ({ request: e }) => { const t = await e.json(), o = p.create({ subscriberId: String(f), objectId: t.objectId, objectType: t.objectType, createdOn: (/* @__PURE__ */ new Date()).toISOString() }); return a.json(o, { status: 201 }); } ), c.delete(`${r}/repo/v1/subscription/:id`, ({ params: e }) => { const t = e.id; return p.delete(t), new Response("", { status: 200 }); }), c.post( `${r}/repo/v1/subscription/subscribers`, async ({ request: e }) => { const t = await e.json(), n = { subscribers: p.getMany( (s) => s.objectType === t.objectType && s.objectId === t.objectId ).map((s) => s.subscriberId) }; return a.json(n, { status: 200 }); } ) ]; } export { g as getSubscriptionHandlers }; //# sourceMappingURL=subscriptionHandlers.js.map