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

117 lines (116 loc) 2.86 kB
import { WIKI_OBJECT_TYPE as w, WIKI_PAGE as m, WIKI_PAGE_ID as k } from "../../../utils/APIConstants.js"; import { ObjectType as d } from "@sage-bionetworks/synapse-types"; import { http as s, HttpResponse as a } from "msw"; import { mockWikiPages as f, MOCK_WIKI_ETAG as l } from "../../mockWiki.js"; import { mockWikiPageKeys as P } from "../../mockWikiPageKey.js"; import { MOCK_USER_ID as p } from "../../user/mock_user_profile.js"; import I from "../util/BasicMockedCrudService.js"; const c = [ d.ENTITY, d.ACCESS_REQUIREMENT, d.EVALUATION ], u = new I({ initialData: f, idField: "id", autoGenerateId: !0 }), y = new I({ initialData: P }); function j(e) { return c.map((i) => s.get( `${e}${k( i, ":ownerObjectId", ":wikiPageId" )}`, ({ params: t }) => { let o = 404, r = { concreteType: "org.sagebionetworks.repo.model.ErrorResponse", reason: `Mock Service worker could not find a wiki page with ID ${t.wikiPageId}` }; const n = u.getOneById( t.wikiPageId ); return n && (r = n, o = 200), a.json(r, { status: o }); } )); } const W = (e) => [ ...j(e), s.get( `${e}/repo/v1/:objectType/:objectId/wiki2/:wikiId/attachmenthandles`, () => { const t = { list: [] }; return a.json(t, { status: 200 }); } ) ]; function E(e) { return c.map((i) => s.get( `${e}${w( i )}/:ownerObjectId/wikikey`, ({ params: t }) => { let o = 404, r = { concreteType: "org.sagebionetworks.repo.model.ErrorResponse", reason: `Mock Service worker could not find a WikiPageKey for ${i} ${t.ownerObjectId}` }; const n = y.getOneByPredicate( (g) => g.ownerObjectId === t.ownerObjectId ); return n && (r = n, o = 200), a.json(r, { status: o }); } )); } function O(e) { return c.map((i) => s.post( `${e}${m(i, ":ownerObjectId")}`, async ({ request: t }) => { const o = await t.json(), r = (/* @__PURE__ */ new Date()).toISOString(), n = u.create({ ...o, etag: l, createdBy: String(p), createdOn: r, modifiedBy: String(p), modifiedOn: r }); return a.json(n, { status: 201 }); } )); } function S(e) { return c.map((i) => s.put( `${e}${k( i, ":ownerObjectId", ":wikiPageId" )}`, async ({ request: t }) => { const o = await t.json(), r = u.update( o.id, o, "replace" ); return a.json(r, { status: 201 }); } )); } function R(e) { return [ ...W(e), ...E(e), ...O(e), ...S(e) ]; } export { O as createWikiPage, R as getAllWikiHandlers, E as getRootWikiPageKeyHandler, W as getWikiHandlers, j as getWikiPage, S as updateWikiPage }; //# sourceMappingURL=wikiHandlers.js.map