From 9a261188394f4f226e983a3dfcbde37043b58956 Mon Sep 17 00:00:00 2001 From: Vincent Alamelle Date: Tue, 9 May 2023 12:22:24 +0200 Subject: [PATCH] Added refused_reason to update document + check if file on delete document --- src/app/api/super-admin/DocumentsController.ts | 4 ++-- .../super-admin/DocumentsService/DocumentsService.ts | 10 ++++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/app/api/super-admin/DocumentsController.ts b/src/app/api/super-admin/DocumentsController.ts index 769ef36b..4cbd9767 100644 --- a/src/app/api/super-admin/DocumentsController.ts +++ b/src/app/api/super-admin/DocumentsController.ts @@ -81,13 +81,13 @@ export default class DocumentsController extends ApiController { } //init Document resource with request body values - const documentEntity = Document.hydrate(req.body); + const documentEntity = Document.hydrate(req.body); //validate document await validateOrReject(documentEntity, { groups: ["updateDocument"] }); //call service to get prisma entity - const prismaEntityUpdated: Documents = await this.documentsService.update(uid, documentEntity); + const prismaEntityUpdated: Documents = await this.documentsService.update(uid, documentEntity, req.body.refused_reason); //Hydrate ressource with prisma entity const document = Document.hydrate(prismaEntityUpdated, { strategy: "excludeAll" }); diff --git a/src/services/super-admin/DocumentsService/DocumentsService.ts b/src/services/super-admin/DocumentsService/DocumentsService.ts index 4e466535..5b6e7217 100644 --- a/src/services/super-admin/DocumentsService/DocumentsService.ts +++ b/src/services/super-admin/DocumentsService/DocumentsService.ts @@ -38,8 +38,8 @@ export default class DocumentsService extends BaseService { * @description : Modify a document * @throws {Error} If document cannot be modified */ - public async update(uid: string, document: Document): Promise { - return this.documentsRepository.update(uid, document); + public async update(uid: string, document: Document, refused_reason?: string): Promise { + return this.documentsRepository.update(uid, document, refused_reason); } /** @@ -55,6 +55,12 @@ export default class DocumentsService extends BaseService { * @throws {Error} If document cannot be get by uid */ public async getByUid(uid: string, query?: any) { + const documentEntity = await this.documentsRepository.findOneByUid(uid, { office_folder_has_customers: true }); + const document = Document.hydrate(documentEntity, { strategy: "excludeAll" }); + + if (document.files && document.files.length !== 0) { + throw new Error("Can't delete a document with file"); + } return this.documentsRepository.findOneByUid(uid, query); } }