fix customer put queries

This commit is contained in:
OxSaitama 2023-10-23 19:30:11 +02:00
parent 78c7364a81
commit e72d4e9203
2 changed files with 29 additions and 59 deletions

View File

@ -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();
}
@ -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<File>(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<File>(fileEntityUpdated, { strategy: "excludeAll" });
//success
this.httpSuccess(response, file);
} catch (error) {
this.httpBadRequest(response, error);
return;
}
}
/**
* @description Delete a specific File
*/

View File

@ -125,6 +125,7 @@ export default class CustomersController extends ApiController {
return;
}
if (customerEntity.contact?.email) {
const customers = await this.customersService.get({
where: {
contact: { email: customerEntity.contact?.email },
@ -148,6 +149,7 @@ export default class CustomersController extends ApiController {
return;
}
}
}
//call service to get prisma entity
try {