From 14aa7e92cb059eb8ba907f8222242150d689d2ce Mon Sep 17 00:00:00 2001 From: Max S Date: Mon, 19 Aug 2024 10:54:12 +0200 Subject: [PATCH 1/2] :bug: change status to ASKED when delete the last document file --- src/app/api/customer/FilesController.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/app/api/customer/FilesController.ts b/src/app/api/customer/FilesController.ts index a5795688..12d91eae 100644 --- a/src/app/api/customer/FilesController.ts +++ b/src/app/api/customer/FilesController.ts @@ -159,13 +159,19 @@ export default class FilesController extends ApiController { //call service to get prisma entity const fileEntity = await this.filesService.deleteKeyAndArchive(uid); - if ( - !(fileFoundEntity.document!.files?.find((file) => file.archived_at === null && file.uid !== uid)) && - fileFoundEntity.document!.document_type!.name === "Autres documents" - ) { + + const isDocumentEmpty = !fileFoundEntity.document!.files?.find((file) => file.archived_at === null && file.uid !== uid); + if (isDocumentEmpty && fileFoundEntity.document!.document_type!.name === "Autres documents") { await this.documentService.delete(fileFoundEntity.document!.uid!); } + // Update document status to 'ASKED' if the deleted file was the last one + if (fileFoundEntity.document && fileFoundEntity.document.uid && isDocumentEmpty) { + const documentToUpdate = Document.hydrate(fileFoundEntity.document); + documentToUpdate.document_status = "ASKED"; + this.documentService.update(fileFoundEntity.document.uid, documentToUpdate); + } + //Hydrate ressource with prisma entity const file = File.hydrate(fileEntity, { strategy: "excludeAll" }); From 6aaf8749d6ca3edd1888796ec1b945064441ccd1 Mon Sep 17 00:00:00 2001 From: Maxime Sallerin <97036207+maxime-sallerin@users.noreply.github.com> Date: Mon, 19 Aug 2024 14:49:37 +0200 Subject: [PATCH 2/2] :bug: Change status to ASKED when delete the last document file (#202) --- src/app/api/customer/FilesController.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/app/api/customer/FilesController.ts b/src/app/api/customer/FilesController.ts index a5795688..12d91eae 100644 --- a/src/app/api/customer/FilesController.ts +++ b/src/app/api/customer/FilesController.ts @@ -159,13 +159,19 @@ export default class FilesController extends ApiController { //call service to get prisma entity const fileEntity = await this.filesService.deleteKeyAndArchive(uid); - if ( - !(fileFoundEntity.document!.files?.find((file) => file.archived_at === null && file.uid !== uid)) && - fileFoundEntity.document!.document_type!.name === "Autres documents" - ) { + + const isDocumentEmpty = !fileFoundEntity.document!.files?.find((file) => file.archived_at === null && file.uid !== uid); + if (isDocumentEmpty && fileFoundEntity.document!.document_type!.name === "Autres documents") { await this.documentService.delete(fileFoundEntity.document!.uid!); } + // Update document status to 'ASKED' if the deleted file was the last one + if (fileFoundEntity.document && fileFoundEntity.document.uid && isDocumentEmpty) { + const documentToUpdate = Document.hydrate(fileFoundEntity.document); + documentToUpdate.document_status = "ASKED"; + this.documentService.update(fileFoundEntity.document.uid, documentToUpdate); + } + //Hydrate ressource with prisma entity const file = File.hydrate(fileEntity, { strategy: "excludeAll" });