From e72d4e920376acf641e9b2827c63f2a805d066dd Mon Sep 17 00:00:00 2001 From: OxSaitama Date: Mon, 23 Oct 2023 19:30:11 +0200 Subject: [PATCH] fix customer put queries --- src/app/api/customer/FilesController.ts | 50 ++++------------------- src/app/api/notary/CustomersController.ts | 38 +++++++++-------- 2 files changed, 29 insertions(+), 59 deletions(-) diff --git a/src/app/api/customer/FilesController.ts b/src/app/api/customer/FilesController.ts index 1cbe6b52..c2947a9c 100644 --- a/src/app/api/customer/FilesController.ts +++ b/src/app/api/customer/FilesController.ts @@ -1,9 +1,9 @@ import { Response, Request } from "express"; -import { Controller, Delete, Get, Post, Put } from "@ControllerPattern/index"; +import { Controller, Delete, Get, Post } from "@ControllerPattern/index"; import ApiController from "@Common/system/controller-pattern/ApiController"; import { Service } from "typedi"; import FilesService from "@Services/common/FilesService/FilesService"; -import { Files, Prisma } from "@prisma/client"; +import { Prisma } from "@prisma/client"; import { File } from "le-coffre-resources/dist/Customer"; import { Document } from "le-coffre-resources/dist/Customer"; import DocumentsService from "@Services/customer/DocumentsService/DocumentsService"; @@ -15,7 +15,11 @@ import { validateOrReject } from "class-validator"; @Controller() @Service() export default class FilesController extends ApiController { - constructor(private filesService: FilesService, private documentService: DocumentsService, private notificationBuilder : NotificationBuilder) { + constructor( + private filesService: FilesService, + private documentService: DocumentsService, + private notificationBuilder: NotificationBuilder, + ) { super(); } @@ -37,7 +41,7 @@ export default class FilesController extends ApiController { return; } if (query.where?.document?.depositor) delete query.where.document.depositor; - const customerWhereInput: Prisma.FilesWhereInput = { ...query.where, document: {depositor: { contact: { email: email } } }}; + const customerWhereInput: Prisma.FilesWhereInput = { ...query.where, document: { depositor: { contact: { email: email } } } }; query.where = customerWhereInput; if (query.include?.document) delete query.include.document; @@ -120,7 +124,6 @@ export default class FilesController extends ApiController { strategy: "excludeAll", }); - //success this.httpCreated(response, fileEntityHydrated); } catch (error) { @@ -129,41 +132,6 @@ export default class FilesController extends ApiController { } } - /** - * @description Update a specific file - */ - @Put("/api/v1/customer/files/:uid", [authHandler, fileHandler]) - protected async update(req: Request, response: Response) { - try { - const uid = req.params["uid"]; - if (!uid) { - throw new Error("No uid provided"); - } - - const fileFound = await this.filesService.getByUid(uid); - - if (!fileFound) { - this.httpNotFoundRequest(response, "file not found"); - return; - } - - //init File resource with request body values - const fileEntity = File.hydrate(req.body); - - //call service to get prisma entity - const fileEntityUpdated: Files = await this.filesService.update(uid, fileEntity); - - //Hydrate ressource with prisma entity - const file = File.hydrate(fileEntityUpdated, { strategy: "excludeAll" }); - - //success - this.httpSuccess(response, file); - } catch (error) { - this.httpBadRequest(response, error); - return; - } - } - /** * @description Delete a specific File */ @@ -217,7 +185,7 @@ export default class FilesController extends ApiController { let query; if (req.query["q"]) { query = JSON.parse(req.query["q"] as string); - if(query.document) delete query.document; + if (query.document) delete query.document; } const fileEntity = await this.filesService.getByUid(uid, query); diff --git a/src/app/api/notary/CustomersController.ts b/src/app/api/notary/CustomersController.ts index 349229cf..f5bc1789 100644 --- a/src/app/api/notary/CustomersController.ts +++ b/src/app/api/notary/CustomersController.ts @@ -125,27 +125,29 @@ export default class CustomersController extends ApiController { return; } - const customers = await this.customersService.get({ - where: { - contact: { email: customerEntity.contact?.email }, - office_folders: { - some: { - office_uid: req.body.user.office_Id, + if (customerEntity.contact?.email) { + const customers = await this.customersService.get({ + where: { + contact: { email: customerEntity.contact?.email }, + office_folders: { + some: { + office_uid: req.body.user.office_Id, + }, }, }, - }, - }); + }); - if (customers.length != 0) { - try { - customers.forEach((customer) => { - if (customer.uid != uid) { - throw new Error("email déjà utilisé"); - } - }); - } catch (error) { - this.httpValidationError(response, [{ property: "email", constraints: { unique: "email déjà utilisé" } }]); - return; + if (customers.length != 0) { + try { + customers.forEach((customer) => { + if (customer.uid != uid) { + throw new Error("email déjà utilisé"); + } + }); + } catch (error) { + this.httpValidationError(response, [{ property: "email", constraints: { unique: "email déjà utilisé" } }]); + return; + } } }