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