Skip to content

Commit

Permalink
list only most recent application per user
Browse files Browse the repository at this point in the history
  • Loading branch information
Bernardo Vieira committed Nov 14, 2023
1 parent c57d245 commit 91bb943
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/api/src/services/app/user/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ export default class UserLogService {
const contractAddress = roles.beneficiary?.community
? roles.beneficiary.community
: roles.manager?.community
? roles.manager.community
: null;
? roles.manager.community
: null;
if (!contractAddress) {
throw new utils.BaseError('USER_NOT_FOUND', 'user not found');
}
Expand Down
10 changes: 9 additions & 1 deletion packages/core/src/services/microcredit/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,15 @@ export default class MicroCreditList {
}

const [orderKey, orderDirection] = query.orderBy ? query.orderBy.split(':') : [undefined, undefined];
const where: WhereOptions<MicroCreditApplication> = { selectedLoanManagerId: userId };
let where: WhereOptions<MicroCreditApplication> = {
selectedLoanManagerId: userId,
// we want only the most recent application to each user
createdAt: {
[Op.eq]: literal(
'(SELECT MAX("createdAt") FROM microcredit_applications ma WHERE ma."userId" = "microCreditApplications"."userId")'
)
}
};
if (query.status !== undefined) {
where.status = query.status;
} else {
Expand Down

0 comments on commit 91bb943

Please sign in to comment.