Merge branch 'preprod'
This commit is contained in:
commit
75347cf1bc
@ -103,7 +103,7 @@ export default class DocumentsController extends ApiController {
|
||||
protected async post(req: Request, response: Response) {
|
||||
try {
|
||||
//init Document resource with request body values
|
||||
const documentEntity = Document.hydrate<Document>(req.body);
|
||||
const documentEntity = Document.hydrate<Document>(req.body);
|
||||
const email = req.body.user.email;
|
||||
|
||||
if (!documentEntity.folder?.uid) {
|
||||
@ -114,6 +114,7 @@ export default class DocumentsController extends ApiController {
|
||||
const folder = await this.officeFoldersService.getByUid(documentEntity.folder.uid, {
|
||||
folder_anchor: true,
|
||||
customers: { include: { contact: true } },
|
||||
office: true,
|
||||
});
|
||||
if (!folder) {
|
||||
this.httpBadRequest(response, "Folder not found");
|
||||
@ -138,7 +139,7 @@ export default class DocumentsController extends ApiController {
|
||||
}
|
||||
|
||||
//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
|
||||
const document = Document.hydrate<Document>(documentEntityCreated, {
|
||||
|
@ -6,6 +6,7 @@ import { Prisma } from "@prisma/client";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import Note from "le-coffre-resources/dist/Customer/Note";
|
||||
import NotesService from "@Services/customer/NotesService/NotesService";
|
||||
import noteHandler from "@App/middlewares/CustomerHandler/NoteHandler";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
@ -128,7 +129,7 @@ export default class NotesController extends ApiController {
|
||||
/**
|
||||
* @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) {
|
||||
try {
|
||||
//init OfficeFolder resource with request body values
|
||||
@ -157,7 +158,7 @@ export default class NotesController extends ApiController {
|
||||
/**
|
||||
* @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) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
|
@ -50,6 +50,26 @@ export default class DocumentsReminderController extends ApiController {
|
||||
}
|
||||
}
|
||||
|
||||
@Get ("/api/v1/notary/document_reminders/count", [authHandler])
|
||||
protected async count(req: Request, response: Response) {
|
||||
try {
|
||||
//get query
|
||||
let query: Prisma.DocumentsReminderCountArgs = {};
|
||||
|
||||
//call service to get prisma entity
|
||||
const count = await this.documentsReminderService.count(query);
|
||||
const responseData = {
|
||||
count: count
|
||||
}
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, responseData);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @description Get a specific document by uid
|
||||
// */
|
||||
|
20
src/app/middlewares/CustomerHandler/NoteHandler.ts
Normal file
20
src/app/middlewares/CustomerHandler/NoteHandler.ts
Normal 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;
|
||||
}
|
||||
}
|
@ -43,4 +43,8 @@ export default class DocumentsReminderRepository extends BaseRepository {
|
||||
|
||||
return documentReminderCreated;
|
||||
}
|
||||
|
||||
public async count (query: Prisma.DocumentsReminderCountArgs) {
|
||||
return this.model.count(query);
|
||||
}
|
||||
}
|
||||
|
@ -23,8 +23,9 @@ export default class DocumentsService extends BaseService {
|
||||
* @description : Create a new document
|
||||
* @throws {Error} If document cannot be created
|
||||
*/
|
||||
public async create(document: Document): Promise<Documents> {
|
||||
const otherDocumentType = await this.documentTypeService.get({ where: { name: "Autres documents" } });
|
||||
public async create(document: Document, office_uid: string): Promise<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");
|
||||
|
||||
|
@ -25,4 +25,8 @@ export default class DocumentsReminderService extends BaseService {
|
||||
public async create(document: DocumentReminder): Promise<DocumentsReminder> {
|
||||
return this.documentsReminderRepository.create(document);
|
||||
}
|
||||
|
||||
public async count (query: Prisma.DocumentsReminderCountArgs) {
|
||||
return this.documentsReminderRepository.count(query);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user