diff --git a/apps/backoffice-v2/src/domains/entities/hooks/mutations/useApproveTaskByIdMutation/useApproveTaskByIdMutation.tsx b/apps/backoffice-v2/src/domains/entities/hooks/mutations/useApproveTaskByIdMutation/useApproveTaskByIdMutation.tsx index e42e1068f4..4c33bf170e 100644 --- a/apps/backoffice-v2/src/domains/entities/hooks/mutations/useApproveTaskByIdMutation/useApproveTaskByIdMutation.tsx +++ b/apps/backoffice-v2/src/domains/entities/hooks/mutations/useApproveTaskByIdMutation/useApproveTaskByIdMutation.tsx @@ -13,10 +13,12 @@ export const useApproveTaskByIdMutation = (workflowId: string) => { return useMutation({ mutationFn: ({ + directorId, documentId, contextUpdateMethod = 'base', comment, }: { + directorId?: string; documentId: string; contextUpdateMethod?: 'base' | 'director'; comment?: string; @@ -25,6 +27,7 @@ export const useApproveTaskByIdMutation = (workflowId: string) => { workflowId, documentId, body: { + directorId, decision: Action.APPROVE, comment, }, diff --git a/apps/backoffice-v2/src/domains/entities/hooks/mutations/useRemoveDecisionTaskByIdMutation/useRemoveDecisionTaskByIdMutation.tsx b/apps/backoffice-v2/src/domains/entities/hooks/mutations/useRemoveDecisionTaskByIdMutation/useRemoveDecisionTaskByIdMutation.tsx index c20c8c09e6..f76d9672a3 100644 --- a/apps/backoffice-v2/src/domains/entities/hooks/mutations/useRemoveDecisionTaskByIdMutation/useRemoveDecisionTaskByIdMutation.tsx +++ b/apps/backoffice-v2/src/domains/entities/hooks/mutations/useRemoveDecisionTaskByIdMutation/useRemoveDecisionTaskByIdMutation.tsx @@ -13,15 +13,18 @@ export const useRemoveDecisionTaskByIdMutation = (workflowId: string) => { return useMutation({ mutationFn: ({ documentId, + directorId, contextUpdateMethod, }: { documentId: string; + directorId?: string; contextUpdateMethod: 'base' | 'director'; }) => updateWorkflowDecision({ workflowId, documentId, body: { + directorId, decision: null, reason: null, }, diff --git a/apps/backoffice-v2/src/domains/entities/hooks/mutations/useRevisionTaskByIdMutation/useRevisionTaskByIdMutation.tsx b/apps/backoffice-v2/src/domains/entities/hooks/mutations/useRevisionTaskByIdMutation/useRevisionTaskByIdMutation.tsx index d5004a0f27..25ef7668f8 100644 --- a/apps/backoffice-v2/src/domains/entities/hooks/mutations/useRevisionTaskByIdMutation/useRevisionTaskByIdMutation.tsx +++ b/apps/backoffice-v2/src/domains/entities/hooks/mutations/useRevisionTaskByIdMutation/useRevisionTaskByIdMutation.tsx @@ -15,11 +15,13 @@ export const useRevisionTaskByIdMutation = () => { workflowId, documentId, reason, + directorId, contextUpdateMethod, }: { workflowId: string; documentId: string; reason?: string; + directorId?: string; contextUpdateMethod?: 'base' | 'director'; }) => updateWorkflowDecision({ @@ -27,6 +29,7 @@ export const useRevisionTaskByIdMutation = () => { documentId, contextUpdateMethod, body: { + directorId, decision: Action.REVISION, reason, }, diff --git a/apps/backoffice-v2/src/domains/workflows/fetchers.ts b/apps/backoffice-v2/src/domains/workflows/fetchers.ts index af75288bb8..f0f440213a 100644 --- a/apps/backoffice-v2/src/domains/workflows/fetchers.ts +++ b/apps/backoffice-v2/src/domains/workflows/fetchers.ts @@ -300,6 +300,7 @@ export const updateWorkflowDecision = async ({ documentId: string; body: { decision: string | null; + directorId?: string; reason?: string; comment?: string; }; diff --git a/apps/backoffice-v2/src/lib/blocks/components/DirectorBlock/hooks/useDirectorBlock/helpers.ts b/apps/backoffice-v2/src/lib/blocks/components/DirectorBlock/hooks/useDirectorBlock/helpers.ts index 1fda1cb510..06fcf83c02 100644 --- a/apps/backoffice-v2/src/lib/blocks/components/DirectorBlock/hooks/useDirectorBlock/helpers.ts +++ b/apps/backoffice-v2/src/lib/blocks/components/DirectorBlock/hooks/useDirectorBlock/helpers.ts @@ -13,6 +13,7 @@ export const directorDocumentsAdapter = ({ documents, storageFiles }) => { decision: { status: document?.decision?.status, }, + version: document?.version, properties: document?.properties, propertiesSchema: document?.propertiesSchema, pages: document?.pages?.map( diff --git a/apps/backoffice-v2/src/lib/blocks/components/DirectorBlock/hooks/useDirectorBlock/useDirectorBlock.tsx b/apps/backoffice-v2/src/lib/blocks/components/DirectorBlock/hooks/useDirectorBlock/useDirectorBlock.tsx index 30b80001a9..ca4c649712 100644 --- a/apps/backoffice-v2/src/lib/blocks/components/DirectorBlock/hooks/useDirectorBlock/useDirectorBlock.tsx +++ b/apps/backoffice-v2/src/lib/blocks/components/DirectorBlock/hooks/useDirectorBlock/useDirectorBlock.tsx @@ -33,15 +33,23 @@ export const useDirectorBlock = ({ workflowId: string; onReuploadNeeded: ({ workflowId, + directorId, documentId, reason, }: { workflowId: string; + directorId?: string; documentId: string; reason?: string; }) => () => void; - onRemoveDecision: (documentId: string) => void; - onApprove: (documentId: string) => void; + onRemoveDecision: ({ + directorId, + documentId, + }: { + directorId: string; + documentId: string; + }) => void; + onApprove: ({ directorId, documentId }: { directorId: string; documentId: string }) => void; director: { id: string; firstName: string; @@ -54,6 +62,7 @@ export const useDirectorBlock = ({ issuer: { country: string; }; + version: string; pages: Array<{ type: string; imageUrl: string; @@ -148,7 +157,12 @@ export const useDirectorBlock = ({ Re-upload needed onRemoveDecision(document.id)} + onClick={() => + onRemoveDecision({ + directorId: director.id, + documentId: document.id, + }) + } /> ), @@ -241,7 +255,12 @@ export const useDirectorBlock = ({ diff --git a/apps/backoffice-v2/src/lib/blocks/variants/DefaultBlocks/hooks/useDefaultBlocksLogic/useDefaultBlocksLogic.tsx b/apps/backoffice-v2/src/lib/blocks/variants/DefaultBlocks/hooks/useDefaultBlocksLogic/useDefaultBlocksLogic.tsx index b506fd5f7f..9c72d86166 100644 --- a/apps/backoffice-v2/src/lib/blocks/variants/DefaultBlocks/hooks/useDefaultBlocksLogic/useDefaultBlocksLogic.tsx +++ b/apps/backoffice-v2/src/lib/blocks/variants/DefaultBlocks/hooks/useDefaultBlocksLogic/useDefaultBlocksLogic.tsx @@ -334,11 +334,12 @@ export const useDefaultBlocksLogic = () => { const onMutateRevisionTaskByIdDirectors = useCallback( ({ workflowId, + directorId, documentId, reason, }: Pick< Parameters[0], - 'workflowId' | 'documentId' | 'reason' + 'workflowId' | 'directorId' | 'documentId' | 'reason' >) => () => { if (!documentId) { @@ -349,6 +350,7 @@ export const useDefaultBlocksLogic = () => { mutateRevisionTaskById({ workflowId, + directorId, documentId, reason, contextUpdateMethod: 'director', @@ -358,12 +360,13 @@ export const useDefaultBlocksLogic = () => { ); const onMutateApproveTaskByIdDirectors = useCallback( - (documentId: string) => mutateApproveTaskById({ documentId, contextUpdateMethod: 'director' }), + ({ directorId, documentId }: { directorId: string; documentId: string }) => + mutateApproveTaskById({ directorId, documentId, contextUpdateMethod: 'director' }), [mutateApproveTaskById], ); const onMutateRemoveDecisionTaskByIdDirectors = useCallback( - (documentId: string) => - mutateRemoveDecisionTaskById({ documentId, contextUpdateMethod: 'director' }), + ({ directorId, documentId }: { directorId: string; documentId: string }) => + mutateRemoveDecisionTaskById({ directorId, documentId, contextUpdateMethod: 'director' }), [mutateRemoveDecisionTaskById], ); diff --git a/apps/backoffice-v2/src/lib/blocks/variants/KybExampleBlocks/hooks/useKybExampleBlocksLogic/useKybExampleBlocksLogic.tsx b/apps/backoffice-v2/src/lib/blocks/variants/KybExampleBlocks/hooks/useKybExampleBlocksLogic/useKybExampleBlocksLogic.tsx index 6702fad741..afbf589cd4 100644 --- a/apps/backoffice-v2/src/lib/blocks/variants/KybExampleBlocks/hooks/useKybExampleBlocksLogic/useKybExampleBlocksLogic.tsx +++ b/apps/backoffice-v2/src/lib/blocks/variants/KybExampleBlocks/hooks/useKybExampleBlocksLogic/useKybExampleBlocksLogic.tsx @@ -174,12 +174,13 @@ export const useKybExampleBlocksLogic = () => { const onMutateRevisionTaskByIdDirectors = useCallback( ({ + directorId, workflowId, documentId, reason, }: Pick< Parameters[0], - 'workflowId' | 'documentId' | 'reason' + 'directorId' | 'workflowId' | 'documentId' | 'reason' >) => () => { if (!documentId) { @@ -189,6 +190,7 @@ export const useKybExampleBlocksLogic = () => { } mutateRevisionTaskById({ + directorId, workflowId, documentId, reason, @@ -206,12 +208,13 @@ export const useKybExampleBlocksLogic = () => { ], ); const onMutateApproveTaskByIdDirectors = useCallback( - (documentId: string) => mutateApproveTaskById({ documentId, contextUpdateMethod: 'director' }), + ({ directorId, documentId }: { directorId: string; documentId: string }) => + mutateApproveTaskById({ directorId, documentId, contextUpdateMethod: 'director' }), [mutateApproveTaskById], ); const onMutateRemoveDecisionTaskByIdDirectors = useCallback( - (documentId: string) => - mutateRemoveDecisionTaskById({ documentId, contextUpdateMethod: 'director' }), + ({ directorId, documentId }: { directorId: string; documentId: string }) => + mutateRemoveDecisionTaskById({ directorId, documentId, contextUpdateMethod: 'director' }), [mutateRemoveDecisionTaskById], ); diff --git a/services/workflows-service/src/workflow/dtos/document-decision-update-input.ts b/services/workflows-service/src/workflow/dtos/document-decision-update-input.ts index a0be01d989..14d18e429d 100644 --- a/services/workflows-service/src/workflow/dtos/document-decision-update-input.ts +++ b/services/workflows-service/src/workflow/dtos/document-decision-update-input.ts @@ -26,4 +26,11 @@ export class DocumentDecisionUpdateInput { @IsOptional() @IsString() comment?: string; + + @ApiProperty({ + required: false, + type: String, + }) + @IsString() + directorId?: string; } diff --git a/services/workflows-service/src/workflow/workflow.controller.internal.ts b/services/workflows-service/src/workflow/workflow.controller.internal.ts index 1a326e44c0..db8b9de711 100644 --- a/services/workflows-service/src/workflow/workflow.controller.internal.ts +++ b/services/workflows-service/src/workflow/workflow.controller.internal.ts @@ -291,6 +291,7 @@ export class WorkflowControllerInternal { const workflowData = await this.service.updateDocumentDecisionById( { workflowId: params?.id, + directorId: data?.directorId, documentId: params?.documentId, documentsUpdateContextMethod: query.contextUpdateMethod, }, diff --git a/services/workflows-service/src/workflow/workflow.service.ts b/services/workflows-service/src/workflow/workflow.service.ts index 8c34c7ea20..ed6b9b286c 100644 --- a/services/workflows-service/src/workflow/workflow.service.ts +++ b/services/workflows-service/src/workflow/workflow.service.ts @@ -820,10 +820,12 @@ export class WorkflowService { async updateDocumentDecisionById( { workflowId, + directorId, documentId, documentsUpdateContextMethod, }: { workflowId: string; + directorId?: string; documentId: string; documentsUpdateContextMethod?: 'base' | 'director'; }, @@ -903,6 +905,7 @@ export class WorkflowService { : document?.type, }, documentsUpdateContextMethod, + directorId, ); document = this.getDocuments(updatedContext, documentsUpdateContextMethod)?.find( @@ -924,6 +927,7 @@ export class WorkflowService { const updatedWorkflow = await this.updateDocumentById( { workflowId, + directorId, documentId, validateDocumentSchema, documentsUpdateContextMethod: documentsUpdateContextMethod, @@ -949,11 +953,13 @@ export class WorkflowService { documentId, validateDocumentSchema = true, documentsUpdateContextMethod, + directorId, }: { workflowId: string; documentId: string; validateDocumentSchema?: boolean; documentsUpdateContextMethod?: 'base' | 'director'; + directorId?: string; }, data: DefaultContextSchema['documents'][number] & { propertiesSchema?: object }, projectId: TProjectId, @@ -1011,6 +1017,7 @@ export class WorkflowService { runtimeData.context, documentSchema, documentsUpdateContextMethod, + directorId, ), arrayMergeOption: documentsUpdateContextMethod === 'director' @@ -1079,6 +1086,7 @@ export class WorkflowService { context: WorkflowRuntimeData['context'], updatePayload: any, method: 'base' | 'director' = 'base', + directorId?: string, ): WorkflowRuntimeData['context'] { switch (method) { case 'base': @@ -1088,7 +1096,7 @@ export class WorkflowService { }; case 'director': - return this.updateDirectorDocument(context, updatePayload); + return this.updateDirectorDocument(context, updatePayload, directorId); default: return context; @@ -1112,8 +1120,15 @@ export class WorkflowService { private updateDirectorDocument( context: WorkflowRuntimeData['context'], documentUpdatePayload: any, + directorId: string | undefined, ): WorkflowRuntimeData['context'] { - const directorsDocuments = this.getDirectorsDocuments(context); + if (!directorId) { + throw new BadRequestException('Attempted to update director document without a director id'); + } + + const directorsDocuments = this.getDirectorsDocuments(context, directorId); + + this.logger.log('directorsDocuments', { directorsDocuments }); directorsDocuments.forEach(document => { if (document?.id === documentUpdatePayload?.id) { @@ -1126,9 +1141,19 @@ export class WorkflowService { return context; } - private getDirectorsDocuments(context: WorkflowRuntimeData['context']): any[] { + private getDirectorsDocuments( + context: WorkflowRuntimeData['context'], + directorId?: string, + ): any[] { return ( this.getDirectors(context) + .filter(director => { + if (!directorId) { + return true; + } + + return director.ballerineEntityId === directorId; + }) .map(director => director.additionalInfo?.documents) .filter(Boolean) .flat() || ([] as any[])