Skip to content

Commit 070a4e7

Browse files
Added route
1 parent 2be53a5 commit 070a4e7

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

src/api/routers/participantsRouter.ts

+40
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { isApproverCheck } from '../middleware/approversMiddleware';
2020
import {
2121
addKeyPair,
2222
createApiKey,
23+
disableApiKey,
2324
getApiKeysBySite,
2425
getKeyPairsList,
2526
getSharingList,
@@ -374,6 +375,45 @@ export function createParticipantsRouter() {
374375
}
375376
);
376377

378+
const apiKeyDeleteInputParser = z.object({
379+
keyId: z.string(),
380+
});
381+
participantsRouter.delete(
382+
'/:participantId/apiKey',
383+
async (req: ParticipantRequest, res: Response) => {
384+
const { participant } = req;
385+
if (!participant?.siteId) {
386+
return res.status(400).send('Site id is not set');
387+
}
388+
389+
const { keyId } = apiKeyDeleteInputParser.parse(req.body);
390+
391+
const apiKey = await getApiKey(participant.siteId, keyId);
392+
if (!apiKey) {
393+
return res.status(404).send('KeyId was invalid');
394+
}
395+
396+
const traceId = getTraceId(req);
397+
const currentUser = await findUserByEmail(req.auth?.payload?.email as string);
398+
const auditTrail = await insertManageApiKeyAuditTrail(
399+
participant!,
400+
currentUser!.id,
401+
currentUser!.email,
402+
AuditAction.Delete,
403+
apiKey.name,
404+
apiKey.roles.map((role) => role.roleName),
405+
traceId,
406+
apiKey.key_id
407+
);
408+
409+
await disableApiKey(apiKey.contact);
410+
411+
await updateAuditTrailToProceed(auditTrail.id);
412+
413+
return res.sendStatus(200);
414+
}
415+
);
416+
377417
participantsRouter.get(
378418
'/:participantId/apiRoles',
379419
async (req: ParticipantRequest, res: Response) => {

src/api/services/adminServiceClient.ts

+8
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,14 @@ export const updateApiKeyRoles = async (contact: string, apiRoles: string[]): Pr
113113
});
114114
};
115115

116+
export const disableApiKey = async (contact: string): Promise<void> => {
117+
await adminServiceClient.post('/api/client/disable', null, {
118+
params: {
119+
contact,
120+
},
121+
});
122+
};
123+
116124
export const getVisibleSiteList = async (): Promise<SiteDTO[]> => {
117125
const siteList = await getSiteList();
118126
return siteList.filter((x) => x.visible !== false);

0 commit comments

Comments
 (0)