diff --git a/apps/backoffice-v2/src/domains/workflows/hooks/mutations/useUpdateDocumentByIdMutation/useUpdateDocumentByIdMutation.tsx b/apps/backoffice-v2/src/domains/workflows/hooks/mutations/useUpdateDocumentByIdMutation/useUpdateDocumentByIdMutation.tsx index fa671ae335..e427555e46 100644 --- a/apps/backoffice-v2/src/domains/workflows/hooks/mutations/useUpdateDocumentByIdMutation/useUpdateDocumentByIdMutation.tsx +++ b/apps/backoffice-v2/src/domains/workflows/hooks/mutations/useUpdateDocumentByIdMutation/useUpdateDocumentByIdMutation.tsx @@ -7,9 +7,11 @@ import { workflowsQueryKeys } from '../../../query-keys'; export const useUpdateDocumentByIdMutation = ({ workflowId, + directorId, documentId, }: { workflowId: string; + directorId?: string; documentId: string; }) => { const queryClient = useQueryClient(); @@ -29,6 +31,7 @@ export const useUpdateDocumentByIdMutation = ({ workflowId, documentId, body: { + directorId, document, }, contextUpdateMethod, diff --git a/apps/backoffice-v2/src/lib/blocks/components/Details/Details.tsx b/apps/backoffice-v2/src/lib/blocks/components/Details/Details.tsx index 6f85036c0f..0342dc0e2f 100644 --- a/apps/backoffice-v2/src/lib/blocks/components/Details/Details.tsx +++ b/apps/backoffice-v2/src/lib/blocks/components/Details/Details.tsx @@ -10,6 +10,7 @@ export const Details: FunctionComponent> = ({ value, hideSeparator, contextUpdateMethod, + directorId, workflowId, documents = [], onSubmit, @@ -34,6 +35,7 @@ export const Details: FunctionComponent> = ({ > { return documents?.map( (document, documentIndex) => ({ - id: document?.id, - category: document?.category, - type: document?.type, - issuer: { - country: document?.issuer?.country, - }, - decision: { - status: document?.decision?.status, - }, - version: document?.version, - properties: document?.properties, - propertiesSchema: document?.propertiesSchema, + ...document, pages: document?.pages?.map( (page, pageIndex) => ({ - type: page?.type, + ...page, + // EditableDetails updates a document by replacing it, we need document to be complete, + // and imageUrl to be omitted in the documents passed to the details cell. imageUrl: storageFiles?.[documentIndex]?.[pageIndex], - metadata: { - side: page?.metadata?.side, - }, } satisfies Parameters< typeof createDirectorsBlocks >[0]['directors'][number]['documents'][number]['pages'][number]), 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 0bb171b487..0c74e35826 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 @@ -96,6 +96,10 @@ export const useDirectorBlock = ({ const blocks = useMemo(() => { const { documents } = director; + const documentsWithoutImageUrl = documents.map(document => ({ + ...document, + pages: document?.pages?.map(({ imageUrl: _imageUrl, ...page }) => page), + })); const isDocumentRevision = documents.some( document => document?.decision?.status === 'revision', ); @@ -112,6 +116,7 @@ export const useDirectorBlock = ({ .addCell({ type: 'details', contextUpdateMethod: 'director', + directorId: director.id, hideSeparator: true, value: { id: document.id, @@ -124,7 +129,8 @@ export const useDirectorBlock = ({ : [], }, workflowId, - documents, + // Otherwise imageUrl will be saved into the document. + documents: documentsWithoutImageUrl, }) .cellAt(0, 0); @@ -326,6 +332,7 @@ export const useDirectorBlock = ({ }) .addCell({ type: 'details', + directorId: director.id, contextUpdateMethod: 'director', value: { id: document.id, @@ -366,7 +373,8 @@ export const useDirectorBlock = ({ }, ), }, - documents, + // Otherwise imageUrl will be saved into the document. + documents: documentsWithoutImageUrl, workflowId, }) .addCell(decisionCell) diff --git a/apps/backoffice-v2/src/lib/blocks/components/EditableDetails/EditableDetails.tsx b/apps/backoffice-v2/src/lib/blocks/components/EditableDetails/EditableDetails.tsx index 685a90058c..afc153780f 100644 --- a/apps/backoffice-v2/src/lib/blocks/components/EditableDetails/EditableDetails.tsx +++ b/apps/backoffice-v2/src/lib/blocks/components/EditableDetails/EditableDetails.tsx @@ -100,6 +100,7 @@ export const EditableDetails: FunctionComponent = ({ data, valueId, id, + directorId, documents, title, workflowId, @@ -133,6 +134,7 @@ export const EditableDetails: FunctionComponent = ({ defaultValues, }); const { mutate: mutateUpdateWorkflowById } = useUpdateDocumentByIdMutation({ + directorId, workflowId, documentId: valueId, }); diff --git a/apps/backoffice-v2/src/lib/blocks/components/EditableDetails/interfaces.ts b/apps/backoffice-v2/src/lib/blocks/components/EditableDetails/interfaces.ts index 4da7f1351a..adbef3b696 100644 --- a/apps/backoffice-v2/src/lib/blocks/components/EditableDetails/interfaces.ts +++ b/apps/backoffice-v2/src/lib/blocks/components/EditableDetails/interfaces.ts @@ -22,6 +22,7 @@ export interface IEditableDetails { }>; valueId: string; id: string; + directorId?: string; documents: IEditableDetailsDocument[]; title: string; workflowId: string; diff --git a/apps/backoffice-v2/src/lib/blocks/create-blocks-typed/types.ts b/apps/backoffice-v2/src/lib/blocks/create-blocks-typed/types.ts index 79d3b6adfd..a8c059d80a 100644 --- a/apps/backoffice-v2/src/lib/blocks/create-blocks-typed/types.ts +++ b/apps/backoffice-v2/src/lib/blocks/create-blocks-typed/types.ts @@ -113,6 +113,7 @@ export type TDetailsCell = { type: 'details'; id: string; workflowId: string; + directorId?: string; hideSeparator?: boolean; documents?: IEditableDetailsDocument[]; contextUpdateMethod?: 'base' | 'director'; diff --git a/services/workflows-service/prisma/data-migrations b/services/workflows-service/prisma/data-migrations index 7c056b12ff..19836cde05 160000 --- a/services/workflows-service/prisma/data-migrations +++ b/services/workflows-service/prisma/data-migrations @@ -1 +1 @@ -Subproject commit 7c056b12ffa30c536a48be04178b437f3735d2db +Subproject commit 19836cde05901328729a88307e45a4cd5fef9998 diff --git a/services/workflows-service/src/workflow/dtos/document-update-update-input.ts b/services/workflows-service/src/workflow/dtos/document-update-update-input.ts index b8db0190c1..fb83d55b29 100644 --- a/services/workflows-service/src/workflow/dtos/document-update-update-input.ts +++ b/services/workflows-service/src/workflow/dtos/document-update-update-input.ts @@ -1,5 +1,5 @@ import { ApiProperty } from '@nestjs/swagger'; -import { IsObject } from 'class-validator'; +import { IsObject, IsOptional, IsString } from 'class-validator'; export class DocumentUpdateInput { @ApiProperty({ @@ -8,4 +8,12 @@ export class DocumentUpdateInput { }) @IsObject() document!: any; + + @ApiProperty({ + required: false, + type: String, + }) + @IsOptional() + @IsString() + directorId?: string; } diff --git a/services/workflows-service/src/workflow/hook-callback-handler.service.ts b/services/workflows-service/src/workflow/hook-callback-handler.service.ts index ea413ff948..dbdfa5a786 100644 --- a/services/workflows-service/src/workflow/hook-callback-handler.service.ts +++ b/services/workflows-service/src/workflow/hook-callback-handler.service.ts @@ -363,7 +363,11 @@ export class HookCallbackHandlerService { // @ts-expect-error - we don't validate `context` is an object this.setNestedProperty(context, attributePath, result); // @ts-expect-error - we don't validate `context` is an object - context.documents = persistedDocuments; + context.documents = [ + // @ts-expect-error - we don't validate `context` is an object + ...context.documents, + ...persistedDocuments, + ]; return context; } diff --git a/services/workflows-service/src/workflow/workflow.controller.internal.ts b/services/workflows-service/src/workflow/workflow.controller.internal.ts index db8b9de711..9c97ea6641 100644 --- a/services/workflows-service/src/workflow/workflow.controller.internal.ts +++ b/services/workflows-service/src/workflow/workflow.controller.internal.ts @@ -245,6 +245,7 @@ export class WorkflowControllerInternal { return await this.service.updateDocumentById( { workflowId: params?.id, + directorId: data?.directorId, documentId: params?.documentId, validateDocumentSchema: false, documentsUpdateContextMethod: query.contextUpdateMethod,