Skip to content

Commit

Permalink
add loanManagerAddress to applications list by authorized users
Browse files Browse the repository at this point in the history
  • Loading branch information
Bernardo Vieira committed Sep 26, 2023
1 parent 6e79b5e commit b6369de
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
13 changes: 13 additions & 0 deletions packages/api/src/controllers/v2/microcredit/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
10 changes: 8 additions & 2 deletions packages/api/src/routes/v2/microcredit/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion packages/api/src/validators/microcredit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type ListApplicationsType = {
limit?: number;
status?: number;
orderBy?: 'appliedOn' | 'appliedOn:asc' | 'appliedOn:desc';
loanManagerAddress?: string;
};

const queryListBorrowersSchema = defaultSchema.object<ListBorrowersType>({
Expand Down Expand Up @@ -65,7 +66,8 @@ const queryListApplicationsSchema = defaultSchema.object<ListApplicationsType>({
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({
Expand Down

0 comments on commit b6369de

Please sign in to comment.