Skip to content

Commit 4031696

Browse files
committed
feat: refactor
1 parent d8e2264 commit 4031696

File tree

7 files changed

+37
-26
lines changed

7 files changed

+37
-26
lines changed

apps/backoffice-v2/public/locales/en/toast.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
"success": "The case has been approved successfully.",
1212
"error": "Error occurred while approving the case."
1313
},
14+
"approve_individual": {
15+
"success": "The individual has been approved successfully.",
16+
"error": "Error occurred while approving the individual."
17+
},
1418
"reject_case": {
1519
"success": "The case has been rejected successfully.",
1620
"error": "Error occurred while rejecting the case."

apps/backoffice-v2/src/domains/individuals/fetchers.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ export const getEndUsersByIds = async ({ ids }: { ids: string[] }) => {
9393
};
9494

9595
export type TIndividualDecision =
96-
| `${typeof EndUserApprovalState.APPROVED}`
97-
| `${typeof EndUserApprovalState.REJECTED}`;
96+
| typeof EndUserApprovalState.APPROVED
97+
| typeof EndUserApprovalState.REJECTED;
9898

9999
export const updateIndividualApprovalDecision = async ({
100100
endUserId,
@@ -108,7 +108,6 @@ export const updateIndividualApprovalDecision = async ({
108108
method: Method.POST,
109109
schema: EndUserSchema,
110110
body: {
111-
endUserId,
112111
decision,
113112
},
114113
});

apps/backoffice-v2/src/domains/individuals/mutations/useMutateIndividualApprovalDecision/useMutateIndividualApprovalDecision.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { toast } from 'sonner';
44
import { t } from 'i18next';
55
import { queryClient } from '@/lib/react-query/query-client';
66
import { workflowsQueryKeys } from '@/domains/workflows/query-keys';
7+
import { endUsersQueryKeys } from '../../query-keys';
78

89
export const useMutateIndividualApprovalDecision = () => {
910
return useMutation({
@@ -19,13 +20,18 @@ export const useMutateIndividualApprovalDecision = () => {
1920
decision,
2021
});
2122
},
22-
onSuccess: () => {
23+
onSuccess: endUser => {
2324
void queryClient.invalidateQueries(workflowsQueryKeys._def);
25+
void queryClient.invalidateQueries(endUsersQueryKeys._def);
2426

25-
toast.success(t('toast:approve_case.success'));
27+
if (endUser?.id) {
28+
void queryClient.invalidateQueries(endUsersQueryKeys.byId({ id: endUser.id }));
29+
}
30+
31+
toast.success(t('toast:approve_individual.success'));
2632
},
2733
onError: () => {
28-
toast.error(t('toast:approve_case.error'));
34+
toast.error(t('toast:approve_individual.error'));
2935
},
3036
});
3137
};

apps/backoffice-v2/src/lib/blocks/components/KycBlock/hooks/useKycBlock/useKycBlock.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ export const useKycBlock = ({
304304
const badgeClassNames = 'text-sm font-bold';
305305

306306
const getDecisionStatusOrAction = (status: TIndividualKycCheckStatus | undefined) => {
307-
if (status === INDIVIDUAL_KYC_CHECK_STATUS_ENUM.revision) {
307+
if (status === INDIVIDUAL_KYC_CHECK_STATUS_ENUM.REVISION) {
308308
return createBlocksTyped()
309309
.addBlock()
310310
.addCell({
@@ -319,7 +319,7 @@ export const useKycBlock = ({
319319
.buildFlat();
320320
}
321321

322-
if (status === INDIVIDUAL_KYC_CHECK_STATUS_ENUM.approved) {
322+
if (status === INDIVIDUAL_KYC_CHECK_STATUS_ENUM.APPROVED) {
323323
return createBlocksTyped()
324324
.addBlock()
325325
.addCell({
@@ -334,7 +334,7 @@ export const useKycBlock = ({
334334
.buildFlat();
335335
}
336336

337-
if (status === INDIVIDUAL_KYC_CHECK_STATUS_ENUM.rejected) {
337+
if (status === INDIVIDUAL_KYC_CHECK_STATUS_ENUM.REJECTED) {
338338
return createBlocksTyped()
339339
.addBlock()
340340
.addCell({
@@ -349,7 +349,7 @@ export const useKycBlock = ({
349349
.buildFlat();
350350
}
351351

352-
if (status === INDIVIDUAL_KYC_CHECK_STATUS_ENUM.pending) {
352+
if (status === INDIVIDUAL_KYC_CHECK_STATUS_ENUM.PENDING) {
353353
return createBlocksTyped()
354354
.addBlock()
355355
.addCell({

apps/backoffice-v2/src/lib/blocks/variants/DefaultBlocks/hooks/useCaseBlocksLogic/utils/compute-individual-kyc-check-status.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,29 @@ import { TWorkflowById } from '@/domains/workflows/fetchers';
33
import { ObjectValues, StateTag } from '@ballerine/common';
44

55
export const INDIVIDUAL_KYC_CHECK_STATUS_ENUM = {
6-
revision: 'revision',
7-
approved: 'approved',
8-
rejected: 'rejected',
9-
pending: 'pending',
6+
REVISION: 'revision',
7+
APPROVED: 'approved',
8+
REJECTED: 'rejected',
9+
PENDING: 'pending',
1010
} as const;
1111

1212
export type TIndividualKycCheckStatus = ObjectValues<typeof INDIVIDUAL_KYC_CHECK_STATUS_ENUM>;
1313

1414
const getStatusFromTags = (tags: string[]) => {
1515
if (tags?.includes(StateTag.REVISION)) {
16-
return INDIVIDUAL_KYC_CHECK_STATUS_ENUM.revision;
16+
return INDIVIDUAL_KYC_CHECK_STATUS_ENUM.REVISION;
1717
}
1818

1919
if (tags?.includes(StateTag.APPROVED)) {
20-
return INDIVIDUAL_KYC_CHECK_STATUS_ENUM.approved;
20+
return INDIVIDUAL_KYC_CHECK_STATUS_ENUM.APPROVED;
2121
}
2222

2323
if (tags?.includes(StateTag.REJECTED)) {
24-
return INDIVIDUAL_KYC_CHECK_STATUS_ENUM.rejected;
24+
return INDIVIDUAL_KYC_CHECK_STATUS_ENUM.REJECTED;
2525
}
2626

2727
if (tags?.includes(StateTag.PENDING_PROCESS)) {
28-
return INDIVIDUAL_KYC_CHECK_STATUS_ENUM.pending;
28+
return INDIVIDUAL_KYC_CHECK_STATUS_ENUM.PENDING;
2929
}
3030
};
3131

@@ -37,7 +37,7 @@ export const computeIndividualKycCheckStatus = ({
3737
tags: TWorkflowById['tags'];
3838
}): TIndividualKycCheckStatus | undefined => {
3939
if (endUser?.individualVerificationsChecks?.status === 'in-progress') {
40-
return INDIVIDUAL_KYC_CHECK_STATUS_ENUM.pending;
40+
return INDIVIDUAL_KYC_CHECK_STATUS_ENUM.PENDING;
4141
}
4242

4343
if (
@@ -48,10 +48,10 @@ export const computeIndividualKycCheckStatus = ({
4848
}
4949

5050
if (endUser?.approvalState === EndUserApprovalState.APPROVED) {
51-
return INDIVIDUAL_KYC_CHECK_STATUS_ENUM.approved;
51+
return INDIVIDUAL_KYC_CHECK_STATUS_ENUM.APPROVED;
5252
}
5353

5454
if (endUser?.approvalState === EndUserApprovalState.REJECTED) {
55-
return INDIVIDUAL_KYC_CHECK_STATUS_ENUM.rejected;
55+
return INDIVIDUAL_KYC_CHECK_STATUS_ENUM.REJECTED;
5656
}
5757
};

apps/backoffice-v2/src/lib/blocks/variants/DefaultBlocks/hooks/useCaseBlocksLogic/utils/useTabsToBlocksMap.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ export const useTabsToBlocksMap = ({
195195
...additionalInfoRest
196196
} = additionalInfo ?? {};
197197
const status = computeIndividualKycCheckStatus({
198-
endUser: endUser,
198+
endUser,
199199
tags: childWorkflow?.tags ?? [],
200200
});
201201
const kycSession = omitPropsFromObject(
@@ -262,7 +262,7 @@ export const useTabsToBlocksMap = ({
262262
({ ids }: { ids: string[] }) =>
263263
() =>
264264
mutateIndividualApprovalDecision({
265-
endUserId: childWorkflow?.context?.entity?.data?.ballerineEntityId,
265+
endUserId: endUser?.id!,
266266
decision: EndUserApprovalState.APPROVED,
267267
}),
268268
onReuploadNeeded:
@@ -422,7 +422,7 @@ export const useTabsToBlocksMap = ({
422422
const endUser = endUsers?.find(endUser => endUser.id === director.ballerineEntityId);
423423
const { amlHits, individualVerificationsChecks, ...directorEndUser } = endUser ?? {};
424424
const status = computeIndividualKycCheckStatus({
425-
endUser: endUser,
425+
endUser,
426426
tags: [],
427427
});
428428

@@ -455,7 +455,7 @@ export const useTabsToBlocksMap = ({
455455
...personOfInterestEndUser
456456
} = endUser ?? {};
457457
const status = computeIndividualKycCheckStatus({
458-
endUser: endUser,
458+
endUser,
459459
tags: [],
460460
});
461461
const kycSession = omitPropsFromObject(

services/workflows-service/src/end-user/end-user.service.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { BadRequestException, Injectable } from '@nestjs/common';
22
import { EndUserRepository } from './end-user.repository';
33
import { EndUserCreateDto } from '@/end-user/dtos/end-user-create';
44
import type { PrismaTransaction, TProjectId, TProjectIds } from '@/types';
5-
import { ProjectScopeService } from '@/project/project-scope.service';
5+
import { assertIsValidProjectIds, ProjectScopeService } from '@/project/project-scope.service';
66
import { ApprovalState, Business, BusinessPosition, EndUser, Prisma } from '@prisma/client';
77
import { EndUserActiveMonitoringsSchema, EndUserAmlHitsSchema } from '@ballerine/common';
88

@@ -118,6 +118,8 @@ export class EndUserService {
118118
}
119119

120120
async updateDecisionById(id: string, decision: ApprovalState, projectIds: TProjectIds) {
121+
assertIsValidProjectIds(projectIds);
122+
121123
const endUser = await this.repository.findById(id, {}, projectIds);
122124

123125
const isApprovedOrRejected = [ApprovalState.APPROVED, ApprovalState.REJECTED].includes(

0 commit comments

Comments
 (0)