Skip to content

Commit

Permalink
Revisions and UBOs documents fixes (#2989)
Browse files Browse the repository at this point in the history
* fix(*): fixed director properties updating

* fix(workflows-service): no longer overriding documents with kyc documents

* chore(*): data migrations conflict
  • Loading branch information
Omri-Levy authored Jan 23, 2025
1 parent d02335d commit aee578b
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import { workflowsQueryKeys } from '../../../query-keys';

export const useUpdateDocumentByIdMutation = ({
workflowId,
directorId,
documentId,
}: {
workflowId: string;
directorId?: string;
documentId: string;
}) => {
const queryClient = useQueryClient();
Expand All @@ -29,6 +31,7 @@ export const useUpdateDocumentByIdMutation = ({
workflowId,
documentId,
body: {
directorId,
document,
},
contextUpdateMethod,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const Details: FunctionComponent<ExtractCellProps<'details'>> = ({
value,
hideSeparator,
contextUpdateMethod,
directorId,
workflowId,
documents = [],
onSubmit,
Expand All @@ -34,6 +35,7 @@ export const Details: FunctionComponent<ExtractCellProps<'details'>> = ({
>
<EditableDetails
workflowId={workflowId}
directorId={directorId}
id={id}
valueId={value?.id}
documents={documents}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,14 @@ export const directorDocumentsAdapter = ({ documents, storageFiles }) => {
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]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
);
Expand All @@ -112,6 +116,7 @@ export const useDirectorBlock = ({
.addCell({
type: 'details',
contextUpdateMethod: 'director',
directorId: director.id,
hideSeparator: true,
value: {
id: document.id,
Expand All @@ -124,7 +129,8 @@ export const useDirectorBlock = ({
: [],
},
workflowId,
documents,
// Otherwise imageUrl will be saved into the document.
documents: documentsWithoutImageUrl,
})
.cellAt(0, 0);

Expand Down Expand Up @@ -326,6 +332,7 @@ export const useDirectorBlock = ({
})
.addCell({
type: 'details',
directorId: director.id,
contextUpdateMethod: 'director',
value: {
id: document.id,
Expand Down Expand Up @@ -366,7 +373,8 @@ export const useDirectorBlock = ({
},
),
},
documents,
// Otherwise imageUrl will be saved into the document.
documents: documentsWithoutImageUrl,
workflowId,
})
.addCell(decisionCell)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export const EditableDetails: FunctionComponent<IEditableDetails> = ({
data,
valueId,
id,
directorId,
documents,
title,
workflowId,
Expand Down Expand Up @@ -133,6 +134,7 @@ export const EditableDetails: FunctionComponent<IEditableDetails> = ({
defaultValues,
});
const { mutate: mutateUpdateWorkflowById } = useUpdateDocumentByIdMutation({
directorId,
workflowId,
documentId: valueId,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface IEditableDetails {
}>;
valueId: string;
id: string;
directorId?: string;
documents: IEditableDetailsDocument[];
title: string;
workflowId: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export type TDetailsCell = {
type: 'details';
id: string;
workflowId: string;
directorId?: string;
hideSeparator?: boolean;
documents?: IEditableDetailsDocument[];
contextUpdateMethod?: 'base' | 'director';
Expand Down
2 changes: 1 addition & 1 deletion services/workflows-service/prisma/data-migrations
Original file line number Diff line number Diff line change
@@ -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({
Expand All @@ -8,4 +8,12 @@ export class DocumentUpdateInput {
})
@IsObject()
document!: any;

@ApiProperty({
required: false,
type: String,
})
@IsOptional()
@IsString()
directorId?: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit aee578b

Please sign in to comment.