diff --git a/src/common/Api/LeCoffreApi/sdk/CollaboratorService.ts b/src/common/Api/LeCoffreApi/sdk/CollaboratorService.ts index 809fde98..4737f7f4 100644 --- a/src/common/Api/LeCoffreApi/sdk/CollaboratorService.ts +++ b/src/common/Api/LeCoffreApi/sdk/CollaboratorService.ts @@ -98,6 +98,9 @@ export default class CollaboratorService extends AbstractService { !items.map((item: any) => item.processData.uid).includes(publicValues['uid']) ).then(async (processes: any[]) => { if (processes.length === 0) { + if (waitForAll) { + callback([...items]); + } return; } @@ -147,25 +150,32 @@ export default class CollaboratorService extends AbstractService { public static getCollaboratorsBy(whereClause: { [path: string]: any }): Promise { return new Promise((resolve: (collaborators: any[]) => void) => { this.getCollaborators((processes: any[]) => { - resolve(processes.length > 0 ? processes.map((process: any) => process.processData).filter((collaborator: any) => { - for (const path in whereClause) { - const paths: string[] = path.split('.'); + if (processes.length === 0) { + resolve([]); + } else { + resolve(processes.filter((process: any) => { + const collaborator: any = process.processData; - let value: any = collaborator; - for (let i = 0; i < paths.length; i++) { - const currentPath = paths[i]; - if (!currentPath || value === undefined || value === null) { - break; + for (const path in whereClause) { + const paths: string[] = path.split('.'); + + let value: any = collaborator; + for (let i = 0; i < paths.length; i++) { + const currentPath = paths[i]; + if (!currentPath || value === undefined || value === null) { + break; + } + value = value[currentPath]; + } + + if (value !== whereClause[path]) { + return false; } - value = value[currentPath]; } - if (value !== whereClause[path]) { - return false; - } - } - return true; - }) : []); + return true; + })); + } }, true); }); } @@ -173,25 +183,32 @@ export default class CollaboratorService extends AbstractService { public static getCollaboratorBy(whereClause: { [path: string]: any }): Promise { return new Promise((resolve: (collaborator: any | null) => void) => { this.getCollaborators((processes: any[]) => { - resolve(processes.length > 0 ? processes.map((process: any) => process.processData).find((collaborator: any) => { - for (const path in whereClause) { - const paths: string[] = path.split('.'); + if (processes.length === 0) { + resolve(null); + } else { + resolve(processes.find((process: any) => { + const collaborator: any = process.processData; - let value: any = collaborator; - for (let i = 0; i < paths.length; i++) { - const currentPath = paths[i]; - if (!currentPath || value === undefined || value === null) { - break; + for (const path in whereClause) { + const paths: string[] = path.split('.'); + + let value: any = collaborator; + for (let i = 0; i < paths.length; i++) { + const currentPath = paths[i]; + if (!currentPath || value === undefined || value === null) { + break; + } + value = value[currentPath]; + } + + if (value !== whereClause[path]) { + return false; } - value = value[currentPath]; } - if (value !== whereClause[path]) { - return false; - } - } - return true; - }) : null); + return true; + })); + } }, true); }); } diff --git a/src/common/Api/LeCoffreApi/sdk/DeedTypeService.ts b/src/common/Api/LeCoffreApi/sdk/DeedTypeService.ts index 12cd9d71..6917cc0c 100644 --- a/src/common/Api/LeCoffreApi/sdk/DeedTypeService.ts +++ b/src/common/Api/LeCoffreApi/sdk/DeedTypeService.ts @@ -95,6 +95,9 @@ export default class DeedTypeService extends AbstractService { !items.map((item: any) => item.processData.uid).includes(publicValues['uid']) ).then(async (processes: any[]) => { if (processes.length === 0) { + if (waitForAll) { + callback([...items]); + } return; } diff --git a/src/common/Api/LeCoffreApi/sdk/FolderService.ts b/src/common/Api/LeCoffreApi/sdk/FolderService.ts index 58566cce..a20be304 100644 --- a/src/common/Api/LeCoffreApi/sdk/FolderService.ts +++ b/src/common/Api/LeCoffreApi/sdk/FolderService.ts @@ -107,6 +107,9 @@ export default class FolderService extends AbstractService { !items.map((item: any) => item.processData.uid).includes(publicValues['uid']) ).then(async (processes: any[]) => { if (processes.length === 0) { + if (waitForAll) { + callback([...items]); + } return; } @@ -156,25 +159,32 @@ export default class FolderService extends AbstractService { public static getFoldersBy(whereClause: { [path: string]: any }): Promise { return new Promise((resolve: (folders: any[]) => void) => { this.getFolders((processes: any[]) => { - resolve(processes.length > 0 ? processes.map((process: any) => process.processData).filter((folder: any) => { - for (const path in whereClause) { - const paths: string[] = path.split('.'); + if (processes.length === 0) { + resolve([]); + } else { + resolve(processes.filter((process: any) => { + const folder: any = process.processData; - let value: any = folder; - for (let i = 0; i < paths.length; i++) { - const currentPath = paths[i]; - if (!currentPath || value === undefined || value === null) { - break; + for (const path in whereClause) { + const paths: string[] = path.split('.'); + + let value: any = folder; + for (let i = 0; i < paths.length; i++) { + const currentPath = paths[i]; + if (!currentPath || value === undefined || value === null) { + break; + } + value = value[currentPath]; + } + + if (value !== whereClause[path]) { + return false; } - value = value[currentPath]; } - if (value !== whereClause[path]) { - return false; - } - } - return true; - }) : []); + return true; + })); + } }, true); }); } diff --git a/src/front/Components/Layouts/ClientDashboard/ReceivedDocuments/index.tsx b/src/front/Components/Layouts/ClientDashboard/ReceivedDocuments/index.tsx index 75071c0a..8062c0d8 100644 --- a/src/front/Components/Layouts/ClientDashboard/ReceivedDocuments/index.tsx +++ b/src/front/Components/Layouts/ClientDashboard/ReceivedDocuments/index.tsx @@ -16,6 +16,7 @@ import classes from "./classes.module.scss"; import Link from "next/link"; import Customer from "le-coffre-resources/dist/Customer"; import { DocumentNotary } from "le-coffre-resources/dist/Notary"; +import { EDocumentNotaryStatus } from "le-coffre-resources/dist/Notary/DocumentNotary"; import FolderService from "src/common/Api/LeCoffreApi/sdk/FolderService"; import DocumentService from "src/common/Api/LeCoffreApi/sdk/DocumentService"; @@ -133,10 +134,24 @@ export default function ReceivedDocuments() { }); }, [folderUid, customer]); - const onDownload = useCallback((doc: any) => { + const onDownload = useCallback(async (doc: any) => { const file = doc.files?.[0]; if (!file) return; + if (doc.document_status !== EDocumentNotaryStatus.DOWNLOADED) { + await new Promise((resolve: () => void) => { + LoaderService.getInstance().show(); + DocumentService.getDocumentByUid(doc.uid).then((process: any) => { + if (process) { + DocumentService.updateDocument(process, { document_status: EDocumentNotaryStatus.DOWNLOADED }).then(() => { + LoaderService.getInstance().hide(); + resolve(); + }); + } + }); + }); + } + return new Promise((resolve: () => void) => { const blob = new Blob([file.file_blob.data], { type: file.file_blob.type }); const url = URL.createObjectURL(blob); @@ -158,9 +173,23 @@ export default function ReceivedDocuments() { const zip = new JSZip(); const folder = zip.folder("documents") || zip; - documentsNotary.map((doc: any) => { + documentsNotary.map(async (doc: any) => { const file = doc.files?.[0]; if (file) { + if (doc.document_status !== EDocumentNotaryStatus.DOWNLOADED) { + await new Promise((resolve: () => void) => { + LoaderService.getInstance().show(); + DocumentService.getDocumentByUid(doc.uid).then((process: any) => { + if (process) { + DocumentService.updateDocument(process, { document_status: EDocumentNotaryStatus.DOWNLOADED }).then(() => { + LoaderService.getInstance().hide(); + resolve(); + }); + } + }); + }); + } + const blob = new Blob([file.file_blob.data], { type: file.file_blob.type }); folder.file(file.file_name ?? "file", blob); } diff --git a/src/front/Components/Layouts/DeedTypes/DeedTypesInformations/index.tsx b/src/front/Components/Layouts/DeedTypes/DeedTypesInformations/index.tsx index 94d28a49..8b017bb3 100644 --- a/src/front/Components/Layouts/DeedTypes/DeedTypesInformations/index.tsx +++ b/src/front/Components/Layouts/DeedTypes/DeedTypesInformations/index.tsx @@ -54,7 +54,7 @@ export default function DeedTypesInformations(props: IProps) { LoaderService.getInstance().show(); DeedTypeService.getDeedTypeByUid(deedTypeUid as string).then((process: any) => { if (process) { - DeedTypeService.updateDeedType(process, { archived_at: new Date().toISOString() }).then(() => { + DeedTypeService.updateDeedType(process, { isDeleted: 'true', archived_at: new Date().toISOString() }).then(() => { router.push(Module.getInstance().get().modules.pages.DeedTypes.props.path); LoaderService.getInstance().hide(); }); diff --git a/src/front/Components/Layouts/Folder/FolderInformation/elements/AnchoringAlertInfo/index.tsx b/src/front/Components/Layouts/Folder/FolderInformation/elements/AnchoringAlertInfo/index.tsx index 62a2e588..fcb75339 100644 --- a/src/front/Components/Layouts/Folder/FolderInformation/elements/AnchoringAlertInfo/index.tsx +++ b/src/front/Components/Layouts/Folder/FolderInformation/elements/AnchoringAlertInfo/index.tsx @@ -10,8 +10,8 @@ export default function AnchoringAlertInfo(props: IProps) { const { onAnchor } = props; return ( { return await new Promise(async (resolve: (role: any) => void) => { - const collaboratorFound: any | null = await CollaboratorService.getCollaboratorBy({ idNot: idNotUser.idNot }); - if (collaboratorFound) { - resolve(collaboratorFound); + const processFound: any | null = await CollaboratorService.getCollaboratorBy({ idNot: idNotUser.idNot }); + if (processFound) { + resolve(processFound.processData); } else { const validatorId: string = '884cb36a346a79af8697559f16940141f068bdf1656f88fa0df0e9ecd7311fb8:0'; CollaboratorService.createCollaborator(collaboratorData, validatorId).then((process: any) => { diff --git a/src/front/Components/Layouts/Offices/OfficeInformations/index.tsx b/src/front/Components/Layouts/Offices/OfficeInformations/index.tsx index 0fd36ef6..1965833c 100644 --- a/src/front/Components/Layouts/Offices/OfficeInformations/index.tsx +++ b/src/front/Components/Layouts/Offices/OfficeInformations/index.tsx @@ -32,7 +32,8 @@ export default function OfficeInformations(props: IProps) { if (!office) return; setOfficeSelected(office); - const users: any[] = await CollaboratorService.getCollaboratorsBy({ 'office.uid': office.uid }); + const users: any[] = (await CollaboratorService.getCollaboratorsBy({ 'office.uid': office.uid })) + .map((process: any) => process.processData); const adminUsers = users.filter((user) => { if (user.office_role && user.office_role.name === "admin") {