Skip to content

Commit

Permalink
fix(*): no longer updating a document decision of all directors
Browse files Browse the repository at this point in the history
  • Loading branch information
Omri-Levy committed Jan 22, 2025
1 parent 7007f16 commit 497154b
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -25,6 +27,7 @@ export const useApproveTaskByIdMutation = (workflowId: string) => {
workflowId,
documentId,
body: {
directorId,
decision: Action.APPROVE,
comment,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,21 @@ export const useRevisionTaskByIdMutation = () => {
workflowId,
documentId,
reason,
directorId,
contextUpdateMethod,
}: {
workflowId: string;
documentId: string;
reason?: string;
directorId?: string;
contextUpdateMethod?: 'base' | 'director';
}) =>
updateWorkflowDecision({
workflowId,
documentId,
contextUpdateMethod,
body: {
directorId,
decision: Action.REVISION,
reason,
},
Expand Down
1 change: 1 addition & 0 deletions apps/backoffice-v2/src/domains/workflows/fetchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ export const updateWorkflowDecision = async ({
documentId: string;
body: {
decision: string | null;
directorId?: string;
reason?: string;
comment?: string;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -54,6 +62,7 @@ export const useDirectorBlock = ({
issuer: {
country: string;
};
version: string;
pages: Array<{
type: string;
imageUrl: string;
Expand Down Expand Up @@ -148,7 +157,12 @@ export const useDirectorBlock = ({
Re-upload needed
<X
className="h-4 w-4 cursor-pointer"
onClick={() => onRemoveDecision(document.id)}
onClick={() =>
onRemoveDecision({
directorId: director.id,
documentId: document.id,
})
}
/>
</React.Fragment>
),
Expand Down Expand Up @@ -241,7 +255,12 @@ export const useDirectorBlock = ({
</Button>
<Button
disabled={isApproveActionDisabled}
onClick={() => onApprove(document.id)}
onClick={() =>
onApprove({
directorId: director.id,
documentId: document.id,
})
}
>
Approve
</Button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,11 +334,12 @@ export const useDefaultBlocksLogic = () => {
const onMutateRevisionTaskByIdDirectors = useCallback(
({
workflowId,
directorId,
documentId,
reason,
}: Pick<
Parameters<typeof mutateRevisionTaskById>[0],
'workflowId' | 'documentId' | 'reason'
'workflowId' | 'directorId' | 'documentId' | 'reason'
>) =>
() => {
if (!documentId) {
Expand All @@ -349,6 +350,7 @@ export const useDefaultBlocksLogic = () => {

mutateRevisionTaskById({
workflowId,
directorId,
documentId,
reason,
contextUpdateMethod: 'director',
Expand All @@ -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],
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,13 @@ export const useKybExampleBlocksLogic = () => {

const onMutateRevisionTaskByIdDirectors = useCallback(
({
directorId,
workflowId,
documentId,
reason,
}: Pick<
Parameters<typeof mutateRevisionTaskById>[0],
'workflowId' | 'documentId' | 'reason'
'directorId' | 'workflowId' | 'documentId' | 'reason'
>) =>
() => {
if (!documentId) {
Expand All @@ -189,6 +190,7 @@ export const useKybExampleBlocksLogic = () => {
}

mutateRevisionTaskById({
directorId,
workflowId,
documentId,
reason,
Expand All @@ -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],
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,11 @@ export class DocumentDecisionUpdateInput {
@IsOptional()
@IsString()
comment?: string;

@ApiProperty({
required: false,
type: String,
})
@IsString()
directorId?: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
31 changes: 28 additions & 3 deletions services/workflows-service/src/workflow/workflow.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -820,10 +820,12 @@ export class WorkflowService {
async updateDocumentDecisionById(
{
workflowId,
directorId,
documentId,
documentsUpdateContextMethod,
}: {
workflowId: string;
directorId?: string;
documentId: string;
documentsUpdateContextMethod?: 'base' | 'director';
},
Expand Down Expand Up @@ -903,6 +905,7 @@ export class WorkflowService {
: document?.type,
},
documentsUpdateContextMethod,
directorId,
);

document = this.getDocuments(updatedContext, documentsUpdateContextMethod)?.find(
Expand All @@ -924,6 +927,7 @@ export class WorkflowService {
const updatedWorkflow = await this.updateDocumentById(
{
workflowId,
directorId,
documentId,
validateDocumentSchema,
documentsUpdateContextMethod: documentsUpdateContextMethod,
Expand All @@ -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,
Expand Down Expand Up @@ -1011,6 +1017,7 @@ export class WorkflowService {
runtimeData.context,
documentSchema,
documentsUpdateContextMethod,
directorId,
),
arrayMergeOption:
documentsUpdateContextMethod === 'director'
Expand Down Expand Up @@ -1079,6 +1086,7 @@ export class WorkflowService {
context: WorkflowRuntimeData['context'],
updatePayload: any,
method: 'base' | 'director' = 'base',
directorId?: string,
): WorkflowRuntimeData['context'] {
switch (method) {
case 'base':
Expand All @@ -1088,7 +1096,7 @@ export class WorkflowService {
};

case 'director':
return this.updateDirectorDocument(context, updatePayload);
return this.updateDirectorDocument(context, updatePayload, directorId);

default:
return context;
Expand All @@ -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) {
Expand All @@ -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[])
Expand Down

0 comments on commit 497154b

Please sign in to comment.