Endpoint delete document notary
This commit is contained in:
parent
8f5974ab59
commit
a68d8b817a
50
src/app/api/customer/DocumentsNotaryController.ts
Normal file
50
src/app/api/customer/DocumentsNotaryController.ts
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
import { Response, Request } from "express";
|
||||||
|
import { Controller, Get } from "@ControllerPattern/index";
|
||||||
|
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||||
|
import { Service } from "typedi";
|
||||||
|
import DocumentsNotaryService from "@Services/notary/DocumentsNotaryService/DocumentsNotaryService";
|
||||||
|
import { Prisma } from "@prisma/client";
|
||||||
|
import { DocumentNotary } from "le-coffre-resources/dist/Notary";
|
||||||
|
import authHandler from "@App/middlewares/AuthHandler";
|
||||||
|
// import NotificationBuilder from "@Common/notifications/NotificationBuilder";
|
||||||
|
|
||||||
|
@Controller()
|
||||||
|
@Service()
|
||||||
|
export default class DocumentsNotaryController extends ApiController {
|
||||||
|
constructor(
|
||||||
|
private documentsNotaryService: DocumentsNotaryService,
|
||||||
|
) {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Get all documents
|
||||||
|
* @returns IDocument[] list of documents
|
||||||
|
*/
|
||||||
|
@Get("/api/v1/customer/documents_notary", [authHandler])
|
||||||
|
protected async get(req: Request, response: Response) {
|
||||||
|
try {
|
||||||
|
//get query
|
||||||
|
let query: Prisma.DocumentsNotaryFindManyArgs = {};
|
||||||
|
if (req.query["q"]) {
|
||||||
|
query = JSON.parse(req.query["q"] as string);
|
||||||
|
if (query.where?.uid) {
|
||||||
|
this.httpBadRequest(response, "You can't filter by uid");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//call service to get prisma entity
|
||||||
|
const documentEntities = await this.documentsNotaryService.get(query);
|
||||||
|
|
||||||
|
//Hydrate ressource with prisma entity
|
||||||
|
const documents = DocumentNotary.hydrateArray<DocumentNotary>(documentEntities, { strategy: "excludeAll" });
|
||||||
|
|
||||||
|
//success
|
||||||
|
this.httpSuccess(response, documents);
|
||||||
|
} catch (error) {
|
||||||
|
this.httpInternalError(response, error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,9 +1,9 @@
|
|||||||
import { Response, Request } from "express";
|
import { Response, Request } from "express";
|
||||||
import { Controller, Get, Post } from "@ControllerPattern/index";
|
import { Controller, Delete, 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 { Prisma } from "@prisma/client";
|
import { DocumentsNotary, Prisma } from "@prisma/client";
|
||||||
import { 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 OfficeFoldersService from "@Services/notary/OfficeFoldersService/OfficeFoldersService";
|
import OfficeFoldersService from "@Services/notary/OfficeFoldersService/OfficeFoldersService";
|
||||||
@ -41,10 +41,6 @@ export default class DocumentsNotaryController extends ApiController {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const officeId: string = req.body.user.office_Id;
|
|
||||||
const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId };
|
|
||||||
if (!query.where) query.where = { folder: { office: officeWhereInput } };
|
|
||||||
query.where.folder!.office = officeWhereInput;
|
|
||||||
|
|
||||||
//call service to get prisma entity
|
//call service to get prisma entity
|
||||||
const documentEntities = await this.documentsNotaryService.get(query);
|
const documentEntities = await this.documentsNotaryService.get(query);
|
||||||
@ -96,112 +92,52 @@ 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);
|
if(!fileEntityCreated) {
|
||||||
|
this.httpBadRequest(response, "File could not be created");
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
|
const documentNotary = await this.documentsNotaryService.getByUid(documentNotaryEntityCreated.uid);
|
||||||
|
|
||||||
|
const document = DocumentNotary.hydrate<DocumentNotary>(documentNotary!);
|
||||||
// //init Document resource with request body values
|
//success
|
||||||
// const documentNotaryEntity = DocumentNotary.hydrate<DocumentNotary>(req.body);
|
this.httpCreated(response, document);
|
||||||
// console.log(documentNotaryEntity);
|
|
||||||
|
|
||||||
// const folder = await this.officeFoldersService.getByUid(documentNotaryEntity.folder?.uid!, {
|
|
||||||
// folder_anchor: true,
|
|
||||||
// });
|
|
||||||
// if (!folder) {
|
|
||||||
// this.httpBadRequest(response, "Folder not found");
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// const folderRessource = OfficeFolder.hydrate<OfficeFolder>(folder);
|
|
||||||
// if (folderRessource.folder_anchor) {
|
|
||||||
// this.httpBadRequest(response, "Cannot add document on an anchored or anchoring folder");
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// //validate document
|
|
||||||
// await validateOrReject(documentNotaryEntity, { groups: ["createDocument"], forbidUnknownValues: false });
|
|
||||||
|
|
||||||
// //call service to get prisma entity
|
|
||||||
// const documentNotaryEntityCreated = await this.documentsNotaryService.create(documentNotaryEntity);
|
|
||||||
|
|
||||||
// //Hydrate ressource with prisma entity
|
|
||||||
// const documentNotary = DocumentNotary.hydrate<DocumentNotary>(documentNotaryEntityCreated, {
|
|
||||||
// strategy: "excludeAll",
|
|
||||||
// });
|
|
||||||
|
|
||||||
// //success
|
|
||||||
// this.httpCreated(response, documentNotary);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.httpInternalError(response, error);
|
this.httpInternalError(response, error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * @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])
|
||||||
// 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 documentNotaryFound = await this.documentsNotaryService.getByUid(uid);
|
||||||
|
|
||||||
// if (!documentFound) {
|
if (!documentNotaryFound) {
|
||||||
// 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 documentNotaryEntity: 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 documentNotary = DocumentNotary.hydrate<DocumentNotary>(documentNotaryEntity, { strategy: "excludeAll" });
|
||||||
|
|
||||||
// //success
|
//success
|
||||||
// this.httpSuccess(response, document);
|
this.httpSuccess(response, documentNotary);
|
||||||
// } catch (error) {
|
} catch (error) {
|
||||||
// this.httpInternalError(response, error);
|
this.httpInternalError(response, error);
|
||||||
// return;
|
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);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// const documentEntity = await this.documentsNotaryService.getByUid(uid, query);
|
|
||||||
|
|
||||||
// if (!documentEntity) {
|
|
||||||
// this.httpNotFoundRequest(response, "document not found");
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// //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;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user