From b6369de9a0f8ae3754caa44c136f1c22f326d095 Mon Sep 17 00:00:00 2001 From: Bernardo Vieira Date: Tue, 26 Sep 2023 15:44:41 +0100 Subject: [PATCH] add loanManagerAddress to applications list by authorized users --- packages/api/src/controllers/v2/microcredit/list.ts | 13 +++++++++++++ packages/api/src/routes/v2/microcredit/list.ts | 10 ++++++++-- packages/api/src/validators/microcredit.ts | 4 +++- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/packages/api/src/controllers/v2/microcredit/list.ts b/packages/api/src/controllers/v2/microcredit/list.ts index d9da30304..43d6fc081 100644 --- a/packages/api/src/controllers/v2/microcredit/list.ts +++ b/packages/api/src/controllers/v2/microcredit/list.ts @@ -59,6 +59,19 @@ class MicroCreditController { }); return; } + + if (req.query.loanManagerAddress) { + if (!config.admin.authorisedAddresses.includes(req.user.address)) { + standardResponse(res, 400, false, '', { + error: { + name: 'USER_NOT_AUTHORIZED', + message: 'User not authorized!' + } + }); + return; + } + } + this.microCreditService .listApplications(req.user.userId, req.query) .then(r => standardResponse(res, 200, true, r)) diff --git a/packages/api/src/routes/v2/microcredit/list.ts b/packages/api/src/routes/v2/microcredit/list.ts index cfc660c3d..d431535de 100644 --- a/packages/api/src/routes/v2/microcredit/list.ts +++ b/packages/api/src/routes/v2/microcredit/list.ts @@ -66,8 +66,8 @@ export default (route: Router): void => { route.get( '/borrowers/:query?', authenticateToken, - // verifySignature, - // cache(cacheIntervals.tenMinutes, true), + verifySignature, + cache(cacheIntervals.tenMinutes, true), onlyAuthorizedRoles(['loanManager']), listBorrowersValidator, controller.listBorrowers @@ -156,6 +156,12 @@ export default (route: Router): void => { * enum: [appliedOn, appliedOn:asc, appliedOn:desc] * required: false * description: order by + * - in: query + * name: loanManagerAddress + * schema: + * type: string + * required: false + * description: loan manager address used to query from an authorized account * responses: * "200": * description: OK diff --git a/packages/api/src/validators/microcredit.ts b/packages/api/src/validators/microcredit.ts index d81bdaf56..d0c17c814 100644 --- a/packages/api/src/validators/microcredit.ts +++ b/packages/api/src/validators/microcredit.ts @@ -33,6 +33,7 @@ type ListApplicationsType = { limit?: number; status?: number; orderBy?: 'appliedOn' | 'appliedOn:asc' | 'appliedOn:desc'; + loanManagerAddress?: string; }; const queryListBorrowersSchema = defaultSchema.object({ @@ -65,7 +66,8 @@ const queryListApplicationsSchema = defaultSchema.object({ offset: Joi.number().optional().default(0), limit: Joi.number().optional().max(20).default(10), status: Joi.number().optional().min(0), - orderBy: Joi.string().optional().valid('appliedOn', 'appliedOn:asc', 'appliedOn:desc') + orderBy: Joi.string().optional().valid('appliedOn', 'appliedOn:asc', 'appliedOn:desc'), + loanManagerAddress: Joi.string().optional() }); const queryRepaymentsHistorySchema = defaultSchema.object({