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

100 lines (99 loc) 3.27 kB
import { FORUM as m, THREAD as f, FORUM_THREAD as I } from "../../../utils/APIConstants.js"; import { DiscussionFilter as a } from "@sage-bionetworks/synapse-types"; import { http as n, HttpResponse as i } from "msw"; import { mockForums as h, mockDiscussionThreadBundles as w } from "../../discussion/mock_discussion.js"; import R from "../../entity/mockProject.js"; import { MOCK_USER_ID as c } from "../../user/mock_user_profile.js"; import g from "../util/BasicMockedCrudService.js"; const S = new g({ initialData: h, idField: "id", autoGenerateId: !0 }), d = new g({ initialData: w, idField: "id", autoGenerateId: !0 }); function y(s, t) { return d.getMany((e) => e.forumId === s).filter((e) => { switch (t) { case a.NO_FILTER: return !0; case a.DELETED_ONLY: return e.isDeleted; case a.EXCLUDE_DELETED: return !e.isDeleted; } }); } function M(s) { return [ n.get(`${s}${m}/:id`, ({ params: t }) => { let e = 404, r = { concreteType: "org.sagebionetworks.repo.model.ErrorResponse", reason: `MSW could not find a mock forum object with ID ${t.id}` }; const o = S.getOneById(t.id); return o && (e = 200, r = o), i.json(r, { status: e }); }), n.get(`${s}${f}/:id`, ({ params: t }) => { let e = 404, r = { concreteType: "org.sagebionetworks.repo.model.ErrorResponse", reason: `MSW could not find a mock discussion thread bundle object with ID ${t.id}` }; t.id === "messageUrl" && (r = { concreteType: "org.sagebionetworks.repo.model.ErrorResponse", reason: "GET /thread/messageUrl is not yet implemented" }); const o = d.getOneById(t.id); return o && (e = 200, r = o), i.json(r, { status: e }); }), n.post( `${s}${f}`, async ({ request: t }) => { const e = await t.json(), r = d.create({ forumId: e.forumId, projectId: R.id, title: e.title, createdOn: (/* @__PURE__ */ new Date()).toISOString(), createdBy: String(c), modifiedOn: (/* @__PURE__ */ new Date()).toISOString(), etag: "etag", messageKey: "todo key", numberOfViews: 0, numberOfReplies: 0, lastActivity: (/* @__PURE__ */ new Date()).toISOString(), activeAuthors: [String(c)], isEdited: !1, isDeleted: !1, isPinned: !1 }); return i.json(r, { status: 201 }); } ), n.get( `${s}${I(":forumId")}`, ({ params: t, request: e }) => { const r = new URL(e.url).searchParams.get("offset"), o = r ? parseInt(r) : 0, u = new URL(e.url).searchParams.get("limit"), p = u ? parseInt(u) : 10, D = t.filter ?? a.EXCLUDE_DELETED, l = y( t.forumId, D ), E = { results: l.slice(o, o + p), totalNumberOfResults: l.length }; return i.json(E, { status: 200 }); } ), n.get(`${s}${m}/:id/moderators`, () => { const t = { results: [String(c)], totalNumberOfResults: 1 }; return i.json(t, { status: 200 }); }) ]; } export { M as getDiscussionHandlers }; //# sourceMappingURL=discussionHandlers.js.map