fix customer put queries
This commit is contained in:
parent
78c7364a81
commit
e72d4e9203
@ -1,9 +1,9 @@
|
|||||||
import { Response, Request } from "express";
|
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 ApiController from "@Common/system/controller-pattern/ApiController";
|
||||||
import { Service } from "typedi";
|
import { Service } from "typedi";
|
||||||
import FilesService from "@Services/common/FilesService/FilesService";
|
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 { File } from "le-coffre-resources/dist/Customer";
|
||||||
import { Document } from "le-coffre-resources/dist/Customer";
|
import { Document } from "le-coffre-resources/dist/Customer";
|
||||||
import DocumentsService from "@Services/customer/DocumentsService/DocumentsService";
|
import DocumentsService from "@Services/customer/DocumentsService/DocumentsService";
|
||||||
@ -15,7 +15,11 @@ import { validateOrReject } from "class-validator";
|
|||||||
@Controller()
|
@Controller()
|
||||||
@Service()
|
@Service()
|
||||||
export default class FilesController extends ApiController {
|
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();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,7 +124,6 @@ export default class FilesController extends ApiController {
|
|||||||
strategy: "excludeAll",
|
strategy: "excludeAll",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
//success
|
//success
|
||||||
this.httpCreated(response, fileEntityHydrated);
|
this.httpCreated(response, fileEntityHydrated);
|
||||||
} catch (error) {
|
} 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
|
* @description Delete a specific File
|
||||||
*/
|
*/
|
||||||
|
@ -125,6 +125,7 @@ export default class CustomersController extends ApiController {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (customerEntity.contact?.email) {
|
||||||
const customers = await this.customersService.get({
|
const customers = await this.customersService.get({
|
||||||
where: {
|
where: {
|
||||||
contact: { email: customerEntity.contact?.email },
|
contact: { email: customerEntity.contact?.email },
|
||||||
@ -148,6 +149,7 @@ export default class CustomersController extends ApiController {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//call service to get prisma entity
|
//call service to get prisma entity
|
||||||
try {
|
try {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user