Skip to content

Commit

Permalink
Utilize new route for admin
Browse files Browse the repository at this point in the history
  • Loading branch information
joshua-smee-ttd committed Dec 5, 2023
1 parent 0db97a0 commit 4ee711d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/api/routers/usersRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { UserRole } from '../entities/User';
import { getLoggers, getTraceId } from '../helpers/loggingHelpers';
import { mapClientTypeToParticipantType } from '../helpers/siteConvertingHelpers';
import { getKcAdminClient } from '../keycloakAdminClient';
import { getSiteList } from '../services/adminServiceClient';
import { getSite, getSiteList } from '../services/adminServiceClient';
import {
assignClientRoleToUser,
deleteUserByEmail,
Expand Down Expand Up @@ -58,8 +58,12 @@ export function createUsersRouter() {

usersRouter.get('/current/participant', async (req: UserRequest, res) => {
const currentParticipant = await Participant.query().findOne({ id: req.user!.participantId });
const sites = await getSiteList();
const currentSite = sites.find((x) => x.id === currentParticipant?.siteId);

const currentSite =
currentParticipant?.siteId === undefined
? undefined
: await getSite(currentParticipant?.siteId);

const allParticipantTypes = await ParticipantType.query();
const result = {
...currentParticipant,
Expand Down
5 changes: 5 additions & 0 deletions src/api/services/adminServiceClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ export const getSiteList = async (): Promise<SiteDTO[]> => {
return response.data;
};

export const getSite = async (siteId: number): Promise<SiteDTO> => {
const response = await adminServiceClient.get<SiteDTO>(`/api/site/${siteId}`);
return response.data;
};

export const getVisibleSiteList = async (): Promise<SiteDTO[]> => {
const siteList = await getSiteList();
return siteList.filter((x) => x.visible !== false);
Expand Down

0 comments on commit 4ee711d

Please sign in to comment.