108 lines
3.1 KiB
TypeScript
108 lines
3.1 KiB
TypeScript
import { Response, Request } from "express";
|
|
import { Controller, Get } from "@ControllerPattern/index";
|
|
import ApiController from "@Common/system/controller-pattern/ApiController";
|
|
import { Service } from "typedi";
|
|
import { Prisma } from "@prisma/client";
|
|
import { DocumentReminder } from "le-coffre-resources/dist/Notary";
|
|
|
|
import authHandler from "@App/middlewares/AuthHandler";
|
|
|
|
import DocumentsReminderService from "@Services/notary/DocumentsReminder/DocumentsReminder";
|
|
// import NotificationBuilder from "@Common/notifications/NotificationBuilder";
|
|
|
|
@Controller()
|
|
@Service()
|
|
export default class DocumentsReminderController extends ApiController {
|
|
constructor(
|
|
private documentsReminderService: DocumentsReminderService,
|
|
) {
|
|
super();
|
|
}
|
|
|
|
/**
|
|
* @description Get all documents
|
|
* @returns IDocument[] list of documents
|
|
*/
|
|
@Get("/api/v1/notary/document_reminders", [authHandler])
|
|
protected async get(req: Request, response: Response) {
|
|
try {
|
|
//get query
|
|
let query: Prisma.DocumentsReminderFindManyArgs = {};
|
|
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 documentReminderEntities = await this.documentsReminderService.get(query);
|
|
|
|
//Hydrate ressource with prisma entity
|
|
const documentReminders = DocumentReminder.hydrateArray<DocumentReminder>(documentReminderEntities, { strategy: "excludeAll" });
|
|
|
|
//success
|
|
this.httpSuccess(response, documentReminders);
|
|
} catch (error) {
|
|
this.httpInternalError(response, error);
|
|
return;
|
|
}
|
|
}
|
|
|
|
@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
|
|
// */
|
|
// @Get("/api/v1/notary/document_reminders/: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;
|
|
// }
|
|
// }
|
|
}
|