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

121 lines (120 loc) 4.04 kB
import { USER_PROFILE_ID as c, USER_PROFILE as p, USER_BUNDLE as m, USER_ID_BUNDLE as E, FAVORITES as $, USER_GROUP_HEADERS_BATCH as R, USER_GROUP_HEADERS as g, PROFILE_IMAGE_PREVIEW as L, NOTIFICATION_EMAIL as P } from "../../../utils/APIConstants.js"; import { TYPE_FILTER as d } from "@sage-bionetworks/synapse-types"; import { http as u, HttpResponse as i } from "msw"; import { mockPaginatedEntityHeaders as U } from "../../entity/mockEntity.js"; import { mockUserData as a, mockUserProfileData as I, mockUserBundle as l } from "../../user/mock_user_profile.js"; import { mockUserGroupData as f } from "../../usergroup/mockUserGroup.js"; const G = (o) => [ /** * Get User Profile by ID */ u.get(`${o}${c(":id")}`, ({ params: t }) => { let r = 404, s = { concreteType: "org.sagebionetworks.repo.model.ErrorResponse", reason: `Mock Service worker could not find a user profile with ID ${t.id}` }; const e = a.find( (n) => n.id.toString() === t.id ); return e && e.userProfile && (s = e.userProfile, r = 200), i.json(s, { status: r }); }), /** * Get the caller's user profile */ u.get(`${o}${p}`, () => { const t = I; return i.json(t, { status: 200 }); }), /** * Get the caller's user bundle */ u.get(`${o}${m}`, () => { const t = l; return i.json(t, { status: 200 }); }), /** * Get a user bundle by ID */ u.get(`${o}${E(":id")}`, ({ params: t }) => { let r = 404, s = { concreteType: "org.sagebionetworks.repo.model.ErrorResponse", reason: `Mock Service worker could not find a user bundle with ID ${t.id}` }; const e = a.find( (n) => n.id.toString() === t.id ); return e && e.userBundle && (s = e.userBundle, r = 200), i.json(s, { status: r }); }), /** * Get the caller's favorites */ u.get(`${o}${$}`, () => i.json(U, { status: 200 })), /** * Get a batch of user group headers */ u.get(`${o}${R}`, ({ request: t }) => { const r = new URL(t.url).searchParams.get("ids").split(","), s = { children: f.filter((e) => r.includes(e.id.toString())).map((e) => e.userGroupHeader) }; return i.json(s, { status: 200 }); }), /** * Get a batch of user profiles */ u.post( `${o}${p}`, async ({ request: t }) => { const r = ((await t.json()).list ?? []).map(String), s = { list: a.filter((e) => r.includes(e.id.toString())).map((e) => e.userProfile).filter( (e) => e != null ) }; return i.json(s, { status: 200 }); } ), /** * Get userGroupHeaders by prefix */ u.get(`${o}${g}`, ({ request: t }) => { const r = (new URL(t.url).searchParams.get("prefix") ?? "").toLowerCase(), s = new URL(t.url).searchParams.get( "typeFilter" ), e = { children: f.filter((n) => !s || s === d.ALL ? !0 : s === d.USERS_ONLY ? n.userGroupHeader.isIndividual : !n.userGroupHeader.isIndividual).filter( (n) => n.userGroupHeader.userName.toLowerCase().startsWith(r) || (n.userGroupHeader.firstName || "").toLowerCase().startsWith(r) || (n.userGroupHeader.displayName || "").toLowerCase().startsWith(r) || (n.userGroupHeader.lastName || "").toLowerCase().startsWith(r) ).map((n) => n.userGroupHeader) }; return i.json(e, { status: 200 }); }), /** * Return a 404 when fetching the profile image */ u.get(`${o}${L(":userId")}`, () => i.json( { reason: "user has no profile image" }, { status: 404 } )), u.get(`${o}${P}`, () => i.json( { email: l.userProfile?.email }, { status: 200 } )), u.get(`${o}/auth/v1/2fa`, () => { const t = { status: "ENABLED" }; return i.json(t, { status: 200 }); }) ]; function N(o, t, r) { return u.get(`${o}${m}`, () => { const e = { ...l, isCertified: t, isVerified: r }; return i.json(e, { status: 200 }); }); } export { N as getCurrentUserCertifiedValidatedHandler, G as getUserProfileHandlers }; //# sourceMappingURL=userProfileHandlers.js.map