Fixed Notary Documents

This commit is contained in:
Vins 2024-09-09 11:15:28 +02:00
parent 3e64472821
commit 8f5974ab59

View File

@ -1,13 +1,11 @@
import { Response, Request } from "express";
import { Controller, Delete, Get, Post } from "@ControllerPattern/index";
import { Controller, Get, Post } from "@ControllerPattern/index";
import ApiController from "@Common/system/controller-pattern/ApiController";
import { Service } from "typedi";
import DocumentsNotaryService from "@Services/notary/DocumentsNotaryService/DocumentsNotaryService";
import { DocumentsNotary, Prisma } from "@prisma/client";
import { Document, DocumentNotary, FileNotary } from "le-coffre-resources/dist/Notary";
import { Prisma } from "@prisma/client";
import { DocumentNotary, FileNotary } from "le-coffre-resources/dist/Notary";
import authHandler from "@App/middlewares/AuthHandler";
import ruleHandler from "@App/middlewares/RulesHandler";
import documentHandler from "@App/middlewares/OfficeMembershipHandlers/DocumentHandler";
import OfficeFoldersService from "@Services/notary/OfficeFoldersService/OfficeFoldersService";
import CustomersService from "@Services/admin/CustomersService/CustomersService";
import UsersService from "@Services/notary/UsersService/UsersService";
@ -31,7 +29,7 @@ export default class DocumentsNotaryController extends ApiController {
* @description Get all documents
* @returns IDocument[] list of documents
*/
@Get("/api/v1/notary/documents_notary", [authHandler, ruleHandler])
@Get("/api/v1/notary/documents_notary", [authHandler])
protected async get(req: Request, response: Response) {
try {
//get query
@ -52,7 +50,7 @@ export default class DocumentsNotaryController extends ApiController {
const documentEntities = await this.documentsNotaryService.get(query);
//Hydrate ressource with prisma entity
const documents = Document.hydrateArray<Document>(documentEntities, { strategy: "excludeAll" });
const documents = DocumentNotary.hydrateArray<DocumentNotary>(documentEntities, { strategy: "excludeAll" });
//success
this.httpSuccess(response, documents);
@ -69,6 +67,8 @@ export default class DocumentsNotaryController extends ApiController {
@Post("/api/v1/notary/documents_notary", [authHandler])
protected async post(req: Request, response: Response) {
try {
console.log("req.file", req.file);
if(!req.file) return;
const customer = await this.customerService.getByUid(req.body.customerUid);
@ -95,7 +95,7 @@ export default class DocumentsNotaryController extends ApiController {
const fileEntity = FileNotary.hydrate<FileNotary>(JSON.parse(query));
const fileEntityCreated = await this.filesService.createFileNotary(fileEntity, req.file);
const fileEntityCreated = await this.filesService.createFileNotary(fileEntity, req.file!);
console.log("fileEntityCreated", fileEntityCreated);
@ -137,71 +137,71 @@ export default class DocumentsNotaryController extends ApiController {
}
}
/**
* @description Delete a specific document
*/
@Delete("/api/v1/notary/documents_notary/:uid", [authHandler, ruleHandler, documentHandler])
protected async delete(req: Request, response: Response) {
try {
const uid = req.params["uid"];
if (!uid) {
this.httpBadRequest(response, "No uid provided");
return;
}
// /**
// * @description Delete a specific document
// */
// @Delete("/api/v1/notary/documents_notary/:uid", [authHandler, ruleHandler, documentHandler])
// protected async delete(req: Request, response: Response) {
// try {
// const uid = req.params["uid"];
// if (!uid) {
// this.httpBadRequest(response, "No uid provided");
// return;
// }
const documentFound = await this.documentsNotaryService.getByUid(uid);
// const documentFound = await this.documentsNotaryService.getByUid(uid);
if (!documentFound) {
this.httpNotFoundRequest(response, "document not found");
return;
}
// if (!documentFound) {
// this.httpNotFoundRequest(response, "document not found");
// return;
// }
//call service to get prisma entity
const documentEntity: DocumentsNotary = await this.documentsNotaryService.delete(uid);
// //call service to get prisma entity
// const documentEntity: DocumentsNotary = await this.documentsNotaryService.delete(uid);
//Hydrate ressource with prisma entity
const document = Document.hydrate<Document>(documentEntity, { strategy: "excludeAll" });
// //Hydrate ressource with prisma entity
// const document = Document.hydrate<Document>(documentEntity, { strategy: "excludeAll" });
//success
this.httpSuccess(response, document);
} catch (error) {
this.httpInternalError(response, error);
return;
}
}
// //success
// this.httpSuccess(response, document);
// } catch (error) {
// this.httpInternalError(response, error);
// return;
// }
// }
/**
* @description Get a specific document by uid
*/
@Get("/api/v1/notary/documents_notary/:uid", [authHandler, ruleHandler, documentHandler])
protected async getOneByUid(req: Request, response: Response) {
try {
const uid = req.params["uid"];
if (!uid) {
this.httpBadRequest(response, "No uid provided");
return;
}
//get query
let query;
if (req.query["q"]) {
query = JSON.parse(req.query["q"] as string);
}
// /**
// * @description Get a specific document by uid
// */
// @Get("/api/v1/notary/documents_notary/:uid", [authHandler, ruleHandler, documentHandler])
// protected async getOneByUid(req: Request, response: Response) {
// try {
// const uid = req.params["uid"];
// if (!uid) {
// this.httpBadRequest(response, "No uid provided");
// return;
// }
// //get query
// let query;
// if (req.query["q"]) {
// query = JSON.parse(req.query["q"] as string);
// }
const documentEntity = await this.documentsNotaryService.getByUid(uid, query);
// const documentEntity = await this.documentsNotaryService.getByUid(uid, query);
if (!documentEntity) {
this.httpNotFoundRequest(response, "document not found");
return;
}
// if (!documentEntity) {
// this.httpNotFoundRequest(response, "document not found");
// return;
// }
//Hydrate ressource with prisma entity
const document = Document.hydrate<Document>(documentEntity, { strategy: "excludeAll" });
// //Hydrate ressource with prisma entity
// const document = Document.hydrate<Document>(documentEntity, { strategy: "excludeAll" });
//success
this.httpSuccess(response, document);
} catch (error) {
this.httpInternalError(response, error);
return;
}
}
// //success
// this.httpSuccess(response, document);
// } catch (error) {
// this.httpInternalError(response, error);
// return;
// }
// }
}