Merge branch 'staging' into preprod

This commit is contained in:
Vins 2024-12-04 15:23:28 +01:00
commit 85c9503502
4 changed files with 29 additions and 6 deletions

View File

@ -114,6 +114,7 @@ export default class DocumentsController extends ApiController {
const folder = await this.officeFoldersService.getByUid(documentEntity.folder.uid, { const folder = await this.officeFoldersService.getByUid(documentEntity.folder.uid, {
folder_anchor: true, folder_anchor: true,
customers: { include: { contact: true } }, customers: { include: { contact: true } },
office: true,
}); });
if (!folder) { if (!folder) {
this.httpBadRequest(response, "Folder not found"); this.httpBadRequest(response, "Folder not found");
@ -138,7 +139,7 @@ export default class DocumentsController extends ApiController {
} }
//call service to get prisma entity //call service to get prisma entity
const documentEntityCreated = await this.documentsService.create(documentEntity); const documentEntityCreated = await this.documentsService.create(documentEntity, folder.office_uid);
//Hydrate ressource with prisma entity //Hydrate ressource with prisma entity
const document = Document.hydrate<Document>(documentEntityCreated, { const document = Document.hydrate<Document>(documentEntityCreated, {

View File

@ -6,6 +6,7 @@ import { Prisma } from "@prisma/client";
import authHandler from "@App/middlewares/AuthHandler"; import authHandler from "@App/middlewares/AuthHandler";
import Note from "le-coffre-resources/dist/Customer/Note"; import Note from "le-coffre-resources/dist/Customer/Note";
import NotesService from "@Services/customer/NotesService/NotesService"; import NotesService from "@Services/customer/NotesService/NotesService";
import noteHandler from "@App/middlewares/CustomerHandler/NoteHandler";
@Controller() @Controller()
@Service() @Service()
@ -128,7 +129,7 @@ export default class NotesController extends ApiController {
/** /**
* @description Create a new note * @description Create a new note
*/ */
@Post("/api/v1/customer/notes", [authHandler]) @Post("/api/v1/customer/notes", [authHandler, noteHandler])
protected async post(req: Request, response: Response) { protected async post(req: Request, response: Response) {
try { try {
//init OfficeFolder resource with request body values //init OfficeFolder resource with request body values
@ -157,7 +158,7 @@ export default class NotesController extends ApiController {
/** /**
* @description Modify a specific note by uid * @description Modify a specific note by uid
*/ */
@Put("/api/v1/customer/notes/:uid", [authHandler]) @Put("/api/v1/customer/notes/:uid", [authHandler, noteHandler])
protected async put(req: Request, response: Response) { protected async put(req: Request, response: Response) {
try { try {
const uid = req.params["uid"]; const uid = req.params["uid"];

View File

@ -0,0 +1,20 @@
import HttpCodes from "@Common/system/controller-pattern/HttpCodes";
import { NextFunction, Request, Response } from "express";
export default async function noteHandler(req: Request, response: Response, next: NextFunction) {
try {
const content = req.body.content;
if (content && content.length > 250) {
response.status(HttpCodes.VALIDATION_ERROR).send([{ property: "content", constraints: { content: "La note dépasse 250 caractères" } }]);
return;
}
next();
} catch (error) {
console.error(error);
response.status(HttpCodes.INTERNAL_ERROR).send("Internal server error");
return;
}
}

View File

@ -23,8 +23,9 @@ export default class DocumentsService extends BaseService {
* @description : Create a new document * @description : Create a new document
* @throws {Error} If document cannot be created * @throws {Error} If document cannot be created
*/ */
public async create(document: Document): Promise<Documents> { public async create(document: Document, office_uid: string): Promise<Documents> {
const otherDocumentType = await this.documentTypeService.get({ where: { name: "Autres documents" } });
const otherDocumentType = await this.documentTypeService.get({ where: { name: "Autres documents", office_uid: office_uid } });
if(otherDocumentType.length < 1) throw new Error("Autres documents document type not found"); if(otherDocumentType.length < 1) throw new Error("Autres documents document type not found");