diff --git a/src/app/api/notary/DocumentsNotaryController.ts b/src/app/api/notary/DocumentsNotaryController.ts index d6cf82e2..1552646e 100644 --- a/src/app/api/notary/DocumentsNotaryController.ts +++ b/src/app/api/notary/DocumentsNotaryController.ts @@ -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(documentEntities, { strategy: "excludeAll" }); + const documents = DocumentNotary.hydrateArray(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(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(documentEntity, { strategy: "excludeAll" }); + // //Hydrate ressource with prisma entity + // const document = Document.hydrate(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(documentEntity, { strategy: "excludeAll" }); + // //Hydrate ressource with prisma entity + // const document = Document.hydrate(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; + // } + // } }