add controllers and services by namespace
This commit is contained in:
parent
eb7f981606
commit
70d0fb6e71
@ -49,7 +49,7 @@
|
||||
"cors": "^2.8.5",
|
||||
"express": "^4.18.2",
|
||||
"jsonwebtoken": "^9.0.0",
|
||||
"le-coffre-resources": "git@github.com:smart-chain-fr/leCoffre-resources.git#v2.54",
|
||||
"le-coffre-resources": "git@github.com:smart-chain-fr/leCoffre-resources.git#v2.55",
|
||||
"module-alias": "^2.2.2",
|
||||
"multer": "^1.4.5-lts.1",
|
||||
"next": "^13.1.5",
|
||||
|
146
src/app/api/admin/CustomersController.ts
Normal file
146
src/app/api/admin/CustomersController.ts
Normal file
@ -0,0 +1,146 @@
|
||||
import { Response, Request } from "express";
|
||||
import { Controller, Get, Post, Put } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import CustomersService from "@Services/admin/CustomersService/CustomersService";
|
||||
import { Service } from "typedi";
|
||||
import { Customer } from "le-coffre-resources/dist/Admin";
|
||||
import { Customers } from "@prisma/client";
|
||||
import { validateOrReject } from "class-validator";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
export default class CustomersController extends ApiController {
|
||||
constructor(private customersService: CustomersService) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get all customers
|
||||
*/
|
||||
@Get("/api/v1/admin/customers", [authHandler, ruleHandler])
|
||||
protected async get(req: Request, response: Response) {
|
||||
try {
|
||||
//get query
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
|
||||
//call service to get prisma entity
|
||||
const customersEntities = await this.customersService.get(query);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const customers = Customer.hydrateArray<Customer>(customersEntities, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, customers);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Create a new customer
|
||||
*/
|
||||
@Post("/api/v1/admin/customers", [authHandler, ruleHandler])
|
||||
protected async post(req: Request, response: Response) {
|
||||
try {
|
||||
//init IUser resource with request body values
|
||||
const customerEntity = Customer.hydrate<Customer>(req.body);
|
||||
//validate user
|
||||
await validateOrReject(customerEntity, { groups: ["createCustomer"], forbidUnknownValues: false });
|
||||
|
||||
//call service to get prisma entity
|
||||
const customerEntityCreated = await this.customersService.create(customerEntity);
|
||||
//Hydrate ressource with prisma entity
|
||||
const customer = Customer.hydrate<Customer>(customerEntityCreated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpCreated(response, customer);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Modify a specific customer by uid
|
||||
*/
|
||||
@Put("/api/v1/admin/customers/:uid", [authHandler, ruleHandler])
|
||||
protected async put(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
const userFound = await this.customersService.getByUid(uid);
|
||||
|
||||
if (!userFound) {
|
||||
this.httpNotFoundRequest(response, "user not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//init IUser resource with request body values
|
||||
const customerEntity = Customer.hydrate<Customer>(req.body);
|
||||
|
||||
//validate user
|
||||
await validateOrReject(customerEntity, { groups: ["updateCustomer"], forbidUnknownValues: false });
|
||||
|
||||
//call service to get prisma entity
|
||||
const customerEntityUpdated = await this.customersService.update(uid, customerEntity);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const customer = Customer.hydrate<Customer>(customerEntityUpdated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, customer);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get a specific customer by uid
|
||||
*/
|
||||
@Get("/api/v1/admin/customers/:uid", [authHandler, ruleHandler])
|
||||
protected async getOneByUid(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
let customerEntity: Customers | null;
|
||||
//get query
|
||||
if (req.query["q"]) {
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
customerEntity = await this.customersService.getByUid(uid, query);
|
||||
} else {
|
||||
//call service to get prisma entity
|
||||
customerEntity = await this.customersService.getByUid(uid);
|
||||
}
|
||||
|
||||
if (!customerEntity) {
|
||||
this.httpNotFoundRequest(response, "customer not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const customer = Customer.hydrate<Customer>(customerEntity, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, customer);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
156
src/app/api/admin/DeedTypesController.ts
Normal file
156
src/app/api/admin/DeedTypesController.ts
Normal file
@ -0,0 +1,156 @@
|
||||
import { Response, Request } from "express";
|
||||
import { Controller, Get, Post, Put } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import { Service } from "typedi";
|
||||
import DeedTypesService from "@Services/admin/DeedTypesService/DeedTypesService";
|
||||
import { DeedTypes, Prisma } from "@prisma/client";
|
||||
import { DeedType } from "le-coffre-resources/dist/Admin";
|
||||
import { validateOrReject } from "class-validator";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
import deedTypeHandler from "@App/middlewares/OfficeMembershipHandlers/DeedTypeHandler";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
export default class DeedTypesController extends ApiController {
|
||||
constructor(private deedTypesService: DeedTypesService) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get all deedtypes
|
||||
* @returns Deedtype[] list of deedtypes
|
||||
*/
|
||||
@Get("/api/v1/admin/deed-types", [authHandler, ruleHandler])
|
||||
protected async get(req: Request, response: Response) {
|
||||
try {
|
||||
//get query
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
const officeId: string = req.body.user.office_Id;
|
||||
const officeWhereInput: Prisma.DeedTypesWhereInput = { office: { uid: officeId } };
|
||||
query.where = officeWhereInput;
|
||||
|
||||
//call service to get prisma entity
|
||||
const deedTypeEntities: DeedTypes[] = await this.deedTypesService.get(query);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const DeedTypes = DeedType.hydrateArray<DeedType>(deedTypeEntities, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, DeedTypes);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Create a new deedtype
|
||||
* @returns Deedtype created
|
||||
*/
|
||||
@Post("/api/v1/admin/deed-types", [authHandler, ruleHandler, deedTypeHandler])
|
||||
protected async post(req: Request, response: Response) {
|
||||
try {
|
||||
//init DeedType resource with request body values
|
||||
const deedTypeEntity = DeedType.hydrate<DeedType>(req.body);
|
||||
|
||||
//validate deed type
|
||||
await validateOrReject(deedTypeEntity, { groups: ["createDeedType"], forbidUnknownValues: false });
|
||||
|
||||
//call service to get prisma entity
|
||||
const deedTypeEntityCreated = await this.deedTypesService.create(deedTypeEntity);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const deedType = DeedType.hydrate<DeedType>(deedTypeEntityCreated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpCreated(response, deedType);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Modify a specific deedtype by uid
|
||||
* @returns Deedtype modified
|
||||
*/
|
||||
@Put("/api/v1/admin/deed-types/:uid", [authHandler, ruleHandler, deedTypeHandler])
|
||||
protected async put(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
const deedTypeFound = await this.deedTypesService.getByUid(uid);
|
||||
|
||||
if (!deedTypeFound) {
|
||||
this.httpNotFoundRequest(response, "deed type not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//init DeedType resource with request body values
|
||||
const deedTypeEntity = DeedType.hydrate<DeedType>(req.body);
|
||||
|
||||
//validate deed type
|
||||
await validateOrReject(deedTypeEntity, { groups: ["updateDeedType"] });
|
||||
|
||||
//call service to get prisma entity
|
||||
const deedTypeEntityUpdated = await this.deedTypesService.update(uid, deedTypeEntity);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const deedType = DeedType.hydrate<DeedType>(deedTypeEntityUpdated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, deedType);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get a specific deedtype by uid
|
||||
* @returns IDeedtype
|
||||
*/
|
||||
@Get("/api/v1/admin/deed-types/:uid", [authHandler, ruleHandler, deedTypeHandler])
|
||||
protected async getOneByUid(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
let deedTypeEntity: DeedTypes | null;
|
||||
//get query
|
||||
if (req.query["q"]) {
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
deedTypeEntity = await this.deedTypesService.getByUid(uid, query);
|
||||
} else {
|
||||
//call service to get prisma entity
|
||||
deedTypeEntity = await this.deedTypesService.getByUid(uid);
|
||||
}
|
||||
|
||||
if (!deedTypeEntity) {
|
||||
this.httpNotFoundRequest(response, "deed type not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const deedType = DeedType.hydrate<DeedType>(deedTypeEntity, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, deedType);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
126
src/app/api/admin/DeedsController.ts
Normal file
126
src/app/api/admin/DeedsController.ts
Normal file
@ -0,0 +1,126 @@
|
||||
import { Response, Request } from "express";
|
||||
import { Controller, Get, Put } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import DeedsService from "@Services/admin/DeedsService/DeedsService";
|
||||
import { Service } from "typedi";
|
||||
import { Deeds, Prisma } from "@prisma/client";
|
||||
import { Deed } from "le-coffre-resources/dist/Admin";
|
||||
import { validateOrReject } from "class-validator";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
import deedHandler from "@App/middlewares/OfficeMembershipHandlers/DeedHandler";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
export default class DeedsController extends ApiController {
|
||||
constructor(private deedsService: DeedsService) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get all deeds
|
||||
* @returns Deed[] list of deeds
|
||||
*/
|
||||
@Get("/api/v1/admin/deeds", [authHandler, ruleHandler])
|
||||
protected async get(req: Request, response: Response) {
|
||||
try {
|
||||
//get query
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
const officeId: string = req.body.user.office_Id;
|
||||
const officeWhereInput: Prisma.DeedsWhereInput = { deed_type: { office: { uid: officeId } } };
|
||||
query.where = officeWhereInput;
|
||||
|
||||
//call service to get prisma entity
|
||||
const deedEntities: Deeds[] = await this.deedsService.get(query);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const deeds = Deed.hydrateArray<Deed>(deedEntities, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, deeds);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get a specific deed by uid
|
||||
* @returns Deed
|
||||
*/
|
||||
@Get("/api/v1/admin/deeds/:uid", [authHandler, ruleHandler, deedHandler])
|
||||
protected async getOneByUid(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
let deedEntity: Deeds | null;
|
||||
//get query
|
||||
if (req.query["q"]) {
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
deedEntity = await this.deedsService.getByUid(uid, query);
|
||||
} else {
|
||||
//call service to get prisma entity
|
||||
deedEntity = await this.deedsService.getByUid(uid);
|
||||
}
|
||||
|
||||
if (!deedEntity) {
|
||||
this.httpNotFoundRequest(response, "deed not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const deed = Deed.hydrate<Deed>(deedEntity, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, deed);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Modify a specific deed by uid
|
||||
*/
|
||||
@Put("/api/v1/admin/deeds/:uid", [authHandler, ruleHandler, deedHandler])
|
||||
protected async put(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
const deedFound = await this.deedsService.getByUid(uid);
|
||||
|
||||
if (!deedFound) {
|
||||
this.httpNotFoundRequest(response, "deed not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//init OfficeFolder resource with request body values
|
||||
const deedEntity = Deed.hydrate<Deed>(req.body);
|
||||
|
||||
//validate folder
|
||||
await validateOrReject(deedEntity, { groups: ["updateDeed"], forbidUnknownValues: false });
|
||||
|
||||
//call service to get prisma entity
|
||||
const deedEntityUpdated = await this.deedsService.update(uid, deedEntity);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const deed = Deed.hydrate<Deed>(deedEntityUpdated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, deed);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
145
src/app/api/admin/DocumentTypesController.ts
Normal file
145
src/app/api/admin/DocumentTypesController.ts
Normal file
@ -0,0 +1,145 @@
|
||||
import { Response, Request } from "express";
|
||||
import { Controller, Get, Post, Put } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import { Service } from "typedi";
|
||||
import DocumentTypesService from "@Services/admin/DocumentTypesService/DocumentTypesService";
|
||||
import { DocumentTypes, Prisma } from "@prisma/client";
|
||||
import ObjectHydrate from "@Common/helpers/ObjectHydrate";
|
||||
import { DocumentType } from "le-coffre-resources/dist/Admin";
|
||||
import { validateOrReject } from "class-validator";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
import documentTypeHandler from "@App/middlewares/OfficeMembershipHandlers/DocumentTypeHandler";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
export default class DocumentTypesController extends ApiController {
|
||||
constructor(private documentTypesService: DocumentTypesService) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get all document-types
|
||||
*/
|
||||
@Get("/api/v1/admin/document-types", [authHandler, ruleHandler])
|
||||
protected async get(req: Request, response: Response) {
|
||||
try {
|
||||
//get query
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
const officeId: string = req.body.user.office_Id;
|
||||
const officeWhereInput: Prisma.DocumentTypesWhereInput = { office: { uid: officeId } };
|
||||
query.where = officeWhereInput;
|
||||
|
||||
//call service to get prisma entity
|
||||
const documentTypeEntities: DocumentTypes[] = await this.documentTypesService.get(query);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const documentTypes = DocumentType.hydrateArray<DocumentType>(documentTypeEntities, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, documentTypes);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Create a new documentType
|
||||
*/
|
||||
@Post("/api/v1/admin/document-types", [authHandler, ruleHandler, documentTypeHandler])
|
||||
protected async post(req: Request, response: Response) {
|
||||
try {
|
||||
//init DocumentType resource with request body values
|
||||
const documentTypeEntity = DocumentType.hydrate<DocumentType>(req.body);
|
||||
//validate user
|
||||
await validateOrReject(documentTypeEntity, { groups: ["createDocumentType"], forbidUnknownValues: false });
|
||||
//call service to get prisma entity
|
||||
const documentTypeEntityCreated = await this.documentTypesService.create(documentTypeEntity);
|
||||
//Hydrate ressource with prisma entity
|
||||
const userEntityCreated = DocumentType.hydrate<DocumentType>(documentTypeEntityCreated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
//success
|
||||
this.httpCreated(response, userEntityCreated);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Modify a specific documentType by uid
|
||||
*/
|
||||
@Put("/api/v1/admin/document-types/:uid", [authHandler, ruleHandler, documentTypeHandler])
|
||||
protected async put(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
const documentTypeFound = await this.documentTypesService.getByUid(uid);
|
||||
|
||||
if (!documentTypeFound) {
|
||||
this.httpNotFoundRequest(response, "document type not found");
|
||||
return;
|
||||
}
|
||||
//init DocumentType resource with request body values
|
||||
const documentTypeEntity = DocumentType.hydrate<DocumentType>(req.body);
|
||||
|
||||
//validate user
|
||||
await validateOrReject(documentTypeEntity, { groups: ["updateDocumentType"] });
|
||||
|
||||
//call service to get prisma entity
|
||||
const documentTypeEntityUpdated = await this.documentTypesService.update(uid, documentTypeEntity);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const documentType = DocumentType.hydrate<DocumentType>(documentTypeEntityUpdated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, documentType);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get a specific documentType by uid
|
||||
*/
|
||||
@Get("/api/v1/admin/document-types/:uid", [authHandler, ruleHandler, documentTypeHandler])
|
||||
protected async getOneByUid(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
let documentTypeEntity: DocumentTypes | null;
|
||||
//get query
|
||||
if (req.query["q"]) {
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
documentTypeEntity = await this.documentTypesService.getByUid(uid, query);
|
||||
} else {
|
||||
//call service to get prisma entity
|
||||
documentTypeEntity = await this.documentTypesService.getByUid(uid);
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const user = ObjectHydrate.hydrate<DocumentType>(new DocumentType(), documentTypeEntity!, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, user);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
185
src/app/api/admin/DocumentsController.ts
Normal file
185
src/app/api/admin/DocumentsController.ts
Normal file
@ -0,0 +1,185 @@
|
||||
import { Response, Request } from "express";
|
||||
import { Controller, Delete, Get, Post, Put } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import { Service } from "typedi";
|
||||
import DocumentsService from "@Services/admin/DocumentsService/DocumentsService";
|
||||
import { Documents, Prisma } from "@prisma/client";
|
||||
import { Document } from "le-coffre-resources/dist/Admin";
|
||||
import { validateOrReject } from "class-validator";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
import documentHandler from "@App/middlewares/OfficeMembershipHandlers/DocumentHandler";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
export default class DocumentsController extends ApiController {
|
||||
constructor(private documentsService: DocumentsService) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get all documents
|
||||
* @returns IDocument[] list of documents
|
||||
*/
|
||||
@Get("/api/v1/admin/documents", [authHandler, ruleHandler])
|
||||
protected async get(req: Request, response: Response) {
|
||||
try {
|
||||
//get query
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
const officeId: string = req.body.user.office_Id;
|
||||
const officeWhereInput: Prisma.DocumentsWhereInput = { document_type: { office: { uid: officeId } } };
|
||||
query.where = officeWhereInput;
|
||||
|
||||
//call service to get prisma entity
|
||||
const documentEntities = await this.documentsService.get(query);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const documents = Document.hydrateArray<Document>(documentEntities, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, documents);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Create a new document
|
||||
* @returns IDocument created
|
||||
*/
|
||||
@Post("/api/v1/admin/documents", [authHandler, ruleHandler, documentHandler])
|
||||
protected async post(req: Request, response: Response) {
|
||||
try {
|
||||
//init Document resource with request body values
|
||||
const documentEntity = Document.hydrate<Document>(req.body);
|
||||
|
||||
//validate document
|
||||
await validateOrReject(documentEntity, { groups: ["createDocument"], forbidUnknownValues: false });
|
||||
|
||||
//call service to get prisma entity
|
||||
const documentEntityCreated = await this.documentsService.create(documentEntity);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const document = Document.hydrate<Document>(documentEntityCreated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpCreated(response, document);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Update a specific document
|
||||
*/
|
||||
@Put("/api/v1/admin/documents/:uid", [authHandler, ruleHandler, documentHandler])
|
||||
protected async update(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
const documentFound = await this.documentsService.getByUid(uid);
|
||||
|
||||
if (!documentFound) {
|
||||
this.httpNotFoundRequest(response, "document not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//init Document resource with request body values
|
||||
const documentEntity = Document.hydrate<Document>(req.body);
|
||||
|
||||
//validate document
|
||||
await validateOrReject(documentEntity, { groups: ["updateDocument"] });
|
||||
|
||||
//call service to get prisma entity
|
||||
const documentEntityUpdated: Documents = await this.documentsService.update(uid, documentEntity, req.body.refused_reason);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const document = Document.hydrate<Document>(documentEntityUpdated, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, document);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Delete a specific document
|
||||
*/
|
||||
@Delete("/api/v1/admin/documents/: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.documentsService.getByUid(uid);
|
||||
|
||||
if (!documentFound) {
|
||||
this.httpNotFoundRequest(response, "document not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//call service to get prisma entity
|
||||
const documentEntity: Documents = await this.documentsService.delete(uid);
|
||||
|
||||
//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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get a specific document by uid
|
||||
*/
|
||||
@Get("/api/v1/admin/documents/: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;
|
||||
}
|
||||
|
||||
let documentEntity: Documents | null;
|
||||
//get query
|
||||
if (req.query["q"]) {
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
documentEntity = await this.documentsService.getByUid(uid, query);
|
||||
} else {
|
||||
//call service to get prisma entity
|
||||
documentEntity = await this.documentsService.getByUid(uid);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
140
src/app/api/admin/FilesController.ts
Normal file
140
src/app/api/admin/FilesController.ts
Normal file
@ -0,0 +1,140 @@
|
||||
import { Response, Request } from "express";
|
||||
import { Controller, Delete, Get } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import { Service } from "typedi";
|
||||
import FilesService from "@Services/common/FilesService/FilesService";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import { File } from "le-coffre-resources/dist/Admin";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
import fileHandler from "@App/middlewares/OfficeMembershipHandlers/FileHandler";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
export default class FilesController extends ApiController {
|
||||
constructor(private filesService: FilesService) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get all Files
|
||||
* @returns File[] list of Files
|
||||
*/
|
||||
@Get("/api/v1/admin/files", [authHandler, ruleHandler])
|
||||
protected async get(req: Request, response: Response) {
|
||||
try {
|
||||
//get query
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
const officeId: string = req.body.user.office_Id;
|
||||
const officeWhereInput: Prisma.FilesWhereInput = { document: { folder: { office: { uid: officeId } } } };
|
||||
query.where = officeWhereInput;
|
||||
//call service to get prisma entity
|
||||
const fileEntities = await this.filesService.get(query);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const files = File.hydrateArray<File>(fileEntities, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, files);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get a specific File by uid
|
||||
*/
|
||||
@Get("/api/v1/admin/files/download/:uid", [authHandler, ruleHandler, fileHandler])
|
||||
protected async download(req: Request, response: Response) {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "uid not found");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const fileInfo = await this.filesService.download(uid);
|
||||
|
||||
if (!fileInfo) {
|
||||
this.httpNotFoundRequest(response, "file not found");
|
||||
return;
|
||||
}
|
||||
|
||||
response.setHeader("Content-Type", fileInfo.file.mimetype);
|
||||
response.setHeader("Content-Disposition", `inline; filename=${encodeURIComponent(fileInfo.file.file_name)}`);
|
||||
|
||||
this.httpSuccess(response, fileInfo.buffer);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Delete a specific File
|
||||
*/
|
||||
@Delete("/api/v1/admin/files/:uid", [authHandler, ruleHandler, fileHandler])
|
||||
protected async delete(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
const fileFound = await this.filesService.getByUid(uid);
|
||||
|
||||
if (!fileFound) {
|
||||
this.httpNotFoundRequest(response, "file not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//call service to get prisma entity
|
||||
const fileEntity = await this.filesService.deleteKeyAndArchive(uid);
|
||||
|
||||
if (!fileEntity) {
|
||||
this.httpNotFoundRequest(response, "file not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const file = File.hydrate<File>(fileEntity, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, file);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get a specific File by uid
|
||||
*/
|
||||
@Get("/api/v1/admin/files/:uid", [authHandler, ruleHandler, fileHandler])
|
||||
protected async getOneByUid(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
const fileEntity = await this.filesService.getByUid(uid);
|
||||
|
||||
if (!fileEntity) {
|
||||
this.httpNotFoundRequest(response, "file not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const file = File.hydrate<File>(fileEntity, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, file);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
183
src/app/api/admin/OfficeFoldersController.ts
Normal file
183
src/app/api/admin/OfficeFoldersController.ts
Normal file
@ -0,0 +1,183 @@
|
||||
import { Response, Request } from "express";
|
||||
import { Controller, Delete, Get, Post, Put } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import OfficeFoldersService from "@Services/admin/OfficeFoldersService/OfficeFoldersService";
|
||||
import { Service } from "typedi";
|
||||
import { OfficeFolders, Prisma } from "@prisma/client";
|
||||
import { OfficeFolder } from "le-coffre-resources/dist/Admin";
|
||||
import { validateOrReject } from "class-validator";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
import folderHandler from "@App/middlewares/OfficeMembershipHandlers/FolderHandler";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
export default class OfficeFoldersController extends ApiController {
|
||||
constructor(private officeFoldersService: OfficeFoldersService) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get all folders
|
||||
*/
|
||||
@Get("/api/v1/admin/folders", [authHandler, ruleHandler])
|
||||
protected async get(req: Request, response: Response) {
|
||||
try {
|
||||
//get query
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
const officeId: string = req.body.user.office_Id;
|
||||
const officeWhereInput: Prisma.OfficeFoldersWhereInput = { office: { uid: officeId } };
|
||||
query.where = officeWhereInput;
|
||||
//call service to get prisma entity
|
||||
const officeFolderEntities: OfficeFolders[] = await this.officeFoldersService.get(query);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const officeFolders = OfficeFolder.hydrateArray<OfficeFolder>(officeFolderEntities, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
//success
|
||||
this.httpSuccess(response, officeFolders);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Create a new folder
|
||||
*/
|
||||
@Post("/api/v1/admin/folders", [authHandler, ruleHandler, folderHandler])
|
||||
protected async post(req: Request, response: Response) {
|
||||
try {
|
||||
//init OfficeFolder resource with request body values
|
||||
const officeFolderRessource = OfficeFolder.hydrate<OfficeFolder>(req.body);
|
||||
await officeFolderRessource.validateOrReject?.({ groups: ["createFolder"], forbidUnknownValues: false });
|
||||
|
||||
//call service to get prisma entity
|
||||
const officeFolderEntity = await this.officeFoldersService.create(officeFolderRessource);
|
||||
//Hydrate ressource with prisma entity
|
||||
const officeFolders = OfficeFolder.hydrate<OfficeFolder>(officeFolderEntity, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
//success
|
||||
this.httpCreated(response, officeFolders);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Modify a specific folder by uid
|
||||
*/
|
||||
@Put("/api/v1/admin/folders/:uid", [authHandler, ruleHandler, folderHandler])
|
||||
protected async put(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
const officeFolderFound = await this.officeFoldersService.getByUid(uid);
|
||||
|
||||
if (!officeFolderFound) {
|
||||
this.httpNotFoundRequest(response, "office folder not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//init OfficeFolder resource with request body values
|
||||
const officeFolderEntity = OfficeFolder.hydrate<OfficeFolder>(req.body);
|
||||
|
||||
//validate folder
|
||||
await validateOrReject(officeFolderEntity, { groups: ["updateFolder"], forbidUnknownValues: false });
|
||||
|
||||
//call service to get prisma entity
|
||||
const officeFolderEntityUpdated = await this.officeFoldersService.update(uid, officeFolderEntity);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const officeFolders = OfficeFolder.hydrate<OfficeFolder>(officeFolderEntityUpdated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, officeFolders);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get a specific folder by uid
|
||||
* @returns IFolder
|
||||
*/
|
||||
@Get("/api/v1/admin/folders/:uid", [authHandler, ruleHandler, folderHandler])
|
||||
protected async getOneByUid(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
let officeFolderEntity: OfficeFolders | null;
|
||||
//get query
|
||||
if (req.query["q"]) {
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
officeFolderEntity = await this.officeFoldersService.getByUid(uid, query);
|
||||
} else {
|
||||
//call service to get prisma entity
|
||||
officeFolderEntity = await this.officeFoldersService.getByUid(uid);
|
||||
}
|
||||
|
||||
if (!officeFolderEntity) {
|
||||
this.httpNotFoundRequest(response, "folder not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const officeFolder = OfficeFolder.hydrate<OfficeFolder>(officeFolderEntity, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, officeFolder);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
this.httpSuccess(response, await this.officeFoldersService.getByUid("uid"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Delete a specific folder
|
||||
*/
|
||||
@Delete("/api/v1/admin/folders/:uid", [authHandler, ruleHandler, folderHandler])
|
||||
protected async delete(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
const officeFolderFound = await this.officeFoldersService.getByUid(uid);
|
||||
|
||||
if (!officeFolderFound) {
|
||||
this.httpNotFoundRequest(response, "office folder not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//call service to get prisma entity
|
||||
const officeFoldertEntity: OfficeFolders = await this.officeFoldersService.delete(uid);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const officeFolder = OfficeFolder.hydrate<OfficeFolder>(officeFoldertEntity, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, officeFolder);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
151
src/app/api/admin/OfficeRolesController.ts
Normal file
151
src/app/api/admin/OfficeRolesController.ts
Normal file
@ -0,0 +1,151 @@
|
||||
import { Response, Request } from "express";
|
||||
import { Controller, Get, Post, Put } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import OfficeRolesService from "@Services/admin/OfficeRolesService/OfficeRolesService";
|
||||
import { Service } from "typedi";
|
||||
import { validateOrReject } from "class-validator";
|
||||
import { OfficeRole } from "le-coffre-resources/dist/Admin";
|
||||
import { OfficeRoles, Prisma } from "@prisma/client";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
import officeRoleHandler from "@App/middlewares/OfficeMembershipHandlers/OfficeRoleHandler";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
export default class OfficeRolesController extends ApiController {
|
||||
constructor(private officeRolesService: OfficeRolesService) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get all officeRoles
|
||||
*/
|
||||
@Get("/api/v1/admin/officeRoles", [authHandler, ruleHandler])
|
||||
protected async get(req: Request, response: Response) {
|
||||
try {
|
||||
//get query
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
const officeId: string = req.body.user.office_Id;
|
||||
const officeWhereInput: Prisma.OfficeRolesWhereInput = { office: { uid: officeId } };
|
||||
query.where = officeWhereInput;
|
||||
|
||||
//call service to get prisma entity
|
||||
const officeRolesEntities = await this.officeRolesService.get(query);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const officeRoles = OfficeRole.hydrateArray<OfficeRole>(officeRolesEntities, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, officeRoles);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Create a new officeRole
|
||||
*/
|
||||
@Post("/api/v1/admin/office-roles", [authHandler, ruleHandler, officeRoleHandler])
|
||||
protected async getAddresses(req: Request, response: Response) {
|
||||
try {
|
||||
//init IOfficeRole resource with request body values
|
||||
const officeRoleEntity = OfficeRole.hydrate<OfficeRole>(req.body);
|
||||
|
||||
//validate officeRole
|
||||
await validateOrReject(officeRoleEntity, { groups: ["createOfficeRole"] });
|
||||
|
||||
//call service to get prisma entity
|
||||
const officeRoleEntityCreated = await this.officeRolesService.create(officeRoleEntity);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const officeRole = OfficeRole.hydrate<OfficeRole>(officeRoleEntityCreated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpCreated(response, officeRole);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Modify a specific officeRole by uid
|
||||
*/
|
||||
@Put("/api/v1/admin/office-roles/:uid", [authHandler, ruleHandler, officeRoleHandler])
|
||||
protected async put(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
const officeRoleFound = await this.officeRolesService.getByUid(uid);
|
||||
|
||||
if (!officeRoleFound) {
|
||||
this.httpNotFoundRequest(response, "officeRole not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//init IOfficeRole resource with request body values
|
||||
const officeRoleEntity = OfficeRole.hydrate<OfficeRole>(req.body);
|
||||
|
||||
//validate officeRole
|
||||
await validateOrReject(officeRoleEntity, { groups: ["updateOfficeRole"] });
|
||||
|
||||
//call service to get prisma entity
|
||||
const officeRoleEntityUpdated = await this.officeRolesService.update(officeRoleEntity);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const officeRole = OfficeRole.hydrate<OfficeRole>(officeRoleEntityUpdated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, officeRole);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get a specific officeRole by uid
|
||||
*/
|
||||
@Get("/api/v1/admin/office-roles/:uid", [authHandler, ruleHandler, officeRoleHandler])
|
||||
protected async getOneByUid(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
let officeRoleEntity: OfficeRoles | null;
|
||||
//get query
|
||||
if (req.query["q"]) {
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
officeRoleEntity = await this.officeRolesService.getByUid(uid, query);
|
||||
} else {
|
||||
//call service to get prisma entity
|
||||
officeRoleEntity = await this.officeRolesService.getByUid(uid);
|
||||
}
|
||||
|
||||
if (!officeRoleEntity) {
|
||||
this.httpNotFoundRequest(response, "officeRole not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const officeRole = OfficeRole.hydrate<OfficeRole>(officeRoleEntity, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, officeRole);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
72
src/app/api/admin/OfficesController.ts
Normal file
72
src/app/api/admin/OfficesController.ts
Normal file
@ -0,0 +1,72 @@
|
||||
import { Response, Request } from "express";
|
||||
import { Controller, Get } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import OfficesService from "@Services/admin/OfficesService/OfficesService";
|
||||
import { Service } from "typedi";
|
||||
import { Offices } from "@prisma/client";
|
||||
import { Office as OfficeResource } from "le-coffre-resources/dist/Admin";
|
||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
export default class OfficesController extends ApiController {
|
||||
constructor(private officesService: OfficesService) {
|
||||
super();
|
||||
}
|
||||
/**
|
||||
* @description Get all offices
|
||||
*/
|
||||
@Get("/api/v1/admin/offices", [authHandler, ruleHandler])
|
||||
protected async get(req: Request, response: Response) {
|
||||
try {
|
||||
//get query
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
//call service to get prisma entity
|
||||
const officesEntities: Offices[] = await this.officesService.get(query);
|
||||
//Hydrate ressource with prisma entity
|
||||
const offices = OfficeResource.hydrateArray<OfficeResource>(officesEntities, { strategy: "excludeAll" });
|
||||
//success
|
||||
this.httpSuccess(response, offices);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get a specific office by uid
|
||||
*/
|
||||
@Get("/api/v1/admin/offices/:uid", [authHandler, ruleHandler])
|
||||
protected async getOneByUid(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
let officeEntity: Offices | null;
|
||||
//get query
|
||||
if (req.query["q"]) {
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
officeEntity = await this.officesService.getByUid(uid, query);
|
||||
} else {
|
||||
//call service to get prisma entity
|
||||
officeEntity = await this.officesService.getByUid(uid);
|
||||
}
|
||||
|
||||
if (!officeEntity) {
|
||||
this.httpNotFoundRequest(response, "office not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const office = OfficeResource.hydrate<OfficeResource>(officeEntity, { strategy: "excludeAll" });
|
||||
//success
|
||||
this.httpSuccess(response, office);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
77
src/app/api/admin/RolesController.ts
Normal file
77
src/app/api/admin/RolesController.ts
Normal file
@ -0,0 +1,77 @@
|
||||
import { Response, Request } from "express";
|
||||
import { Controller, Get } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import RolesService from "@Services/admin/RolesService/RolesService";
|
||||
import { Service } from "typedi";
|
||||
import { Role } from "le-coffre-resources/dist/Admin";
|
||||
import { Roles } from "@prisma/client";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
export default class RolesController extends ApiController {
|
||||
constructor(private rolesService: RolesService) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get all roles
|
||||
*/
|
||||
@Get("/api/v1/admin/roles", [authHandler, ruleHandler])
|
||||
protected async get(req: Request, response: Response) {
|
||||
try {
|
||||
//get query
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
|
||||
//call service to get prisma entity
|
||||
const rolesEntities = await this.rolesService.get(query);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const roles = Role.hydrateArray<Role>(rolesEntities, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, roles);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get a specific role by uid
|
||||
*/
|
||||
@Get("/api/v1/admin/roles/:uid", [authHandler, ruleHandler])
|
||||
protected async getOneByUid(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
let roleEntity: Roles | null;
|
||||
//get query
|
||||
if (req.query["q"]) {
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
roleEntity = await this.rolesService.getByUid(uid, query);
|
||||
} else {
|
||||
//call service to get prisma entity
|
||||
roleEntity = await this.rolesService.getByUid(uid);
|
||||
}
|
||||
|
||||
if (!roleEntity) {
|
||||
this.httpNotFoundRequest(response, "role not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const role = Role.hydrate<Role>(roleEntity, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, role);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
77
src/app/api/admin/RulesController.ts
Normal file
77
src/app/api/admin/RulesController.ts
Normal file
@ -0,0 +1,77 @@
|
||||
import { Response, Request } from "express";
|
||||
import { Controller, Get } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import RulesService from "@Services/admin/RulesService/RulesService";
|
||||
import { Service } from "typedi";
|
||||
import { Rule } from "le-coffre-resources/dist/Admin";
|
||||
import { Rules } from "@prisma/client";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
export default class RulesController extends ApiController {
|
||||
constructor(private rulesService: RulesService) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get all rules
|
||||
*/
|
||||
@Get("/api/v1/admin/rules", [authHandler, ruleHandler])
|
||||
protected async get(req: Request, response: Response) {
|
||||
try {
|
||||
//get query
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
|
||||
//call service to get prisma entity
|
||||
const rulesEntities = await this.rulesService.get(query);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const rules = Rule.hydrateArray<Rule>(rulesEntities, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, rules);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get a specific rule by uid
|
||||
*/
|
||||
@Get("/api/v1/admin/rules/:uid", [authHandler, ruleHandler])
|
||||
protected async getOneByUid(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
let ruleEntity: Rules | null;
|
||||
//get query
|
||||
if (req.query["q"]) {
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
ruleEntity = await this.rulesService.getByUid(uid, query);
|
||||
} else {
|
||||
//call service to get prisma entity
|
||||
ruleEntity = await this.rulesService.getByUid(uid);
|
||||
}
|
||||
|
||||
if (!ruleEntity) {
|
||||
this.httpNotFoundRequest(response, "rule not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const rule = Rule.hydrate<Rule>(ruleEntity, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, rule);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
81
src/app/api/admin/UsersController.ts
Normal file
81
src/app/api/admin/UsersController.ts
Normal file
@ -0,0 +1,81 @@
|
||||
import { Response, Request } from "express";
|
||||
import { Controller, Get } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import UsersService from "@Services/admin/UsersService/UsersService";
|
||||
import { Service } from "typedi";
|
||||
import User from "le-coffre-resources/dist/Admin";
|
||||
import { Prisma, Users } from "@prisma/client";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
import userHandler from "@App/middlewares/OfficeMembershipHandlers/UserHandler";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
export default class UsersController extends ApiController {
|
||||
constructor(private usersService: UsersService) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get all users
|
||||
*/
|
||||
@Get("/api/v1/admin/users", [authHandler, ruleHandler])
|
||||
protected async get(req: Request, response: Response) {
|
||||
try {
|
||||
//get query
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
const officeId: string = req.body.user.office_Id;
|
||||
const officeWhereInput: Prisma.UsersWhereInput = { office_membership: { uid: officeId } };
|
||||
query.where = officeWhereInput;
|
||||
|
||||
//call service to get prisma entity
|
||||
const usersEntities = await this.usersService.get(query);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const users = User.hydrateArray<User>(usersEntities, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, users);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get a specific user by uid
|
||||
*/
|
||||
@Get("/api/v1/admin/users/:uid", [authHandler, ruleHandler, userHandler])
|
||||
protected async getOneByUid(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
let userEntity: Users | null;
|
||||
//get query
|
||||
if (req.query["q"]) {
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
userEntity = await this.usersService.getByUid(uid, query);
|
||||
} else {
|
||||
//call service to get prisma entity
|
||||
userEntity = await this.usersService.getByUid(uid);
|
||||
}
|
||||
|
||||
if (!userEntity) {
|
||||
this.httpNotFoundRequest(response, "user not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const user = User.hydrate<User>(userEntity, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, user);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,11 +1,12 @@
|
||||
import { Response, Request } from "express";
|
||||
import { Controller, Delete, Get, Post, Put } from "@ControllerPattern/index";
|
||||
import { Controller, Get } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import { Service } from "typedi";
|
||||
import DocumentsService from "@Services/customer/DocumentsService/DocumentsService";
|
||||
import { Documents } from "@prisma/client";
|
||||
import { Documents, Prisma } from "@prisma/client";
|
||||
import { Document } from "le-coffre-resources/dist/Customer";
|
||||
import { validateOrReject } from "class-validator";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import documentHandler from "@App/middlewares/CustomerHandler/DocumentHandler";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
@ -18,11 +19,14 @@ export default class DocumentsController extends ApiController {
|
||||
* @description Get all documents
|
||||
* @returns IDocument[] list of documents
|
||||
*/
|
||||
@Get("/api/v1/customer/documents")
|
||||
@Get("/api/v1/customer/documents", [authHandler])
|
||||
protected async get(req: Request, response: Response) {
|
||||
try {
|
||||
//get query
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
const customerId: string = req.body.user.customerId;
|
||||
const customerWhereInput: Prisma.DocumentsWhereInput ={ depositor: { uid: customerId } };
|
||||
query.where = customerWhereInput;
|
||||
|
||||
//call service to get prisma entity
|
||||
const documentEntities: Documents[] = await this.documentsService.get(query);
|
||||
@ -38,112 +42,10 @@ export default class DocumentsController extends ApiController {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Create a new document
|
||||
* @returns IDocument created
|
||||
*/
|
||||
@Post("/api/v1/customer/documents")
|
||||
protected async post(req: Request, response: Response) {
|
||||
try {
|
||||
//init Document resource with request body values
|
||||
const documentEntity = Document.hydrate<Document>(req.body);
|
||||
|
||||
//validate document
|
||||
await validateOrReject(documentEntity, { groups: ["createDocument"] });
|
||||
|
||||
//call service to get prisma entity
|
||||
const documentEntityCreated = await this.documentsService.create(documentEntity);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const document = Document.hydrate<Document>(documentEntityCreated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, document);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Update a specific document
|
||||
*/
|
||||
@Put("/api/v1/customer/documents/:uid")
|
||||
protected async update(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
const documentFound = await this.documentsService.getByUid(uid);
|
||||
|
||||
if (!documentFound) {
|
||||
this.httpNotFoundRequest(response, "document not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//init Document resource with request body values
|
||||
const documentEntity = new Document();
|
||||
Document.hydrate(documentEntity, req.body);
|
||||
|
||||
//validate document
|
||||
await validateOrReject(documentEntity, { groups: ["createDocument"] });
|
||||
|
||||
//call service to get prisma entity
|
||||
const documentEntityUpdated: Documents = await this.documentsService.update(uid, documentEntity);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const document = Document.hydrate<Document>(documentEntityUpdated, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, document);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Delete a specific document
|
||||
*/
|
||||
@Delete("/api/v1/customer/documents/:uid")
|
||||
protected async delete(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
const documentEntity = await this.documentsService.getByUid(uid);
|
||||
|
||||
if (!documentEntity) {
|
||||
this.httpNotFoundRequest(response, "document not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//call service to get prisma entity
|
||||
const documentEntityDeleted: Documents = await this.documentsService.delete(uid);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const document = Document.hydrate<Document>(documentEntityDeleted, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, document);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get a specific document by uid
|
||||
*/
|
||||
@Get("/api/v1/customer/documents/:uid")
|
||||
@Get("/api/v1/customer/documents/:uid",[authHandler,documentHandler])
|
||||
protected async getOneByUid(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
|
219
src/app/api/customer/FilesController.ts
Normal file
219
src/app/api/customer/FilesController.ts
Normal file
@ -0,0 +1,219 @@
|
||||
import { Response, Request } from "express";
|
||||
import { Controller, Delete, Get, Post, Put } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import { Service } from "typedi";
|
||||
import FilesService from "@Services/common/FilesService/FilesService";
|
||||
import { Files, Prisma } from "@prisma/client";
|
||||
import { File } from "le-coffre-resources/dist/Customer";
|
||||
import { Document } from "le-coffre-resources/dist/Customer";
|
||||
import { validateOrReject } from "class-validator";
|
||||
import DocumentsService from "@Services/super-admin/DocumentsService/DocumentsService";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import fileHandler from "@App/middlewares/CustomerHandler/FileHandler";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
export default class FilesController extends ApiController {
|
||||
constructor(private filesService: FilesService, private documentService: DocumentsService) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get all Files
|
||||
* @returns File[] list of Files
|
||||
*/
|
||||
@Get("/api/v1/customer/files", [authHandler])
|
||||
protected async get(req: Request, response: Response) {
|
||||
try {
|
||||
//get query
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
const customerId: string = req.body.user.customerId;
|
||||
const customerWhereInput: Prisma.FilesWhereInput = { document: { depositor: { uid: customerId } } };
|
||||
query.where = customerWhereInput;
|
||||
//call service to get prisma entity
|
||||
const fileEntities = await this.filesService.get(query);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const files = File.hydrateArray<File>(fileEntities, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, files);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get a specific File by uid
|
||||
*/
|
||||
@Get("/api/v1/customer/files/download/:uid", [authHandler, fileHandler])
|
||||
protected async download(req: Request, response: Response) {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "uid not found");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const fileInfo = await this.filesService.download(uid);
|
||||
|
||||
if (!fileInfo) {
|
||||
this.httpNotFoundRequest(response, "file not found");
|
||||
return;
|
||||
}
|
||||
|
||||
response.setHeader("Content-Type", fileInfo.file.mimetype);
|
||||
response.setHeader("Content-Disposition", `inline; filename=${encodeURIComponent(fileInfo.file.file_name)}`);
|
||||
|
||||
this.httpSuccess(response, fileInfo.buffer);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Create a new File
|
||||
* @returns File created
|
||||
*/
|
||||
@Post("/api/v1/customer/files", [authHandler, fileHandler])
|
||||
protected async post(req: Request, response: Response) {
|
||||
try {
|
||||
//get file
|
||||
if (!req.file) throw new Error("No file provided");
|
||||
|
||||
//init File resource with request body values
|
||||
const fileEntity = File.hydrate<File>(JSON.parse(req.body["q"]));
|
||||
|
||||
//validate File
|
||||
await validateOrReject(fileEntity, { groups: ["createFile"] });
|
||||
|
||||
//call service to get prisma entity
|
||||
const fileEntityCreated = await this.filesService.create(fileEntity, req.file);
|
||||
|
||||
const document = await this.documentService.getByUid(fileEntity.document!.uid!);
|
||||
|
||||
const documentToUpdate = Document.hydrate<Document>(document!);
|
||||
|
||||
documentToUpdate!.document_status = "DEPOSITED";
|
||||
await this.documentService.update(document!.uid!, documentToUpdate);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const fileEntityHydrated = File.hydrate<File>(fileEntityCreated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpCreated(response, fileEntityHydrated);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Update a specific file
|
||||
*/
|
||||
@Put("/api/v1/customer/files/:uid", [authHandler, fileHandler])
|
||||
protected async update(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
throw new Error("No uid provided");
|
||||
}
|
||||
|
||||
const fileFound = await this.filesService.getByUid(uid);
|
||||
|
||||
if (!fileFound) {
|
||||
this.httpNotFoundRequest(response, "file not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//init File resource with request body values
|
||||
const fileEntity = File.hydrate<File>(req.body);
|
||||
|
||||
//validate file
|
||||
await validateOrReject(fileEntity, { groups: ["updateFile"] });
|
||||
|
||||
//call service to get prisma entity
|
||||
const fileEntityUpdated: Files = await this.filesService.update(uid, fileEntity);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const file = File.hydrate<File>(fileEntityUpdated, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, file);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Delete a specific File
|
||||
*/
|
||||
@Delete("/api/v1/customer/files/:uid", [authHandler, fileHandler])
|
||||
protected async delete(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
const fileFound = await this.filesService.getByUid(uid);
|
||||
|
||||
if (!fileFound) {
|
||||
this.httpNotFoundRequest(response, "file not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//call service to get prisma entity
|
||||
const fileEntity = await this.filesService.deleteKeyAndArchive(uid);
|
||||
|
||||
if (!fileEntity) {
|
||||
this.httpNotFoundRequest(response, "file not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const file = File.hydrate<File>(fileEntity, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, file);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get a specific File by uid
|
||||
*/
|
||||
@Get("/api/v1/customer/files/:uid", [authHandler, fileHandler])
|
||||
protected async getOneByUid(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
const fileEntity = await this.filesService.getByUid(uid);
|
||||
|
||||
if (!fileEntity) {
|
||||
this.httpNotFoundRequest(response, "file not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const file = File.hydrate<File>(fileEntity, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, file);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
64
src/app/api/franceConnect/CustomerController.ts
Normal file
64
src/app/api/franceConnect/CustomerController.ts
Normal file
@ -0,0 +1,64 @@
|
||||
import { Response, Request } from "express";
|
||||
import { Controller, Post } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import { Service } from "typedi";
|
||||
import AuthService from "@Services/common/AuthService/AuthService";
|
||||
import { JwtPayload } from "jsonwebtoken";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
export default class CustomerController extends ApiController {
|
||||
constructor(private authService: AuthService) {
|
||||
super();
|
||||
}
|
||||
|
||||
@Post("/api/v1/france-connect/customer/login/:email")
|
||||
protected async login(req: Request, response: Response) {
|
||||
try {
|
||||
const email = req.params["email"];
|
||||
if (!email) throw new Error("email is required");
|
||||
|
||||
const payload = await this.authService.getCustomerJwtPayload(email);
|
||||
const accessToken = this.authService.generateAccessToken(payload);
|
||||
const refreshToken = this.authService.generateRefreshToken(payload);
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, { accessToken, refreshToken });
|
||||
} catch (error) {
|
||||
this.httpInternalError(response);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@Post("/api/v1/france-connect/customer/refresh-token")
|
||||
protected async refreshToken(req: Request, response: Response) {
|
||||
try {
|
||||
const authHeader = req.headers["authorization"];
|
||||
const token = authHeader && authHeader.split(" ")[1];
|
||||
|
||||
if (!token) {
|
||||
this.httpBadRequest(response);
|
||||
return;
|
||||
}
|
||||
|
||||
let accessToken;
|
||||
this.authService.verifyRefreshToken(token, (err, customerPayload) => {
|
||||
if (err) {
|
||||
this.httpUnauthorized(response);
|
||||
return;
|
||||
}
|
||||
|
||||
const customer = customerPayload as JwtPayload;
|
||||
delete customer.iat;
|
||||
delete customer!.exp;
|
||||
accessToken = this.authService.generateAccessToken(customer);
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, accessToken);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
146
src/app/api/notary/CustomersController.ts
Normal file
146
src/app/api/notary/CustomersController.ts
Normal file
@ -0,0 +1,146 @@
|
||||
import { Response, Request } from "express";
|
||||
import { Controller, Get, Post, Put } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import CustomersService from "@Services/notary/CustomersService/CustomersService";
|
||||
import { Service } from "typedi";
|
||||
import { Customer } from "le-coffre-resources/dist/Notary";
|
||||
import { Customers } from "@prisma/client";
|
||||
import { validateOrReject } from "class-validator";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
export default class CustomersController extends ApiController {
|
||||
constructor(private customersService: CustomersService) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get all customers
|
||||
*/
|
||||
@Get("/api/v1/notary/customers", [authHandler, ruleHandler])
|
||||
protected async get(req: Request, response: Response) {
|
||||
try {
|
||||
//get query
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
|
||||
//call service to get prisma entity
|
||||
const customersEntities = await this.customersService.get(query);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const customers = Customer.hydrateArray<Customer>(customersEntities, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, customers);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Create a new customer
|
||||
*/
|
||||
@Post("/api/v1/notary/customers", [authHandler, ruleHandler])
|
||||
protected async post(req: Request, response: Response) {
|
||||
try {
|
||||
//init IUser resource with request body values
|
||||
const customerEntity = Customer.hydrate<Customer>(req.body);
|
||||
//validate user
|
||||
await validateOrReject(customerEntity, { groups: ["createCustomer"], forbidUnknownValues: false });
|
||||
|
||||
//call service to get prisma entity
|
||||
const customerEntityCreated = await this.customersService.create(customerEntity);
|
||||
//Hydrate ressource with prisma entity
|
||||
const customer = Customer.hydrate<Customer>(customerEntityCreated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpCreated(response, customer);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Modify a specific customer by uid
|
||||
*/
|
||||
@Put("/api/v1/notary/customers/:uid", [authHandler, ruleHandler])
|
||||
protected async put(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
const userFound = await this.customersService.getByUid(uid);
|
||||
|
||||
if (!userFound) {
|
||||
this.httpNotFoundRequest(response, "user not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//init IUser resource with request body values
|
||||
const customerEntity = Customer.hydrate<Customer>(req.body);
|
||||
|
||||
//validate user
|
||||
await validateOrReject(customerEntity, { groups: ["updateCustomer"], forbidUnknownValues: false });
|
||||
|
||||
//call service to get prisma entity
|
||||
const customerEntityUpdated = await this.customersService.update(uid, customerEntity);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const customer = Customer.hydrate<Customer>(customerEntityUpdated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, customer);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get a specific customer by uid
|
||||
*/
|
||||
@Get("/api/v1/notary/customers/:uid", [authHandler, ruleHandler])
|
||||
protected async getOneByUid(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
let customerEntity: Customers | null;
|
||||
//get query
|
||||
if (req.query["q"]) {
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
customerEntity = await this.customersService.getByUid(uid, query);
|
||||
} else {
|
||||
//call service to get prisma entity
|
||||
customerEntity = await this.customersService.getByUid(uid);
|
||||
}
|
||||
|
||||
if (!customerEntity) {
|
||||
this.httpNotFoundRequest(response, "customer not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const customer = Customer.hydrate<Customer>(customerEntity, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, customer);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
156
src/app/api/notary/DeedTypesController.ts
Normal file
156
src/app/api/notary/DeedTypesController.ts
Normal file
@ -0,0 +1,156 @@
|
||||
import { Response, Request } from "express";
|
||||
import { Controller, Get, Post, Put } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import { Service } from "typedi";
|
||||
import DeedTypesService from "@Services/notary/DeedTypesService/DeedTypesService";
|
||||
import { DeedTypes, Prisma } from "@prisma/client";
|
||||
import { DeedType } from "le-coffre-resources/dist/Notary";
|
||||
import { validateOrReject } from "class-validator";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
import deedTypeHandler from "@App/middlewares/OfficeMembershipHandlers/DeedTypeHandler";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
export default class DeedTypesController extends ApiController {
|
||||
constructor(private deedTypesService: DeedTypesService) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get all deedtypes
|
||||
* @returns Deedtype[] list of deedtypes
|
||||
*/
|
||||
@Get("/api/v1/notary/deed-types", [authHandler, ruleHandler])
|
||||
protected async get(req: Request, response: Response) {
|
||||
try {
|
||||
//get query
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
const officeId: string = req.body.user.office_Id;
|
||||
const officeWhereInput: Prisma.DeedTypesWhereInput = { office: { uid: officeId } };
|
||||
query.where = officeWhereInput;
|
||||
|
||||
//call service to get prisma entity
|
||||
const deedTypeEntities: DeedTypes[] = await this.deedTypesService.get(query);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const DeedTypes = DeedType.hydrateArray<DeedType>(deedTypeEntities, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, DeedTypes);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Create a new deedtype
|
||||
* @returns Deedtype created
|
||||
*/
|
||||
@Post("/api/v1/notary/deed-types", [authHandler, ruleHandler, deedTypeHandler])
|
||||
protected async post(req: Request, response: Response) {
|
||||
try {
|
||||
//init DeedType resource with request body values
|
||||
const deedTypeEntity = DeedType.hydrate<DeedType>(req.body);
|
||||
|
||||
//validate deed type
|
||||
await validateOrReject(deedTypeEntity, { groups: ["createDeedType"], forbidUnknownValues: false });
|
||||
|
||||
//call service to get prisma entity
|
||||
const deedTypeEntityCreated = await this.deedTypesService.create(deedTypeEntity);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const deedType = DeedType.hydrate<DeedType>(deedTypeEntityCreated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpCreated(response, deedType);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Modify a specific deedtype by uid
|
||||
* @returns Deedtype modified
|
||||
*/
|
||||
@Put("/api/v1/notary/deed-types/:uid", [authHandler, ruleHandler, deedTypeHandler])
|
||||
protected async put(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
const deedTypeFound = await this.deedTypesService.getByUid(uid);
|
||||
|
||||
if (!deedTypeFound) {
|
||||
this.httpNotFoundRequest(response, "deed type not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//init DeedType resource with request body values
|
||||
const deedTypeEntity = DeedType.hydrate<DeedType>(req.body);
|
||||
|
||||
//validate deed type
|
||||
await validateOrReject(deedTypeEntity, { groups: ["updateDeedType"] });
|
||||
|
||||
//call service to get prisma entity
|
||||
const deedTypeEntityUpdated = await this.deedTypesService.update(uid, deedTypeEntity);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const deedType = DeedType.hydrate<DeedType>(deedTypeEntityUpdated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, deedType);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get a specific deedtype by uid
|
||||
* @returns IDeedtype
|
||||
*/
|
||||
@Get("/api/v1/notary/deed-types/:uid", [authHandler, ruleHandler, deedTypeHandler])
|
||||
protected async getOneByUid(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
let deedTypeEntity: DeedTypes | null;
|
||||
//get query
|
||||
if (req.query["q"]) {
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
deedTypeEntity = await this.deedTypesService.getByUid(uid, query);
|
||||
} else {
|
||||
//call service to get prisma entity
|
||||
deedTypeEntity = await this.deedTypesService.getByUid(uid);
|
||||
}
|
||||
|
||||
if (!deedTypeEntity) {
|
||||
this.httpNotFoundRequest(response, "deed type not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const deedType = DeedType.hydrate<DeedType>(deedTypeEntity, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, deedType);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
126
src/app/api/notary/DeedsController.ts
Normal file
126
src/app/api/notary/DeedsController.ts
Normal file
@ -0,0 +1,126 @@
|
||||
import { Response, Request } from "express";
|
||||
import { Controller, Get, Put } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import DeedsService from "@Services/notary/DeedsService/DeedsService";
|
||||
import { Service } from "typedi";
|
||||
import { Deeds, Prisma } from "@prisma/client";
|
||||
import { Deed } from "le-coffre-resources/dist/Notary";
|
||||
import { validateOrReject } from "class-validator";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
import deedHandler from "@App/middlewares/OfficeMembershipHandlers/DeedHandler";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
export default class DeedsController extends ApiController {
|
||||
constructor(private deedsService: DeedsService) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get all deeds
|
||||
* @returns Deed[] list of deeds
|
||||
*/
|
||||
@Get("/api/v1/notary/deeds", [authHandler, ruleHandler])
|
||||
protected async get(req: Request, response: Response) {
|
||||
try {
|
||||
//get query
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
const officeId: string = req.body.user.office_Id;
|
||||
const officeWhereInput: Prisma.DeedsWhereInput = { deed_type: { office: { uid: officeId } } };
|
||||
query.where = officeWhereInput;
|
||||
|
||||
//call service to get prisma entity
|
||||
const deedEntities: Deeds[] = await this.deedsService.get(query);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const deeds = Deed.hydrateArray<Deed>(deedEntities, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, deeds);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get a specific deed by uid
|
||||
* @returns Deed
|
||||
*/
|
||||
@Get("/api/v1/notary/deeds/:uid", [authHandler, ruleHandler, deedHandler])
|
||||
protected async getOneByUid(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
let deedEntity: Deeds | null;
|
||||
//get query
|
||||
if (req.query["q"]) {
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
deedEntity = await this.deedsService.getByUid(uid, query);
|
||||
} else {
|
||||
//call service to get prisma entity
|
||||
deedEntity = await this.deedsService.getByUid(uid);
|
||||
}
|
||||
|
||||
if (!deedEntity) {
|
||||
this.httpNotFoundRequest(response, "deed not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const deed = Deed.hydrate<Deed>(deedEntity, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, deed);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Modify a specific deed by uid
|
||||
*/
|
||||
@Put("/api/v1/notary/deeds/:uid", [authHandler, ruleHandler, deedHandler])
|
||||
protected async put(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
const deedFound = await this.deedsService.getByUid(uid);
|
||||
|
||||
if (!deedFound) {
|
||||
this.httpNotFoundRequest(response, "deed not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//init OfficeFolder resource with request body values
|
||||
const deedEntity = Deed.hydrate<Deed>(req.body);
|
||||
|
||||
//validate folder
|
||||
await validateOrReject(deedEntity, { groups: ["updateDeed"], forbidUnknownValues: false });
|
||||
|
||||
//call service to get prisma entity
|
||||
const deedEntityUpdated = await this.deedsService.update(uid, deedEntity);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const deed = Deed.hydrate<Deed>(deedEntityUpdated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, deed);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
145
src/app/api/notary/DocumentTypesController.ts
Normal file
145
src/app/api/notary/DocumentTypesController.ts
Normal file
@ -0,0 +1,145 @@
|
||||
import { Response, Request } from "express";
|
||||
import { Controller, Get, Post, Put } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import { Service } from "typedi";
|
||||
import DocumentTypesService from "@Services/notary/DocumentTypesService/DocumentTypesService";
|
||||
import { DocumentTypes, Prisma } from "@prisma/client";
|
||||
import ObjectHydrate from "@Common/helpers/ObjectHydrate";
|
||||
import { DocumentType } from "le-coffre-resources/dist/Notary";
|
||||
import { validateOrReject } from "class-validator";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
import documentTypeHandler from "@App/middlewares/OfficeMembershipHandlers/DocumentTypeHandler";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
export default class DocumentTypesController extends ApiController {
|
||||
constructor(private documentTypesService: DocumentTypesService) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get all document-types
|
||||
*/
|
||||
@Get("/api/v1/notary/document-types", [authHandler, ruleHandler])
|
||||
protected async get(req: Request, response: Response) {
|
||||
try {
|
||||
//get query
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
const officeId: string = req.body.user.office_Id;
|
||||
const officeWhereInput: Prisma.DocumentTypesWhereInput = { office: { uid: officeId } };
|
||||
query.where = officeWhereInput;
|
||||
|
||||
//call service to get prisma entity
|
||||
const documentTypeEntities: DocumentTypes[] = await this.documentTypesService.get(query);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const documentTypes = DocumentType.hydrateArray<DocumentType>(documentTypeEntities, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, documentTypes);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Create a new documentType
|
||||
*/
|
||||
@Post("/api/v1/notary/document-types", [authHandler, ruleHandler, documentTypeHandler])
|
||||
protected async post(req: Request, response: Response) {
|
||||
try {
|
||||
//init DocumentType resource with request body values
|
||||
const documentTypeEntity = DocumentType.hydrate<DocumentType>(req.body);
|
||||
//validate user
|
||||
await validateOrReject(documentTypeEntity, { groups: ["createDocumentType"], forbidUnknownValues: false });
|
||||
//call service to get prisma entity
|
||||
const documentTypeEntityCreated = await this.documentTypesService.create(documentTypeEntity);
|
||||
//Hydrate ressource with prisma entity
|
||||
const userEntityCreated = DocumentType.hydrate<DocumentType>(documentTypeEntityCreated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
//success
|
||||
this.httpCreated(response, userEntityCreated);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Modify a specific documentType by uid
|
||||
*/
|
||||
@Put("/api/v1/notary/document-types/:uid", [authHandler, ruleHandler, documentTypeHandler])
|
||||
protected async put(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
const documentTypeFound = await this.documentTypesService.getByUid(uid);
|
||||
|
||||
if (!documentTypeFound) {
|
||||
this.httpNotFoundRequest(response, "document type not found");
|
||||
return;
|
||||
}
|
||||
//init DocumentType resource with request body values
|
||||
const documentTypeEntity = DocumentType.hydrate<DocumentType>(req.body);
|
||||
|
||||
//validate user
|
||||
await validateOrReject(documentTypeEntity, { groups: ["updateDocumentType"] });
|
||||
|
||||
//call service to get prisma entity
|
||||
const documentTypeEntityUpdated = await this.documentTypesService.update(uid, documentTypeEntity);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const documentType = DocumentType.hydrate<DocumentType>(documentTypeEntityUpdated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, documentType);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get a specific documentType by uid
|
||||
*/
|
||||
@Get("/api/v1/notary/document-types/:uid", [authHandler, ruleHandler, documentTypeHandler])
|
||||
protected async getOneByUid(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
let documentTypeEntity: DocumentTypes | null;
|
||||
//get query
|
||||
if (req.query["q"]) {
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
documentTypeEntity = await this.documentTypesService.getByUid(uid, query);
|
||||
} else {
|
||||
//call service to get prisma entity
|
||||
documentTypeEntity = await this.documentTypesService.getByUid(uid);
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const user = ObjectHydrate.hydrate<DocumentType>(new DocumentType(), documentTypeEntity!, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, user);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
185
src/app/api/notary/DocumentsController.ts
Normal file
185
src/app/api/notary/DocumentsController.ts
Normal file
@ -0,0 +1,185 @@
|
||||
import { Response, Request } from "express";
|
||||
import { Controller, Delete, Get, Post, Put } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import { Service } from "typedi";
|
||||
import DocumentsService from "@Services/notary/DocumentsService/DocumentsService";
|
||||
import { Documents, Prisma } from "@prisma/client";
|
||||
import { Document } from "le-coffre-resources/dist/Notary";
|
||||
import { validateOrReject } from "class-validator";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
import documentHandler from "@App/middlewares/OfficeMembershipHandlers/DocumentHandler";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
export default class DocumentsController extends ApiController {
|
||||
constructor(private documentsService: DocumentsService) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get all documents
|
||||
* @returns IDocument[] list of documents
|
||||
*/
|
||||
@Get("/api/v1/notary/documents", [authHandler, ruleHandler])
|
||||
protected async get(req: Request, response: Response) {
|
||||
try {
|
||||
//get query
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
const officeId: string = req.body.user.office_Id;
|
||||
const officeWhereInput: Prisma.DocumentsWhereInput = { document_type: { office: { uid: officeId } } };
|
||||
query.where = officeWhereInput;
|
||||
|
||||
//call service to get prisma entity
|
||||
const documentEntities = await this.documentsService.get(query);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const documents = Document.hydrateArray<Document>(documentEntities, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, documents);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Create a new document
|
||||
* @returns IDocument created
|
||||
*/
|
||||
@Post("/api/v1/notary/documents", [authHandler, ruleHandler, documentHandler])
|
||||
protected async post(req: Request, response: Response) {
|
||||
try {
|
||||
//init Document resource with request body values
|
||||
const documentEntity = Document.hydrate<Document>(req.body);
|
||||
|
||||
//validate document
|
||||
await validateOrReject(documentEntity, { groups: ["createDocument"], forbidUnknownValues: false });
|
||||
|
||||
//call service to get prisma entity
|
||||
const documentEntityCreated = await this.documentsService.create(documentEntity);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const document = Document.hydrate<Document>(documentEntityCreated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpCreated(response, document);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Update a specific document
|
||||
*/
|
||||
@Put("/api/v1/notary/documents/:uid", [authHandler, ruleHandler, documentHandler])
|
||||
protected async update(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
const documentFound = await this.documentsService.getByUid(uid);
|
||||
|
||||
if (!documentFound) {
|
||||
this.httpNotFoundRequest(response, "document not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//init Document resource with request body values
|
||||
const documentEntity = Document.hydrate<Document>(req.body);
|
||||
|
||||
//validate document
|
||||
await validateOrReject(documentEntity, { groups: ["updateDocument"] });
|
||||
|
||||
//call service to get prisma entity
|
||||
const documentEntityUpdated: Documents = await this.documentsService.update(uid, documentEntity, req.body.refused_reason);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const document = Document.hydrate<Document>(documentEntityUpdated, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, document);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Delete a specific document
|
||||
*/
|
||||
@Delete("/api/v1/notary/documents/: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.documentsService.getByUid(uid);
|
||||
|
||||
if (!documentFound) {
|
||||
this.httpNotFoundRequest(response, "document not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//call service to get prisma entity
|
||||
const documentEntity: Documents = await this.documentsService.delete(uid);
|
||||
|
||||
//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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get a specific document by uid
|
||||
*/
|
||||
@Get("/api/v1/notary/documents/: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;
|
||||
}
|
||||
|
||||
let documentEntity: Documents | null;
|
||||
//get query
|
||||
if (req.query["q"]) {
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
documentEntity = await this.documentsService.getByUid(uid, query);
|
||||
} else {
|
||||
//call service to get prisma entity
|
||||
documentEntity = await this.documentsService.getByUid(uid);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
140
src/app/api/notary/FilesController.ts
Normal file
140
src/app/api/notary/FilesController.ts
Normal file
@ -0,0 +1,140 @@
|
||||
import { Response, Request } from "express";
|
||||
import { Controller, Delete, Get } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import { Service } from "typedi";
|
||||
import FilesService from "@Services/common/FilesService/FilesService";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import { File } from "le-coffre-resources/dist/Notary";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
import fileHandler from "@App/middlewares/OfficeMembershipHandlers/FileHandler";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
export default class FilesController extends ApiController {
|
||||
constructor(private filesService: FilesService) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get all Files
|
||||
* @returns File[] list of Files
|
||||
*/
|
||||
@Get("/api/v1/notary/files", [authHandler, ruleHandler])
|
||||
protected async get(req: Request, response: Response) {
|
||||
try {
|
||||
//get query
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
const officeId: string = req.body.user.office_Id;
|
||||
const officeWhereInput: Prisma.FilesWhereInput = { document: { folder: { office: { uid: officeId } } } };
|
||||
query.where = officeWhereInput;
|
||||
//call service to get prisma entity
|
||||
const fileEntities = await this.filesService.get(query);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const files = File.hydrateArray<File>(fileEntities, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, files);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get a specific File by uid
|
||||
*/
|
||||
@Get("/api/v1/notary/files/download/:uid", [authHandler, ruleHandler, fileHandler])
|
||||
protected async download(req: Request, response: Response) {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "uid not found");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const fileInfo = await this.filesService.download(uid);
|
||||
|
||||
if (!fileInfo) {
|
||||
this.httpNotFoundRequest(response, "file not found");
|
||||
return;
|
||||
}
|
||||
|
||||
response.setHeader("Content-Type", fileInfo.file.mimetype);
|
||||
response.setHeader("Content-Disposition", `inline; filename=${encodeURIComponent(fileInfo.file.file_name)}`);
|
||||
|
||||
this.httpSuccess(response, fileInfo.buffer);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Delete a specific File
|
||||
*/
|
||||
@Delete("/api/v1/notary/files/:uid", [authHandler, ruleHandler, fileHandler])
|
||||
protected async delete(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
const fileFound = await this.filesService.getByUid(uid);
|
||||
|
||||
if (!fileFound) {
|
||||
this.httpNotFoundRequest(response, "file not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//call service to get prisma entity
|
||||
const fileEntity = await this.filesService.deleteKeyAndArchive(uid);
|
||||
|
||||
if (!fileEntity) {
|
||||
this.httpNotFoundRequest(response, "file not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const file = File.hydrate<File>(fileEntity, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, file);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get a specific File by uid
|
||||
*/
|
||||
@Get("/api/v1/notary/files/:uid", [authHandler, ruleHandler, fileHandler])
|
||||
protected async getOneByUid(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
const fileEntity = await this.filesService.getByUid(uid);
|
||||
|
||||
if (!fileEntity) {
|
||||
this.httpNotFoundRequest(response, "file not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const file = File.hydrate<File>(fileEntity, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, file);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
183
src/app/api/notary/OfficeFoldersController.ts
Normal file
183
src/app/api/notary/OfficeFoldersController.ts
Normal file
@ -0,0 +1,183 @@
|
||||
import { Response, Request } from "express";
|
||||
import { Controller, Delete, Get, Post, Put } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import OfficeFoldersService from "@Services/notary/OfficeFoldersService/OfficeFoldersService";
|
||||
import { Service } from "typedi";
|
||||
import { OfficeFolders, Prisma } from "@prisma/client";
|
||||
import { OfficeFolder } from "le-coffre-resources/dist/Notary";
|
||||
import { validateOrReject } from "class-validator";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
import folderHandler from "@App/middlewares/OfficeMembershipHandlers/FolderHandler";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
export default class OfficeFoldersController extends ApiController {
|
||||
constructor(private officeFoldersService: OfficeFoldersService) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get all folders
|
||||
*/
|
||||
@Get("/api/v1/notary/folders", [authHandler, ruleHandler])
|
||||
protected async get(req: Request, response: Response) {
|
||||
try {
|
||||
//get query
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
const officeId: string = req.body.user.office_Id;
|
||||
const officeWhereInput: Prisma.OfficeFoldersWhereInput = { office: { uid: officeId } };
|
||||
query.where = officeWhereInput;
|
||||
//call service to get prisma entity
|
||||
const officeFolderEntities: OfficeFolders[] = await this.officeFoldersService.get(query);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const officeFolders = OfficeFolder.hydrateArray<OfficeFolder>(officeFolderEntities, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
//success
|
||||
this.httpSuccess(response, officeFolders);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Create a new folder
|
||||
*/
|
||||
@Post("/api/v1/notary/folders", [authHandler, ruleHandler, folderHandler])
|
||||
protected async post(req: Request, response: Response) {
|
||||
try {
|
||||
//init OfficeFolder resource with request body values
|
||||
const officeFolderRessource = OfficeFolder.hydrate<OfficeFolder>(req.body);
|
||||
await officeFolderRessource.validateOrReject?.({ groups: ["createFolder"], forbidUnknownValues: false });
|
||||
|
||||
//call service to get prisma entity
|
||||
const officeFolderEntity = await this.officeFoldersService.create(officeFolderRessource);
|
||||
//Hydrate ressource with prisma entity
|
||||
const officeFolders = OfficeFolder.hydrate<OfficeFolder>(officeFolderEntity, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
//success
|
||||
this.httpCreated(response, officeFolders);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Modify a specific folder by uid
|
||||
*/
|
||||
@Put("/api/v1/notary/folders/:uid", [authHandler, ruleHandler, folderHandler])
|
||||
protected async put(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
const officeFolderFound = await this.officeFoldersService.getByUid(uid);
|
||||
|
||||
if (!officeFolderFound) {
|
||||
this.httpNotFoundRequest(response, "office folder not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//init OfficeFolder resource with request body values
|
||||
const officeFolderEntity = OfficeFolder.hydrate<OfficeFolder>(req.body);
|
||||
|
||||
//validate folder
|
||||
await validateOrReject(officeFolderEntity, { groups: ["updateFolder"], forbidUnknownValues: false });
|
||||
|
||||
//call service to get prisma entity
|
||||
const officeFolderEntityUpdated = await this.officeFoldersService.update(uid, officeFolderEntity);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const officeFolders = OfficeFolder.hydrate<OfficeFolder>(officeFolderEntityUpdated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, officeFolders);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get a specific folder by uid
|
||||
* @returns IFolder
|
||||
*/
|
||||
@Get("/api/v1/notary/folders/:uid", [authHandler, ruleHandler, folderHandler])
|
||||
protected async getOneByUid(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
let officeFolderEntity: OfficeFolders | null;
|
||||
//get query
|
||||
if (req.query["q"]) {
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
officeFolderEntity = await this.officeFoldersService.getByUid(uid, query);
|
||||
} else {
|
||||
//call service to get prisma entity
|
||||
officeFolderEntity = await this.officeFoldersService.getByUid(uid);
|
||||
}
|
||||
|
||||
if (!officeFolderEntity) {
|
||||
this.httpNotFoundRequest(response, "folder not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const officeFolder = OfficeFolder.hydrate<OfficeFolder>(officeFolderEntity, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, officeFolder);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
this.httpSuccess(response, await this.officeFoldersService.getByUid("uid"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Delete a specific folder
|
||||
*/
|
||||
@Delete("/api/v1/notary/folders/:uid", [authHandler, ruleHandler, folderHandler])
|
||||
protected async delete(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
|
||||
const officeFolderFound = await this.officeFoldersService.getByUid(uid);
|
||||
|
||||
if (!officeFolderFound) {
|
||||
this.httpNotFoundRequest(response, "office folder not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//call service to get prisma entity
|
||||
const officeFoldertEntity: OfficeFolders = await this.officeFoldersService.delete(uid);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const officeFolder = OfficeFolder.hydrate<OfficeFolder>(officeFoldertEntity, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, officeFolder);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
81
src/app/api/notary/OfficeRolesController.ts
Normal file
81
src/app/api/notary/OfficeRolesController.ts
Normal file
@ -0,0 +1,81 @@
|
||||
import { Response, Request } from "express";
|
||||
import { Controller, Get } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import OfficeRolesService from "@Services/notary/OfficeRolesService/OfficeRolesService";
|
||||
import { Service } from "typedi";
|
||||
import { OfficeRole } from "le-coffre-resources/dist/Notary";
|
||||
import { OfficeRoles, Prisma } from "@prisma/client";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
import officeRoleHandler from "@App/middlewares/OfficeMembershipHandlers/OfficeRoleHandler";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
export default class OfficeRolesController extends ApiController {
|
||||
constructor(private officeRolesService: OfficeRolesService) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get all officeRoles
|
||||
*/
|
||||
@Get("/api/v1/notary/officeRoles", [authHandler, ruleHandler])
|
||||
protected async get(req: Request, response: Response) {
|
||||
try {
|
||||
//get query
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
const officeId: string = req.body.user.office_Id;
|
||||
const officeWhereInput: Prisma.OfficeRolesWhereInput = { office: { uid: officeId } };
|
||||
query.where = officeWhereInput;
|
||||
|
||||
//call service to get prisma entity
|
||||
const officeRolesEntities = await this.officeRolesService.get(query);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const officeRoles = OfficeRole.hydrateArray<OfficeRole>(officeRolesEntities, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, officeRoles);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get a specific officeRole by uid
|
||||
*/
|
||||
@Get("/api/v1/notary/office-roles/:uid", [authHandler, ruleHandler, officeRoleHandler])
|
||||
protected async getOneByUid(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
let officeRoleEntity: OfficeRoles | null;
|
||||
//get query
|
||||
if (req.query["q"]) {
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
officeRoleEntity = await this.officeRolesService.getByUid(uid, query);
|
||||
} else {
|
||||
//call service to get prisma entity
|
||||
officeRoleEntity = await this.officeRolesService.getByUid(uid);
|
||||
}
|
||||
|
||||
if (!officeRoleEntity) {
|
||||
this.httpNotFoundRequest(response, "officeRole not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const officeRole = OfficeRole.hydrate<OfficeRole>(officeRoleEntity, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, officeRole);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
72
src/app/api/notary/OfficesController.ts
Normal file
72
src/app/api/notary/OfficesController.ts
Normal file
@ -0,0 +1,72 @@
|
||||
import { Response, Request } from "express";
|
||||
import { Controller, Get } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import OfficesService from "@Services/notary/OfficesService/OfficesService";
|
||||
import { Service } from "typedi";
|
||||
import { Offices } from "@prisma/client";
|
||||
import { Office as OfficeResource } from "le-coffre-resources/dist/Notary";
|
||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
export default class OfficesController extends ApiController {
|
||||
constructor(private officesService: OfficesService) {
|
||||
super();
|
||||
}
|
||||
/**
|
||||
* @description Get all offices
|
||||
*/
|
||||
@Get("/api/v1/notary/offices", [authHandler, ruleHandler])
|
||||
protected async get(req: Request, response: Response) {
|
||||
try {
|
||||
//get query
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
//call service to get prisma entity
|
||||
const officesEntities: Offices[] = await this.officesService.get(query);
|
||||
//Hydrate ressource with prisma entity
|
||||
const offices = OfficeResource.hydrateArray<OfficeResource>(officesEntities, { strategy: "excludeAll" });
|
||||
//success
|
||||
this.httpSuccess(response, offices);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get a specific office by uid
|
||||
*/
|
||||
@Get("/api/v1/notary/offices/:uid", [authHandler, ruleHandler])
|
||||
protected async getOneByUid(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
let officeEntity: Offices | null;
|
||||
//get query
|
||||
if (req.query["q"]) {
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
officeEntity = await this.officesService.getByUid(uid, query);
|
||||
} else {
|
||||
//call service to get prisma entity
|
||||
officeEntity = await this.officesService.getByUid(uid);
|
||||
}
|
||||
|
||||
if (!officeEntity) {
|
||||
this.httpNotFoundRequest(response, "office not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const office = OfficeResource.hydrate<OfficeResource>(officeEntity, { strategy: "excludeAll" });
|
||||
//success
|
||||
this.httpSuccess(response, office);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
77
src/app/api/notary/RolesController.ts
Normal file
77
src/app/api/notary/RolesController.ts
Normal file
@ -0,0 +1,77 @@
|
||||
import { Response, Request } from "express";
|
||||
import { Controller, Get } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import RolesService from "@Services/notary/RolesService/RolesService";
|
||||
import { Service } from "typedi";
|
||||
import { Role } from "le-coffre-resources/dist/Notary";
|
||||
import { Roles } from "@prisma/client";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
export default class RolesController extends ApiController {
|
||||
constructor(private rolesService: RolesService) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get all roles
|
||||
*/
|
||||
@Get("/api/v1/notary/roles", [authHandler, ruleHandler])
|
||||
protected async get(req: Request, response: Response) {
|
||||
try {
|
||||
//get query
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
|
||||
//call service to get prisma entity
|
||||
const rolesEntities = await this.rolesService.get(query);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const roles = Role.hydrateArray<Role>(rolesEntities, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, roles);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get a specific role by uid
|
||||
*/
|
||||
@Get("/api/v1/notary/roles/:uid", [authHandler, ruleHandler])
|
||||
protected async getOneByUid(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
let roleEntity: Roles | null;
|
||||
//get query
|
||||
if (req.query["q"]) {
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
roleEntity = await this.rolesService.getByUid(uid, query);
|
||||
} else {
|
||||
//call service to get prisma entity
|
||||
roleEntity = await this.rolesService.getByUid(uid);
|
||||
}
|
||||
|
||||
if (!roleEntity) {
|
||||
this.httpNotFoundRequest(response, "role not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const role = Role.hydrate<Role>(roleEntity, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, role);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
77
src/app/api/notary/RulesController.ts
Normal file
77
src/app/api/notary/RulesController.ts
Normal file
@ -0,0 +1,77 @@
|
||||
import { Response, Request } from "express";
|
||||
import { Controller, Get } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import RulesService from "@Services/notary/RulesService/RulesService";
|
||||
import { Service } from "typedi";
|
||||
import { Rule } from "le-coffre-resources/dist/Notary";
|
||||
import { Rules } from "@prisma/client";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
export default class RulesController extends ApiController {
|
||||
constructor(private rulesService: RulesService) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get all rules
|
||||
*/
|
||||
@Get("/api/v1/notary/rules", [authHandler, ruleHandler])
|
||||
protected async get(req: Request, response: Response) {
|
||||
try {
|
||||
//get query
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
|
||||
//call service to get prisma entity
|
||||
const rulesEntities = await this.rulesService.get(query);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const rules = Rule.hydrateArray<Rule>(rulesEntities, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, rules);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get a specific rule by uid
|
||||
*/
|
||||
@Get("/api/v1/notary/rules/:uid", [authHandler, ruleHandler])
|
||||
protected async getOneByUid(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
let ruleEntity: Rules | null;
|
||||
//get query
|
||||
if (req.query["q"]) {
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
ruleEntity = await this.rulesService.getByUid(uid, query);
|
||||
} else {
|
||||
//call service to get prisma entity
|
||||
ruleEntity = await this.rulesService.getByUid(uid);
|
||||
}
|
||||
|
||||
if (!ruleEntity) {
|
||||
this.httpNotFoundRequest(response, "rule not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const rule = Rule.hydrate<Rule>(ruleEntity, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, rule);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
81
src/app/api/notary/UsersController.ts
Normal file
81
src/app/api/notary/UsersController.ts
Normal file
@ -0,0 +1,81 @@
|
||||
import { Response, Request } from "express";
|
||||
import { Controller, Get } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import UsersService from "@Services/notary/UsersService/UsersService";
|
||||
import { Service } from "typedi";
|
||||
import User from "le-coffre-resources/dist/Notary";
|
||||
import { Prisma, Users } from "@prisma/client";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
import userHandler from "@App/middlewares/OfficeMembershipHandlers/UserHandler";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
export default class UsersController extends ApiController {
|
||||
constructor(private usersService: UsersService) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get all users
|
||||
*/
|
||||
@Get("/api/v1/notary/users", [authHandler, ruleHandler])
|
||||
protected async get(req: Request, response: Response) {
|
||||
try {
|
||||
//get query
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
const officeId: string = req.body.user.office_Id;
|
||||
const officeWhereInput: Prisma.UsersWhereInput = { office_membership: { uid: officeId } };
|
||||
query.where = officeWhereInput;
|
||||
|
||||
//call service to get prisma entity
|
||||
const usersEntities = await this.usersService.get(query);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const users = User.hydrateArray<User>(usersEntities, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, users);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get a specific user by uid
|
||||
*/
|
||||
@Get("/api/v1/notary/users/:uid", [authHandler, ruleHandler, userHandler])
|
||||
protected async getOneByUid(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
this.httpBadRequest(response, "No uid provided");
|
||||
return;
|
||||
}
|
||||
let userEntity: Users | null;
|
||||
//get query
|
||||
if (req.query["q"]) {
|
||||
const query = JSON.parse(req.query["q"] as string);
|
||||
userEntity = await this.usersService.getByUid(uid, query);
|
||||
} else {
|
||||
//call service to get prisma entity
|
||||
userEntity = await this.usersService.getByUid(uid);
|
||||
}
|
||||
|
||||
if (!userEntity) {
|
||||
this.httpNotFoundRequest(response, "user not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const user = User.hydrate<User>(userEntity, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, user);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,12 +1,10 @@
|
||||
import { Response, Request } from "express";
|
||||
import { Controller, Delete, Get, Post, Put } from "@ControllerPattern/index";
|
||||
import { Controller, Delete, Get } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import { Service } from "typedi";
|
||||
import FilesService from "@Services/common/FilesService/FilesService";
|
||||
import { Files, Prisma } from "@prisma/client";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import { File } from "le-coffre-resources/dist/SuperAdmin";
|
||||
import { validateOrReject } from "class-validator";
|
||||
import DocumentsService from "@Services/super-admin/DocumentsService/DocumentsService";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
import fileHandler from "@App/middlewares/OfficeMembershipHandlers/FileHandler";
|
||||
@ -14,7 +12,7 @@ import fileHandler from "@App/middlewares/OfficeMembershipHandlers/FileHandler";
|
||||
@Controller()
|
||||
@Service()
|
||||
export default class FilesController extends ApiController {
|
||||
constructor(private filesService: FilesService, private documentService: DocumentsService) {
|
||||
constructor(private filesService: FilesService) {
|
||||
super();
|
||||
}
|
||||
|
||||
@ -72,81 +70,6 @@ export default class FilesController extends ApiController {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Create a new File
|
||||
* @returns File created
|
||||
*/
|
||||
@Post("/api/v1/super-admin/files", [authHandler, ruleHandler, fileHandler])
|
||||
protected async post(req: Request, response: Response) {
|
||||
try {
|
||||
//get file
|
||||
if (!req.file) throw new Error("No file provided");
|
||||
|
||||
//init File resource with request body values
|
||||
const fileEntity = File.hydrate<File>(JSON.parse(req.body["q"]));
|
||||
|
||||
//validate File
|
||||
await validateOrReject(fileEntity, { groups: ["createFile"] });
|
||||
|
||||
//call service to get prisma entity
|
||||
const fileEntityCreated = await this.filesService.create(fileEntity, req.file);
|
||||
|
||||
const document = await this.documentService.getByUid(fileEntity.document!.uid!);
|
||||
|
||||
document!.document_status = "DEPOSITED";
|
||||
await this.documentService.update(document!.uid!, document!);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const fileEntityHydrated = File.hydrate<File>(fileEntityCreated, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
||||
//success
|
||||
this.httpCreated(response, fileEntityHydrated);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Update a specific file
|
||||
*/
|
||||
@Put("/api/v1/super-admin/files/:uid", [authHandler, ruleHandler, fileHandler])
|
||||
protected async update(req: Request, response: Response) {
|
||||
try {
|
||||
const uid = req.params["uid"];
|
||||
if (!uid) {
|
||||
throw new Error("No uid provided");
|
||||
}
|
||||
|
||||
const fileFound = await this.filesService.getByUid(uid);
|
||||
|
||||
if (!fileFound) {
|
||||
this.httpNotFoundRequest(response, "file not found");
|
||||
return;
|
||||
}
|
||||
|
||||
//init File resource with request body values
|
||||
const fileEntity = File.hydrate<File>(req.body);
|
||||
|
||||
//validate file
|
||||
await validateOrReject(fileEntity, { groups: ["updateFile"] });
|
||||
|
||||
//call service to get prisma entity
|
||||
const fileEntityUpdated: Files = await this.filesService.update(uid, fileEntity);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const file = File.hydrate<File>(fileEntityUpdated, { strategy: "excludeAll" });
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, file);
|
||||
} catch (error) {
|
||||
this.httpBadRequest(response, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Delete a specific File
|
||||
*/
|
||||
|
@ -4,7 +4,7 @@ import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import OfficeRolesService from "@Services/super-admin/OfficeRolesService/OfficeRolesService";
|
||||
import { Service } from "typedi";
|
||||
import { validateOrReject } from "class-validator";
|
||||
import { OfficeRole } from "le-coffre-resources/dist/Notary";
|
||||
import { OfficeRole } from "le-coffre-resources/dist/SuperAdmin";
|
||||
import { OfficeRoles, Prisma } from "@prisma/client";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
|
@ -4,7 +4,7 @@ import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import RolesService from "@Services/super-admin/RolesService/RolesService";
|
||||
import { Service } from "typedi";
|
||||
import { validateOrReject } from "class-validator";
|
||||
import { Role } from "le-coffre-resources/dist/Notary";
|
||||
import { Role } from "le-coffre-resources/dist/SuperAdmin";
|
||||
import { Roles } from "@prisma/client";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
|
@ -4,7 +4,7 @@ import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import RulesService from "@Services/super-admin/RulesService/RulesService";
|
||||
import { Service } from "typedi";
|
||||
import { validateOrReject } from "class-validator";
|
||||
import { Rule } from "le-coffre-resources/dist/Notary";
|
||||
import { Rule } from "le-coffre-resources/dist/SuperAdmin";
|
||||
import { Rules } from "@prisma/client";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
|
@ -4,7 +4,7 @@ import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import UsersService from "@Services/super-admin/UsersService/UsersService";
|
||||
import { Service } from "typedi";
|
||||
import { validateOrReject } from "class-validator";
|
||||
import User from "le-coffre-resources/dist/Notary";
|
||||
import User from "le-coffre-resources/dist/SuperAdmin";
|
||||
import { Users } from "@prisma/client";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
|
23
src/app/middlewares/CustomerHandler/DocumentHandler.ts
Normal file
23
src/app/middlewares/CustomerHandler/DocumentHandler.ts
Normal file
@ -0,0 +1,23 @@
|
||||
import HttpCodes from "@Common/system/controller-pattern/HttpCodes";
|
||||
import DocumentsService from "@Services/customer/DocumentsService/DocumentsService";
|
||||
import { NextFunction, Request, Response } from "express";
|
||||
import Container from "typedi";
|
||||
|
||||
export default async function documentHandler(req: Request, response: Response, next: NextFunction) {
|
||||
const customerId = req.body.user.customerId;
|
||||
const uid = req.path && req.path.split("/")[5];
|
||||
|
||||
if(!uid) {
|
||||
response.sendStatus(HttpCodes.BAD_REQUEST);
|
||||
return;
|
||||
}
|
||||
|
||||
const documentService = Container.get(DocumentsService);
|
||||
const document = await documentService.getByUid(uid);
|
||||
|
||||
if(document?.depositor_uid != customerId) {
|
||||
response.sendStatus(HttpCodes.UNAUTHORIZED);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
37
src/app/middlewares/CustomerHandler/FileHandler.ts
Normal file
37
src/app/middlewares/CustomerHandler/FileHandler.ts
Normal file
@ -0,0 +1,37 @@
|
||||
import HttpCodes from "@Common/system/controller-pattern/HttpCodes";
|
||||
import FilesService from "@Services/common/FilesService/FilesService";
|
||||
import DocumentsService from "@Services/customer/DocumentsService/DocumentsService";
|
||||
import { NextFunction, Request, Response } from "express";
|
||||
import Container from "typedi";
|
||||
|
||||
export default async function fileHandler(req: Request, response: Response, next: NextFunction) {
|
||||
const customerId = req.body.user.customerId;
|
||||
const uid = req.path && req.path.split("/")[5];
|
||||
const document = req.body.document;
|
||||
|
||||
if (uid) {
|
||||
const fileService = Container.get(FilesService);
|
||||
const file = await fileService.getByUidWithDocument(uid);
|
||||
if (!file) {
|
||||
response.sendStatus(HttpCodes.BAD_REQUEST);
|
||||
return;
|
||||
}
|
||||
if (file.document.depositor_uid != customerId) {
|
||||
response.sendStatus(HttpCodes.UNAUTHORIZED);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (document) {
|
||||
const documentService = Container.get(DocumentsService);
|
||||
const documentFound = await documentService.getByUid(document.uid!);
|
||||
if(!documentFound) {
|
||||
response.sendStatus(HttpCodes.BAD_REQUEST);
|
||||
return;
|
||||
}
|
||||
if (documentFound.depositor_uid != customerId) {
|
||||
response.sendStatus(HttpCodes.UNAUTHORIZED);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
29
src/common/repositories/ContactRepository.ts
Normal file
29
src/common/repositories/ContactRepository.ts
Normal file
@ -0,0 +1,29 @@
|
||||
import Database from "@Common/databases/database";
|
||||
import BaseRepository from "@Repositories/BaseRepository";
|
||||
import { Service } from "typedi";
|
||||
import { Contacts, Customers } from "@prisma/client";
|
||||
|
||||
@Service()
|
||||
export default class ContactRepository extends BaseRepository {
|
||||
constructor(private database: Database) {
|
||||
super();
|
||||
}
|
||||
protected get model() {
|
||||
return this.database.getClient().contacts;
|
||||
}
|
||||
protected get instanceDb() {
|
||||
return this.database.getClient();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Find unique customer by email
|
||||
*/
|
||||
public async findOneByEmail(email: string): Promise<(Contacts & {customers: Customers | null}) | null> {
|
||||
return this.model.findUnique({
|
||||
where: {
|
||||
email: email,
|
||||
},
|
||||
include: { customers: true }
|
||||
});
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
import Database from "@Common/databases/database";
|
||||
import BaseRepository from "@Repositories/BaseRepository";
|
||||
import { Service } from "typedi";
|
||||
import { Contacts, Customers, ECivility, ECustomerStatus, Prisma } from "@prisma/client";
|
||||
import { Customers, ECivility, ECustomerStatus, Prisma } from "@prisma/client";
|
||||
import { Customer } from "le-coffre-resources/dist/SuperAdmin";
|
||||
|
||||
@Service()
|
||||
@ -28,7 +28,7 @@ export default class CustomersRepository extends BaseRepository {
|
||||
/**
|
||||
* @description : Create a customer
|
||||
*/
|
||||
public async create(customer: Customer): Promise<Customers & { contact: Contacts }> {
|
||||
public async create(customer: Customer): Promise<Customers> {
|
||||
const createArgs: Prisma.CustomersCreateArgs = {
|
||||
data: {
|
||||
status: ECustomerStatus.PENDING,
|
||||
@ -61,7 +61,7 @@ export default class CustomersRepository extends BaseRepository {
|
||||
/**
|
||||
* @description : Update data from a customer
|
||||
*/
|
||||
public async update(uid: string, customer: Customer): Promise<Customers & { contact: Contacts }> {
|
||||
public async update(uid: string, customer: Customer): Promise<Customers> {
|
||||
const updateArgs: Prisma.CustomersUpdateArgs = {
|
||||
where: {
|
||||
uid: uid,
|
||||
@ -102,4 +102,15 @@ export default class CustomersRepository extends BaseRepository {
|
||||
include: query,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Find unique customer
|
||||
*/
|
||||
public async findOneByContact(contactUid: string) {
|
||||
return this.model.findUnique({
|
||||
where: {
|
||||
contact_uid: contactUid,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
import Database from "@Common/databases/database";
|
||||
import BaseRepository from "@Repositories/BaseRepository";
|
||||
import { Service } from "typedi";
|
||||
import { DeedTypes, DocumentTypes, Prisma } from "@prisma/client";
|
||||
import { DeedTypes, Prisma } from "@prisma/client";
|
||||
import { DeedType } from "le-coffre-resources/dist/SuperAdmin";
|
||||
|
||||
@Service()
|
||||
@ -52,7 +52,7 @@ export default class DeedTypesRepository extends BaseRepository {
|
||||
/**
|
||||
* @description : Update data of a deed type
|
||||
*/
|
||||
public async update(uid: string, deedType: DeedType): Promise<DeedTypes & { document_types: DocumentTypes[] }> {
|
||||
public async update(uid: string, deedType: DeedType): Promise<DeedTypes> {
|
||||
const updateArgs: Prisma.DeedTypesUpdateArgs = {
|
||||
where: {
|
||||
uid: uid,
|
||||
|
@ -1,7 +1,7 @@
|
||||
import Database from "@Common/databases/database";
|
||||
import BaseRepository from "@Repositories/BaseRepository";
|
||||
import { Service } from "typedi";
|
||||
import { Deeds, DocumentTypes, Prisma } from "@prisma/client";
|
||||
import { Deeds, Prisma } from "@prisma/client";
|
||||
import { Deed } from "le-coffre-resources/dist/Notary";
|
||||
|
||||
@Service()
|
||||
@ -27,7 +27,7 @@ export default class DeedsRepository extends BaseRepository {
|
||||
/**
|
||||
* @description : Create a deed based on a deed type
|
||||
*/
|
||||
public async create(deed: Deed): Promise<Deeds & { document_types: DocumentTypes[] }> {
|
||||
public async create(deed: Deed): Promise<Deeds> {
|
||||
const createArgs: Prisma.DeedsCreateArgs = {
|
||||
data: {
|
||||
deed_type: {
|
||||
@ -59,7 +59,7 @@ export default class DeedsRepository extends BaseRepository {
|
||||
/**
|
||||
* @description : Update data of a deed type
|
||||
*/
|
||||
public async update(uid: string, deed: Deed): Promise<Deeds & { document_types: DocumentTypes[] }> {
|
||||
public async update(uid: string, deed: Deed): Promise<Deeds> {
|
||||
const updateArgs: Prisma.DeedsUpdateArgs = {
|
||||
where: {
|
||||
uid: uid,
|
||||
|
@ -1,7 +1,7 @@
|
||||
import Database from "@Common/databases/database";
|
||||
import BaseRepository from "@Repositories/BaseRepository";
|
||||
import { Service } from "typedi";
|
||||
import { DocumentTypes, Documents, EDocumentStatus, Prisma } from "@prisma/client";
|
||||
import { Documents, EDocumentStatus, Prisma } from "@prisma/client";
|
||||
import { Document } from "le-coffre-resources/dist/SuperAdmin";
|
||||
|
||||
@Service()
|
||||
@ -27,7 +27,7 @@ export default class DocumentsRepository extends BaseRepository {
|
||||
/**
|
||||
* @description : Create a document
|
||||
*/
|
||||
public async create(document: Document): Promise<Documents & { document_type: DocumentTypes }> {
|
||||
public async create(document: Document): Promise<Documents> {
|
||||
const createArgs: Prisma.DocumentsCreateArgs = {
|
||||
data: {
|
||||
folder: {
|
||||
@ -125,7 +125,7 @@ export default class DocumentsRepository extends BaseRepository {
|
||||
/**
|
||||
* @description : Find unique document
|
||||
*/
|
||||
public async findOneByUid(uid: string, query?: Prisma.DocumentsInclude) {
|
||||
public async findOneByUid(uid: string, query?: Prisma.DocumentsInclude): Promise<Documents | null> {
|
||||
return this.model.findUnique({
|
||||
where: {
|
||||
uid: uid,
|
||||
|
@ -1,7 +1,7 @@
|
||||
import Database from "@Common/databases/database";
|
||||
import BaseRepository from "@Repositories/BaseRepository";
|
||||
import { Service } from "typedi";
|
||||
import { Documents, Files, Prisma } from "@prisma/client";
|
||||
import { Files, Prisma } from "@prisma/client";
|
||||
import { File } from "le-coffre-resources/dist/SuperAdmin";
|
||||
|
||||
@Service()
|
||||
@ -27,7 +27,7 @@ export default class FilesRepository extends BaseRepository {
|
||||
/**
|
||||
* @description : Create a file linked to a document
|
||||
*/
|
||||
public async create(file: File, key: string): Promise<Files & { document: Documents }> {
|
||||
public async create(file: File, key: string): Promise<Files> {
|
||||
const createArgs: Prisma.FilesCreateArgs = {
|
||||
data: {
|
||||
document: {
|
||||
@ -48,7 +48,7 @@ export default class FilesRepository extends BaseRepository {
|
||||
/**
|
||||
* @description : Update data of a file
|
||||
*/
|
||||
public async update(uid: string, file: File, key: string): Promise<Files & { document: Documents }> {
|
||||
public async update(uid: string, file: File, key: string): Promise<Files> {
|
||||
const updateArgs: Prisma.FilesUpdateArgs = {
|
||||
where: {
|
||||
uid: uid,
|
||||
@ -67,7 +67,7 @@ export default class FilesRepository extends BaseRepository {
|
||||
/**
|
||||
* @description : Delete a file key and archive
|
||||
*/
|
||||
public async deleteKeyAndArchive(uid: string): Promise<Files & { document: Documents }> {
|
||||
public async deleteKeyAndArchive(uid: string): Promise<Files> {
|
||||
const updateArgs: Prisma.FilesUpdateArgs = {
|
||||
where: {
|
||||
uid: uid,
|
||||
@ -103,4 +103,16 @@ export default class FilesRepository extends BaseRepository {
|
||||
include: { document: { include: { folder: { include: { office: true } } } } },
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Find unique file with document
|
||||
*/
|
||||
public async findOneByUidWithDocument(uid: string) {
|
||||
return this.model.findUnique({
|
||||
where: {
|
||||
uid: uid,
|
||||
},
|
||||
include: { document: true },
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
import Database from "@Common/databases/database";
|
||||
import BaseRepository from "@Repositories/BaseRepository";
|
||||
import { Service } from "typedi";
|
||||
import { Customers, Documents, EFolderStatus, OfficeFolders, Prisma, Users } from "@prisma/client";
|
||||
import { EFolderStatus, OfficeFolders, Prisma } from "@prisma/client";
|
||||
import { OfficeFolder } from "le-coffre-resources/dist/SuperAdmin";
|
||||
|
||||
@Service()
|
||||
@ -27,7 +27,7 @@ export default class OfficeFoldersRepository extends BaseRepository {
|
||||
/**
|
||||
* @description : Create new office folder with stakeholders
|
||||
*/
|
||||
public async create(officeFolder: OfficeFolder): Promise<OfficeFolders & { stakeholders: Users[] }> {
|
||||
public async create(officeFolder: OfficeFolder): Promise<OfficeFolders> {
|
||||
const createArgs: Prisma.OfficeFoldersCreateArgs = {
|
||||
data: {
|
||||
folder_number: officeFolder.folder_number,
|
||||
@ -61,7 +61,7 @@ export default class OfficeFoldersRepository extends BaseRepository {
|
||||
public async update(
|
||||
officeFolderuid: string,
|
||||
officeFolder: OfficeFolder,
|
||||
): Promise<OfficeFolders & { stakeholders: Users[]; customers: Customers[]; documents: Documents[] }> {
|
||||
): Promise<OfficeFolders> {
|
||||
const updateArgs: Prisma.OfficeFoldersUpdateArgs = {
|
||||
where: {
|
||||
uid: officeFolderuid,
|
||||
|
@ -1,7 +1,7 @@
|
||||
import Database from "@Common/databases/database";
|
||||
import BaseRepository from "@Repositories/BaseRepository";
|
||||
import { Service } from "typedi";
|
||||
import { OfficeRoles, Prisma, Rules } from "@prisma/client";
|
||||
import { OfficeRoles, Prisma } from "@prisma/client";
|
||||
import { OfficeRole } from "le-coffre-resources/dist/SuperAdmin";
|
||||
|
||||
@Service()
|
||||
@ -27,7 +27,7 @@ export default class OfficeRolesRepository extends BaseRepository {
|
||||
/**
|
||||
* @description : Create new officeRole with rules
|
||||
*/
|
||||
public async create(officeRole: OfficeRole): Promise<OfficeRoles & { rules: Rules[] }> {
|
||||
public async create(officeRole: OfficeRole): Promise<OfficeRoles> {
|
||||
const createArgs: Prisma.OfficeRolesCreateArgs = {
|
||||
data: {
|
||||
name: officeRole.name,
|
||||
@ -50,7 +50,7 @@ export default class OfficeRolesRepository extends BaseRepository {
|
||||
/**
|
||||
* @description : Update data of a officeRole with rules
|
||||
*/
|
||||
public async update(officeRole: OfficeRole): Promise<OfficeRoles & { rules: Rules[] }> {
|
||||
public async update(officeRole: OfficeRole): Promise<OfficeRoles> {
|
||||
const updateArgs: Prisma.OfficeRolesUpdateArgs = {
|
||||
where: {
|
||||
uid: officeRole.uid,
|
||||
|
@ -1,7 +1,7 @@
|
||||
import Database from "@Common/databases/database";
|
||||
import BaseRepository from "@Repositories/BaseRepository";
|
||||
import { Service } from "typedi";
|
||||
import { Addresses, Contacts, ECivility, Offices, Prisma, Users } from "@prisma/client";
|
||||
import { ECivility, Prisma, Users } from "@prisma/client";
|
||||
import User from "le-coffre-resources/dist/SuperAdmin";
|
||||
|
||||
@Service()
|
||||
@ -87,17 +87,7 @@ export default class UsersRepository extends BaseRepository {
|
||||
/**
|
||||
* @description : Update data from a user
|
||||
*/
|
||||
public async update(
|
||||
uid: string,
|
||||
user: User,
|
||||
): Promise<
|
||||
Users & {
|
||||
contact: Contacts;
|
||||
office_membership: Offices & {
|
||||
address: Addresses;
|
||||
};
|
||||
}
|
||||
> {
|
||||
public async update(uid: string, user: User): Promise<Users> {
|
||||
const updateArgs: Prisma.UsersUpdateArgs = {
|
||||
where: {
|
||||
uid: uid,
|
||||
|
52
src/services/admin/CustomersService/CustomersService.ts
Normal file
52
src/services/admin/CustomersService/CustomersService.ts
Normal file
@ -0,0 +1,52 @@
|
||||
import { Customers, Prisma } from "@prisma/client";
|
||||
import CustomersRepository from "@Repositories/CustomersRepository";
|
||||
import BaseService from "@Services/BaseService";
|
||||
import { Customer } from "le-coffre-resources/dist/Admin";
|
||||
import { Service } from "typedi";
|
||||
|
||||
@Service()
|
||||
export default class CustomersService extends BaseService {
|
||||
constructor(private customerRepository: CustomersRepository) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get all Customers
|
||||
* @throws {Error} If Customers cannot be get
|
||||
*/
|
||||
public async get(query: Prisma.CustomersFindManyArgs): Promise<Customers[]> {
|
||||
return this.customerRepository.findMany(query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Create a new customer
|
||||
* @throws {Error} If customer cannot be created
|
||||
*/
|
||||
public async create(customerEntity: Customer): Promise<Customers> {
|
||||
return this.customerRepository.create(customerEntity);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Modify a customer
|
||||
* @throws {Error} If customer cannot be modified
|
||||
*/
|
||||
public async update(uid: string, customerEntity: Customer): Promise<Customers> {
|
||||
return this.customerRepository.update(uid, customerEntity);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get a customer by uid
|
||||
* @throws {Error} If customer cannot be get by uid
|
||||
*/
|
||||
public async getByUid(uid: string, query?: Prisma.CustomersInclude): Promise<Customers | null> {
|
||||
return this.customerRepository.findOneByUid(uid, query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get a customer by contact uid
|
||||
* @throws {Error} If customer cannot be get by contact uid
|
||||
*/
|
||||
public async getByContact(contactUid: string): Promise<Customers | null> {
|
||||
return this.customerRepository.findOneByContact(contactUid);
|
||||
}
|
||||
}
|
52
src/services/admin/DeedTypesService/DeedTypesService.ts
Normal file
52
src/services/admin/DeedTypesService/DeedTypesService.ts
Normal file
@ -0,0 +1,52 @@
|
||||
import { DeedTypes, Prisma } from "@prisma/client";
|
||||
import DeedTypesRepository from "@Repositories/DeedTypesRepository";
|
||||
import BaseService from "@Services/BaseService";
|
||||
import { DeedType } from "le-coffre-resources/dist/Admin";
|
||||
import { Service } from "typedi";
|
||||
|
||||
@Service()
|
||||
export default class DeedTypesService extends BaseService {
|
||||
constructor(private deedTypeRepository: DeedTypesRepository) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get all deed-types
|
||||
* @throws {Error} If deed-types cannot be get
|
||||
*/
|
||||
public async get(query: Prisma.DeedTypesFindManyArgs) {
|
||||
return this.deedTypeRepository.findMany(query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Create a new deed-type
|
||||
* @throws {Error} If deed-type cannot be created
|
||||
*/
|
||||
public async create(deedTypeEntity: DeedType): Promise<DeedTypes> {
|
||||
return this.deedTypeRepository.create(deedTypeEntity);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Modify a deed-type
|
||||
* @throws {Error} If deed-type cannot be modifified
|
||||
*/
|
||||
public async update(uid: string, deedTypeEntity: DeedType): Promise<DeedTypes> {
|
||||
return this.deedTypeRepository.update(uid, deedTypeEntity);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get a deedtype by uid
|
||||
* @throws {Error} If deed-type cannot be get by uid
|
||||
*/
|
||||
public async getByUid(uid: string, query?: Prisma.DeedTypesInclude): Promise<DeedTypes | null> {
|
||||
return this.deedTypeRepository.findOneByUid(uid, query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get a deedtype by uid
|
||||
* @throws {Error} If deed-type cannot be get by uid
|
||||
*/
|
||||
public async getByUidWithOffice(uid: string) {
|
||||
return this.deedTypeRepository.findOneByUidWithOffice(uid);
|
||||
}
|
||||
}
|
48
src/services/admin/DeedsService/DeedsService.ts
Normal file
48
src/services/admin/DeedsService/DeedsService.ts
Normal file
@ -0,0 +1,48 @@
|
||||
import { Deeds, Prisma } from "@prisma/client";
|
||||
import DeedsRepository from "@Repositories/DeedsRepository";
|
||||
import BaseService from "@Services/BaseService";
|
||||
import { Deed } from "le-coffre-resources/dist/Admin";
|
||||
import { Service } from "typedi";
|
||||
|
||||
@Service()
|
||||
export default class DeedsService extends BaseService {
|
||||
constructor(private deedRepository: DeedsRepository) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get all deeds
|
||||
* @throws {Error} If deeds cannot be get
|
||||
*/
|
||||
public async get(query: Prisma.DeedsFindManyArgs) {
|
||||
return this.deedRepository.findMany(query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Create a new deed with document types
|
||||
* @throws {Error} If deeds cannot be created
|
||||
*/
|
||||
public async create(deed: Deed): Promise<Deeds> {
|
||||
return this.deedRepository.create(deed);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Update data of a deed with document types
|
||||
* @throws {Error} If deeds cannot be updated with document types or one of them
|
||||
*/
|
||||
public async update(uid: string, deed: Deed): Promise<Deeds> {
|
||||
return this.deedRepository.update(uid, deed);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get a deed by uid
|
||||
* @throws {Error} If deed-type cannot be get by uid
|
||||
*/
|
||||
public async getByUid(uid: string, query?: Prisma.DeedsInclude) {
|
||||
return this.deedRepository.findOneByUid(uid, query);
|
||||
}
|
||||
|
||||
public async getOneByUidWithOffice(uid: string) {
|
||||
return this.deedRepository.findOneByUidWithOffice(uid);
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
import { DocumentTypes, Prisma } from "@prisma/client";
|
||||
import DocumentTypesRepository from "@Repositories/DocumentTypesRepository";
|
||||
import BaseService from "@Services/BaseService";
|
||||
import { DocumentType } from "le-coffre-resources/dist/Admin";
|
||||
import { Service } from "typedi";
|
||||
|
||||
@Service()
|
||||
export default class DocumentTypesService extends BaseService {
|
||||
constructor(private documentTypeRepository: DocumentTypesRepository) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get all document-types
|
||||
* @throws {Error} If document-types cannot be get
|
||||
*/
|
||||
public async get(query: Prisma.DocumentTypesFindManyArgs) {
|
||||
return this.documentTypeRepository.findMany(query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Create a new document-type
|
||||
* @throws {Error} If document-types cannot be created
|
||||
*/
|
||||
public async create(documentTypeEntity: DocumentType): Promise<DocumentTypes> {
|
||||
return this.documentTypeRepository.create(documentTypeEntity);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Modify a document-type
|
||||
* @throws {Error} If document-type cannot be modified
|
||||
*/
|
||||
public async update(uid: string, documentTypeEntity: DocumentType): Promise<DocumentTypes> {
|
||||
return this.documentTypeRepository.update(uid, documentTypeEntity);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get a document-type by uid
|
||||
* @throws {Error} If document-type is not found
|
||||
*/
|
||||
public async getByUid(uid: string, query?: Prisma.DocumentTypesInclude) {
|
||||
return this.documentTypeRepository.findOneByUid(uid, query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get a document-type by uid with relations
|
||||
* @throws {Error} If document-type is not found
|
||||
*/
|
||||
public async getByUidWithOffice(uid: string) {
|
||||
return this.documentTypeRepository.findOneByUidWithOffice(uid);
|
||||
}
|
||||
}
|
75
src/services/admin/DocumentsService/DocumentsService.ts
Normal file
75
src/services/admin/DocumentsService/DocumentsService.ts
Normal file
@ -0,0 +1,75 @@
|
||||
import { Documents, Prisma } from "@prisma/client";
|
||||
import { Document } from "le-coffre-resources/dist/Admin";
|
||||
import DocumentsRepository from "@Repositories/DocumentsRepository";
|
||||
import BaseService from "@Services/BaseService";
|
||||
import { Service } from "typedi";
|
||||
|
||||
@Service()
|
||||
export default class DocumentsService extends BaseService {
|
||||
constructor(private documentsRepository: DocumentsRepository) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get all documents
|
||||
* @throws {Error} If documents cannot be get
|
||||
*/
|
||||
public async get(query: Prisma.DocumentsFindManyArgs) {
|
||||
return this.documentsRepository.findMany(query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Create a new document
|
||||
* @throws {Error} If document cannot be created
|
||||
*/
|
||||
public async create(document: Document): Promise<Documents> {
|
||||
return this.documentsRepository.create(document);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Create new documents
|
||||
* @throws {Error} If documents or one of them cannot be created
|
||||
*/
|
||||
public async createMany(documents: Document[]): Promise<Documents[]> {
|
||||
return this.documentsRepository.createMany(documents);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Modify a document
|
||||
* @throws {Error} If document cannot be modified
|
||||
*/
|
||||
public async update(uid: string, document: Partial<Document>, refused_reason?: string): Promise<Documents> {
|
||||
return this.documentsRepository.update(uid, document, refused_reason);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Delete a document
|
||||
* @throws {Error} If document cannot be deleted
|
||||
*/
|
||||
public async delete(uid: string): Promise<Documents> {
|
||||
const documentEntity = await this.documentsRepository.findOneByUid(uid, { files: true });
|
||||
if (!documentEntity) throw new Error("document not found");
|
||||
const document = Document.hydrate<Document>(documentEntity, { strategy: "excludeAll" });
|
||||
|
||||
if (document.files && document.files.length !== 0) {
|
||||
throw new Error("Can't delete a document with file");
|
||||
}
|
||||
return this.documentsRepository.delete(uid);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get a document by uid
|
||||
* @throws {Error} If document cannot be get by uid
|
||||
*/
|
||||
public async getByUid(uid: string, query?: Prisma.DocumentsInclude): Promise<Documents | null> {
|
||||
return this.documentsRepository.findOneByUid(uid, query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get a document by uid
|
||||
* @throws {Error} If document cannot be get by uid
|
||||
*/
|
||||
public async getByUidWithOffice(uid: string) {
|
||||
return this.documentsRepository.findOneByUidWithOffice(uid);
|
||||
}
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
import { OfficeFolders } from ".prisma/client";
|
||||
import OfficeFoldersRepository from "@Repositories/OfficeFoldersRepository";
|
||||
import BaseService from "@Services/BaseService";
|
||||
import { OfficeFolder } from "le-coffre-resources/dist/Admin";
|
||||
import { Service } from "typedi";
|
||||
import DeedTypesService from "../DeedTypesService/DeedTypesService";
|
||||
import DeedsRepository from "@Repositories/DeedsRepository";
|
||||
import { Prisma } from "@prisma/client";
|
||||
|
||||
@Service()
|
||||
export default class OfficeFoldersService extends BaseService {
|
||||
constructor(
|
||||
private officeFoldersRepository: OfficeFoldersRepository,
|
||||
private deedTypeService: DeedTypesService,
|
||||
private deedRepository: DeedsRepository,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get all folders
|
||||
* @throws {Error} If folders cannot be get
|
||||
*/
|
||||
public async get(query: Prisma.OfficeFoldersFindManyArgs) {
|
||||
return this.officeFoldersRepository.findMany(query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Create a new folder
|
||||
* @throws {Error} If folder cannot be created
|
||||
*/
|
||||
public async create(officeFolderEntity: OfficeFolder): Promise<OfficeFolders> {
|
||||
const deedType = await this.deedTypeService.getByUid(officeFolderEntity.deed!.deed_type!.uid!);
|
||||
if (!deedType) throw new Error("deed type not found");
|
||||
if (deedType.archived_at) throw new Error("deed type is archived");
|
||||
const deed = await this.deedRepository.create(officeFolderEntity.deed!);
|
||||
officeFolderEntity.deed!.uid = deed.uid;
|
||||
return this.officeFoldersRepository.create(officeFolderEntity);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Modify a folder
|
||||
* @throws {Error} If folder cannot be modified
|
||||
*/
|
||||
public async update(officeFolderuid: string, officeFolderEntity: OfficeFolder): Promise<OfficeFolders> {
|
||||
return this.officeFoldersRepository.update(officeFolderuid, officeFolderEntity);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get a folder by uid
|
||||
* @throws {Error} If folder cannot be get by uid
|
||||
*/
|
||||
public async getByUid(uid: string, query?: Prisma.OfficeFoldersInclude) {
|
||||
return this.officeFoldersRepository.findOneByUid(uid, query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get a folder by uid
|
||||
* @throws {Error} If folder cannot be get by uid
|
||||
*/
|
||||
public async getByUidWithOffice(uid: string) {
|
||||
return this.officeFoldersRepository.findOneByUidWithOffice(uid);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Delete a folder
|
||||
* @throws {Error} If document cannot be deleted
|
||||
*/
|
||||
public async delete(uid: string): Promise<OfficeFolders> {
|
||||
const officeFolderEntity = await this.officeFoldersRepository.findOneByUid(uid, { customers: true });
|
||||
if (!officeFolderEntity) throw new Error("office folder not found");
|
||||
const officeFolder = OfficeFolder.hydrate<OfficeFolder>(officeFolderEntity, { strategy: "excludeAll" });
|
||||
|
||||
if (officeFolder.customers?.length) {
|
||||
throw new Error("This folder is used by customers");
|
||||
}
|
||||
return this.officeFoldersRepository.delete(uid);
|
||||
}
|
||||
}
|
52
src/services/admin/OfficeRolesService/OfficeRolesService.ts
Normal file
52
src/services/admin/OfficeRolesService/OfficeRolesService.ts
Normal file
@ -0,0 +1,52 @@
|
||||
import BaseService from "@Services/BaseService";
|
||||
import { Service } from "typedi";
|
||||
import OfficeRolesRepository from "@Repositories/OfficeRolesRepository";
|
||||
import { OfficeRole } from "le-coffre-resources/dist/Admin";
|
||||
import { Prisma, OfficeRoles } from "@prisma/client";
|
||||
|
||||
@Service()
|
||||
export default class OfficeRolesService extends BaseService {
|
||||
constructor(private officeRoleRepository: OfficeRolesRepository) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get all officeRoles
|
||||
* @throws {Error} If officeRoles cannot be get
|
||||
*/
|
||||
public get(query: Prisma.OfficeRolesFindManyArgs) {
|
||||
return this.officeRoleRepository.findMany(query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Create a officeRole
|
||||
* @throws {Error} If officeRole couldn't be created
|
||||
*/
|
||||
public create(officeRoleEntity: OfficeRole): Promise<OfficeRoles> {
|
||||
return this.officeRoleRepository.create(officeRoleEntity);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Modify a officeRole
|
||||
* @throws {Error} If officeRole modification failed
|
||||
*/
|
||||
public update(officeRoleEntity: OfficeRole): Promise<OfficeRoles> {
|
||||
return this.officeRoleRepository.update(officeRoleEntity);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get a officeRole by uid
|
||||
* @throws {Error} If officeRole cannot be get by uid
|
||||
*/
|
||||
public getByUid(uid: string, query?: Prisma.OfficeRolesInclude) {
|
||||
return this.officeRoleRepository.findOneByUid(uid, query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get a officeRole by uid
|
||||
* @throws {Error} If officeRole cannot be get by uid
|
||||
*/
|
||||
public getByUidWithOffice(uid: string) {
|
||||
return this.officeRoleRepository.findOneByUidWithOffice(uid);
|
||||
}
|
||||
}
|
27
src/services/admin/OfficesService/OfficesService.ts
Normal file
27
src/services/admin/OfficesService/OfficesService.ts
Normal file
@ -0,0 +1,27 @@
|
||||
import { Prisma } from "@prisma/client";
|
||||
import OfficesRepository from "@Repositories/OfficesRepository";
|
||||
import BaseService from "@Services/BaseService";
|
||||
import { Service } from "typedi";
|
||||
|
||||
@Service()
|
||||
export default class OfficesService extends BaseService {
|
||||
constructor(private officeRepository: OfficesRepository) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get all offices
|
||||
* @throws {Error} If offices cannot be get
|
||||
*/
|
||||
public async get(query: Prisma.OfficesFindManyArgs) {
|
||||
return this.officeRepository.findMany(query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get a office by uid
|
||||
* @throws {Error} If office cannot be get
|
||||
*/
|
||||
public async getByUid(uid: string, query?: Prisma.OfficesInclude) {
|
||||
return this.officeRepository.findOneByUid(uid, query);
|
||||
}
|
||||
}
|
45
src/services/admin/RolesService/RolesService.ts
Normal file
45
src/services/admin/RolesService/RolesService.ts
Normal file
@ -0,0 +1,45 @@
|
||||
import BaseService from "@Services/BaseService";
|
||||
import "reflect-metadata";
|
||||
import { Service } from "typedi";
|
||||
import RolesRepository from "@Repositories/RolesRepository";
|
||||
import { Role } from "le-coffre-resources/dist/Admin";
|
||||
import { Prisma, Roles } from "@prisma/client";
|
||||
|
||||
@Service()
|
||||
export default class RolesService extends BaseService {
|
||||
constructor(private roleRepository: RolesRepository) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get all roles
|
||||
* @throws {Error} If roles cannot be get
|
||||
*/
|
||||
public get(query: Prisma.RolesFindManyArgs) {
|
||||
return this.roleRepository.findMany(query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Create a role
|
||||
* @throws {Error} If role couldn't be created
|
||||
*/
|
||||
public create(roleEntity: Role): Promise<Roles> {
|
||||
return this.roleRepository.create(roleEntity);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Modify a role
|
||||
* @throws {Error} If role modification failed
|
||||
*/
|
||||
public update(roleEntity: Role): Promise<Roles> {
|
||||
return this.roleRepository.update(roleEntity);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get a role by uid
|
||||
* @throws {Error} If role cannot be get by uid
|
||||
*/
|
||||
public getByUid(uid: string, query?: Prisma.RolesInclude) {
|
||||
return this.roleRepository.findOneByUid(uid, query);
|
||||
}
|
||||
}
|
45
src/services/admin/RulesService/RulesService.ts
Normal file
45
src/services/admin/RulesService/RulesService.ts
Normal file
@ -0,0 +1,45 @@
|
||||
import BaseService from "@Services/BaseService";
|
||||
import "reflect-metadata";
|
||||
import { Service } from "typedi";
|
||||
import RulesRepository from "@Repositories/RulesRepository";
|
||||
import { Rule } from "le-coffre-resources/dist/Admin";
|
||||
import { Prisma, Rules } from "@prisma/client";
|
||||
|
||||
@Service()
|
||||
export default class RulesService extends BaseService {
|
||||
constructor(private ruleRepository: RulesRepository) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get all rules
|
||||
* @throws {Error} If rules cannot be get
|
||||
*/
|
||||
public get(query: Prisma.RulesFindManyArgs) {
|
||||
return this.ruleRepository.findMany(query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Create a rule
|
||||
* @throws {Error} If rule couldn't be created
|
||||
*/
|
||||
public create(ruleEntity: Rule): Promise<Rules> {
|
||||
return this.ruleRepository.create(ruleEntity);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Modify a rule
|
||||
* @throws {Error} If rule modification failed
|
||||
*/
|
||||
public update(ruleEntity: Rule): Promise<Rules> {
|
||||
return this.ruleRepository.update(ruleEntity);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get a rule by uid
|
||||
* @throws {Error} If rule cannot be get by uid
|
||||
*/
|
||||
public getByUid(uid: string, query?: Prisma.RulesInclude) {
|
||||
return this.ruleRepository.findOneByUid(uid, query);
|
||||
}
|
||||
}
|
61
src/services/admin/UsersService/UsersService.ts
Normal file
61
src/services/admin/UsersService/UsersService.ts
Normal file
@ -0,0 +1,61 @@
|
||||
import BaseService from "@Services/BaseService";
|
||||
import "reflect-metadata";
|
||||
import { Service } from "typedi";
|
||||
import UsersRepository from "@Repositories/UsersRepository";
|
||||
import User from "le-coffre-resources/dist/Admin";
|
||||
import { Prisma, Users } from "@prisma/client";
|
||||
|
||||
@Service()
|
||||
export default class UsersService extends BaseService {
|
||||
constructor(private userRepository: UsersRepository) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get all users
|
||||
* @throws {Error} If users cannot be get
|
||||
*/
|
||||
public get(query: Prisma.UsersFindManyArgs) {
|
||||
return this.userRepository.findMany(query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Create a user
|
||||
* @throws {Error} If user couldn't be created
|
||||
*/
|
||||
public create(userEntity: User): Promise<Users> {
|
||||
return this.userRepository.create(userEntity);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Modify a user
|
||||
* @throws {Error} If user modification failed
|
||||
*/
|
||||
public update(uid: string, userEntity: User): Promise<Users> {
|
||||
return this.userRepository.update(uid, userEntity);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get a user by uid
|
||||
* @throws {Error} If user cannot be get by uid
|
||||
*/
|
||||
public getByUid(uid: string, query?: Prisma.UsersInclude) {
|
||||
return this.userRepository.findOneByUid(uid, query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get a user by uid with office
|
||||
* @throws {Error} If user cannot be get by uid
|
||||
*/
|
||||
public getByUidWithOffice(uid: string) {
|
||||
return this.userRepository.findOneByUidWithOffice(uid);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get a user by uid
|
||||
* @throws {Error} If user cannot be get by uid
|
||||
*/
|
||||
public getByProvider(providerName: string, id: string) {
|
||||
return this.userRepository.findOneByProvider(providerName, id);
|
||||
}
|
||||
}
|
@ -3,12 +3,21 @@ import BaseService from "@Services/BaseService";
|
||||
import { BackendVariables } from "@Common/config/variables/Variables";
|
||||
import { Service } from "typedi";
|
||||
import UsersService from "@Services/super-admin/UsersService/UsersService";
|
||||
import CustomersService from "@Services/super-admin/CustomersService/CustomersService";
|
||||
import ContactService from "../ContactService";
|
||||
import { ECustomerStatus } from "@prisma/client";
|
||||
|
||||
enum PROVIDER_OPENID {
|
||||
idNot = "idNot",
|
||||
}
|
||||
|
||||
interface IJwtPayload {
|
||||
interface ICustomerJwtPayload {
|
||||
customerId: string;
|
||||
email: string;
|
||||
}
|
||||
|
||||
|
||||
interface IUserJwtPayload {
|
||||
userId: string;
|
||||
openId: {
|
||||
providerName: PROVIDER_OPENID;
|
||||
@ -21,11 +30,27 @@ interface IJwtPayload {
|
||||
|
||||
@Service()
|
||||
export default class AuthService extends BaseService {
|
||||
constructor(protected variables: BackendVariables, private userService: UsersService) {
|
||||
constructor(protected variables: BackendVariables, private userService: UsersService, private customerService: CustomersService, private contactService: ContactService) {
|
||||
super();
|
||||
}
|
||||
|
||||
public async getUserJwtPayload(id: string, providerName: PROVIDER_OPENID = PROVIDER_OPENID.idNot): Promise<IJwtPayload | null> {
|
||||
public async getCustomerJwtPayload(email:string): Promise<ICustomerJwtPayload | null> {
|
||||
const contact = await this.contactService.getByEmail(email);
|
||||
|
||||
if (!contact) return null;
|
||||
|
||||
if(contact.customers?.status === ECustomerStatus["PENDING"]) {
|
||||
contact.customers.status = ECustomerStatus["VALIDATED"];
|
||||
this.customerService.update(contact.customers.uid, contact.customers);
|
||||
}
|
||||
|
||||
return {
|
||||
customerId: contact.customers!.uid,
|
||||
email: contact.email,
|
||||
};
|
||||
}
|
||||
|
||||
public async getUserJwtPayload(id: string, providerName: PROVIDER_OPENID = PROVIDER_OPENID.idNot): Promise<IUserJwtPayload | null> {
|
||||
const user = await this.userService.getByProvider(providerName, id);
|
||||
|
||||
if (!user) return null;
|
||||
|
19
src/services/common/ContactService.ts
Normal file
19
src/services/common/ContactService.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import { Contacts, Customers } from "@prisma/client";
|
||||
import BaseService from "@Services/BaseService";
|
||||
import { Service } from "typedi";
|
||||
import ContactRepository from "@Repositories/ContactRepository";
|
||||
|
||||
@Service()
|
||||
export default class DocumentsService extends BaseService {
|
||||
constructor(private contactRepository: ContactRepository) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get a contact by email
|
||||
* @throws {Error} If contact cannot be get by email
|
||||
*/
|
||||
public async getByEmail(email: string): Promise<(Contacts & {customers: Customers | null}) | null> {
|
||||
return this.contactRepository.findOneByEmail(email);
|
||||
}
|
||||
}
|
@ -45,6 +45,14 @@ export default class FilesService extends BaseService {
|
||||
return this.filesRepository.findOneByUidWithOffice(uid);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get a file by uid with document
|
||||
* @throws {Error} If project cannot be created
|
||||
*/
|
||||
public async getByUidWithDocument(uid: string) {
|
||||
return this.filesRepository.findOneByUidWithDocument(uid);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : view a file
|
||||
* @throws {Error} If file cannot be deleted
|
||||
|
52
src/services/notary/CustomersService/CustomersService.ts
Normal file
52
src/services/notary/CustomersService/CustomersService.ts
Normal file
@ -0,0 +1,52 @@
|
||||
import { Customers, Prisma } from "@prisma/client";
|
||||
import CustomersRepository from "@Repositories/CustomersRepository";
|
||||
import BaseService from "@Services/BaseService";
|
||||
import { Customer } from "le-coffre-resources/dist/Notary";
|
||||
import { Service } from "typedi";
|
||||
|
||||
@Service()
|
||||
export default class CustomersService extends BaseService {
|
||||
constructor(private customerRepository: CustomersRepository) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get all Customers
|
||||
* @throws {Error} If Customers cannot be get
|
||||
*/
|
||||
public async get(query: Prisma.CustomersFindManyArgs): Promise<Customers[]> {
|
||||
return this.customerRepository.findMany(query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Create a new customer
|
||||
* @throws {Error} If customer cannot be created
|
||||
*/
|
||||
public async create(customerEntity: Customer): Promise<Customers> {
|
||||
return this.customerRepository.create(customerEntity);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Modify a customer
|
||||
* @throws {Error} If customer cannot be modified
|
||||
*/
|
||||
public async update(uid: string, customerEntity: Customer): Promise<Customers> {
|
||||
return this.customerRepository.update(uid, customerEntity);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get a customer by uid
|
||||
* @throws {Error} If customer cannot be get by uid
|
||||
*/
|
||||
public async getByUid(uid: string, query?: Prisma.CustomersInclude): Promise<Customers | null> {
|
||||
return this.customerRepository.findOneByUid(uid, query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get a customer by contact uid
|
||||
* @throws {Error} If customer cannot be get by contact uid
|
||||
*/
|
||||
public async getByContact(contactUid: string): Promise<Customers | null> {
|
||||
return this.customerRepository.findOneByContact(contactUid);
|
||||
}
|
||||
}
|
52
src/services/notary/DeedTypesService/DeedTypesService.ts
Normal file
52
src/services/notary/DeedTypesService/DeedTypesService.ts
Normal file
@ -0,0 +1,52 @@
|
||||
import { DeedTypes, Prisma } from "@prisma/client";
|
||||
import DeedTypesRepository from "@Repositories/DeedTypesRepository";
|
||||
import BaseService from "@Services/BaseService";
|
||||
import { DeedType } from "le-coffre-resources/dist/Notary";
|
||||
import { Service } from "typedi";
|
||||
|
||||
@Service()
|
||||
export default class DeedTypesService extends BaseService {
|
||||
constructor(private deedTypeRepository: DeedTypesRepository) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get all deed-types
|
||||
* @throws {Error} If deed-types cannot be get
|
||||
*/
|
||||
public async get(query: Prisma.DeedTypesFindManyArgs) {
|
||||
return this.deedTypeRepository.findMany(query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Create a new deed-type
|
||||
* @throws {Error} If deed-type cannot be created
|
||||
*/
|
||||
public async create(deedTypeEntity: DeedType): Promise<DeedTypes> {
|
||||
return this.deedTypeRepository.create(deedTypeEntity);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Modify a deed-type
|
||||
* @throws {Error} If deed-type cannot be modifified
|
||||
*/
|
||||
public async update(uid: string, deedTypeEntity: DeedType): Promise<DeedTypes> {
|
||||
return this.deedTypeRepository.update(uid, deedTypeEntity);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get a deedtype by uid
|
||||
* @throws {Error} If deed-type cannot be get by uid
|
||||
*/
|
||||
public async getByUid(uid: string, query?: Prisma.DeedTypesInclude): Promise<DeedTypes | null> {
|
||||
return this.deedTypeRepository.findOneByUid(uid, query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get a deedtype by uid
|
||||
* @throws {Error} If deed-type cannot be get by uid
|
||||
*/
|
||||
public async getByUidWithOffice(uid: string) {
|
||||
return this.deedTypeRepository.findOneByUidWithOffice(uid);
|
||||
}
|
||||
}
|
48
src/services/notary/DeedsService/DeedsService.ts
Normal file
48
src/services/notary/DeedsService/DeedsService.ts
Normal file
@ -0,0 +1,48 @@
|
||||
import { Deeds, Prisma } from "@prisma/client";
|
||||
import DeedsRepository from "@Repositories/DeedsRepository";
|
||||
import BaseService from "@Services/BaseService";
|
||||
import { Deed } from "le-coffre-resources/dist/Notary";
|
||||
import { Service } from "typedi";
|
||||
|
||||
@Service()
|
||||
export default class DeedsService extends BaseService {
|
||||
constructor(private deedRepository: DeedsRepository) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get all deeds
|
||||
* @throws {Error} If deeds cannot be get
|
||||
*/
|
||||
public async get(query: Prisma.DeedsFindManyArgs) {
|
||||
return this.deedRepository.findMany(query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Create a new deed with document types
|
||||
* @throws {Error} If deeds cannot be created
|
||||
*/
|
||||
public async create(deed: Deed): Promise<Deeds> {
|
||||
return this.deedRepository.create(deed);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Update data of a deed with document types
|
||||
* @throws {Error} If deeds cannot be updated with document types or one of them
|
||||
*/
|
||||
public async update(uid: string, deed: Deed): Promise<Deeds> {
|
||||
return this.deedRepository.update(uid, deed);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get a deed by uid
|
||||
* @throws {Error} If deed-type cannot be get by uid
|
||||
*/
|
||||
public async getByUid(uid: string, query?: Prisma.DeedsInclude) {
|
||||
return this.deedRepository.findOneByUid(uid, query);
|
||||
}
|
||||
|
||||
public async getOneByUidWithOffice(uid: string) {
|
||||
return this.deedRepository.findOneByUidWithOffice(uid);
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
import { DocumentTypes, Prisma } from "@prisma/client";
|
||||
import DocumentTypesRepository from "@Repositories/DocumentTypesRepository";
|
||||
import BaseService from "@Services/BaseService";
|
||||
import { DocumentType } from "le-coffre-resources/dist/Notary";
|
||||
import { Service } from "typedi";
|
||||
|
||||
@Service()
|
||||
export default class DocumentTypesService extends BaseService {
|
||||
constructor(private documentTypeRepository: DocumentTypesRepository) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get all document-types
|
||||
* @throws {Error} If document-types cannot be get
|
||||
*/
|
||||
public async get(query: Prisma.DocumentTypesFindManyArgs) {
|
||||
return this.documentTypeRepository.findMany(query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Create a new document-type
|
||||
* @throws {Error} If document-types cannot be created
|
||||
*/
|
||||
public async create(documentTypeEntity: DocumentType): Promise<DocumentTypes> {
|
||||
return this.documentTypeRepository.create(documentTypeEntity);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Modify a document-type
|
||||
* @throws {Error} If document-type cannot be modified
|
||||
*/
|
||||
public async update(uid: string, documentTypeEntity: DocumentType): Promise<DocumentTypes> {
|
||||
return this.documentTypeRepository.update(uid, documentTypeEntity);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get a document-type by uid
|
||||
* @throws {Error} If document-type is not found
|
||||
*/
|
||||
public async getByUid(uid: string, query?: Prisma.DocumentTypesInclude) {
|
||||
return this.documentTypeRepository.findOneByUid(uid, query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get a document-type by uid with relations
|
||||
* @throws {Error} If document-type is not found
|
||||
*/
|
||||
public async getByUidWithOffice(uid: string) {
|
||||
return this.documentTypeRepository.findOneByUidWithOffice(uid);
|
||||
}
|
||||
}
|
75
src/services/notary/DocumentsService/DocumentsService.ts
Normal file
75
src/services/notary/DocumentsService/DocumentsService.ts
Normal file
@ -0,0 +1,75 @@
|
||||
import { Documents, Prisma } from "@prisma/client";
|
||||
import { Document } from "le-coffre-resources/dist/Notary";
|
||||
import DocumentsRepository from "@Repositories/DocumentsRepository";
|
||||
import BaseService from "@Services/BaseService";
|
||||
import { Service } from "typedi";
|
||||
|
||||
@Service()
|
||||
export default class DocumentsService extends BaseService {
|
||||
constructor(private documentsRepository: DocumentsRepository) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get all documents
|
||||
* @throws {Error} If documents cannot be get
|
||||
*/
|
||||
public async get(query: Prisma.DocumentsFindManyArgs) {
|
||||
return this.documentsRepository.findMany(query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Create a new document
|
||||
* @throws {Error} If document cannot be created
|
||||
*/
|
||||
public async create(document: Document): Promise<Documents> {
|
||||
return this.documentsRepository.create(document);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Create new documents
|
||||
* @throws {Error} If documents or one of them cannot be created
|
||||
*/
|
||||
public async createMany(documents: Document[]): Promise<Documents[]> {
|
||||
return this.documentsRepository.createMany(documents);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Modify a document
|
||||
* @throws {Error} If document cannot be modified
|
||||
*/
|
||||
public async update(uid: string, document: Partial<Document>, refused_reason?: string): Promise<Documents> {
|
||||
return this.documentsRepository.update(uid, document, refused_reason);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Delete a document
|
||||
* @throws {Error} If document cannot be deleted
|
||||
*/
|
||||
public async delete(uid: string): Promise<Documents> {
|
||||
const documentEntity = await this.documentsRepository.findOneByUid(uid, { files: true });
|
||||
if (!documentEntity) throw new Error("document not found");
|
||||
const document = Document.hydrate<Document>(documentEntity, { strategy: "excludeAll" });
|
||||
|
||||
if (document.files && document.files.length !== 0) {
|
||||
throw new Error("Can't delete a document with file");
|
||||
}
|
||||
return this.documentsRepository.delete(uid);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get a document by uid
|
||||
* @throws {Error} If document cannot be get by uid
|
||||
*/
|
||||
public async getByUid(uid: string, query?: Prisma.DocumentsInclude): Promise<Documents | null> {
|
||||
return this.documentsRepository.findOneByUid(uid, query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get a document by uid
|
||||
* @throws {Error} If document cannot be get by uid
|
||||
*/
|
||||
public async getByUidWithOffice(uid: string) {
|
||||
return this.documentsRepository.findOneByUidWithOffice(uid);
|
||||
}
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
import { OfficeFolders } from ".prisma/client";
|
||||
import OfficeFoldersRepository from "@Repositories/OfficeFoldersRepository";
|
||||
import BaseService from "@Services/BaseService";
|
||||
import { OfficeFolder } from "le-coffre-resources/dist/Notary";
|
||||
import { Service } from "typedi";
|
||||
import DeedTypesService from "../DeedTypesService/DeedTypesService";
|
||||
import DeedsRepository from "@Repositories/DeedsRepository";
|
||||
import { Prisma } from "@prisma/client";
|
||||
|
||||
@Service()
|
||||
export default class OfficeFoldersService extends BaseService {
|
||||
constructor(
|
||||
private officeFoldersRepository: OfficeFoldersRepository,
|
||||
private deedTypeService: DeedTypesService,
|
||||
private deedRepository: DeedsRepository,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get all folders
|
||||
* @throws {Error} If folders cannot be get
|
||||
*/
|
||||
public async get(query: Prisma.OfficeFoldersFindManyArgs) {
|
||||
return this.officeFoldersRepository.findMany(query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Create a new folder
|
||||
* @throws {Error} If folder cannot be created
|
||||
*/
|
||||
public async create(officeFolderEntity: OfficeFolder): Promise<OfficeFolders> {
|
||||
const deedType = await this.deedTypeService.getByUid(officeFolderEntity.deed!.deed_type!.uid!);
|
||||
if (!deedType) throw new Error("deed type not found");
|
||||
if (deedType.archived_at) throw new Error("deed type is archived");
|
||||
const deed = await this.deedRepository.create(officeFolderEntity.deed!);
|
||||
officeFolderEntity.deed!.uid = deed.uid;
|
||||
return this.officeFoldersRepository.create(officeFolderEntity);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Modify a folder
|
||||
* @throws {Error} If folder cannot be modified
|
||||
*/
|
||||
public async update(officeFolderuid: string, officeFolderEntity: OfficeFolder): Promise<OfficeFolders> {
|
||||
return this.officeFoldersRepository.update(officeFolderuid, officeFolderEntity);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get a folder by uid
|
||||
* @throws {Error} If folder cannot be get by uid
|
||||
*/
|
||||
public async getByUid(uid: string, query?: Prisma.OfficeFoldersInclude) {
|
||||
return this.officeFoldersRepository.findOneByUid(uid, query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get a folder by uid
|
||||
* @throws {Error} If folder cannot be get by uid
|
||||
*/
|
||||
public async getByUidWithOffice(uid: string) {
|
||||
return this.officeFoldersRepository.findOneByUidWithOffice(uid);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Delete a folder
|
||||
* @throws {Error} If document cannot be deleted
|
||||
*/
|
||||
public async delete(uid: string): Promise<OfficeFolders> {
|
||||
const officeFolderEntity = await this.officeFoldersRepository.findOneByUid(uid, { customers: true });
|
||||
if (!officeFolderEntity) throw new Error("office folder not found");
|
||||
const officeFolder = OfficeFolder.hydrate<OfficeFolder>(officeFolderEntity, { strategy: "excludeAll" });
|
||||
|
||||
if (officeFolder.customers?.length) {
|
||||
throw new Error("This folder is used by customers");
|
||||
}
|
||||
return this.officeFoldersRepository.delete(uid);
|
||||
}
|
||||
}
|
35
src/services/notary/OfficeRolesService/OfficeRolesService.ts
Normal file
35
src/services/notary/OfficeRolesService/OfficeRolesService.ts
Normal file
@ -0,0 +1,35 @@
|
||||
import BaseService from "@Services/BaseService";
|
||||
import { Service } from "typedi";
|
||||
import OfficeRolesRepository from "@Repositories/OfficeRolesRepository";
|
||||
import { Prisma } from "@prisma/client";
|
||||
|
||||
@Service()
|
||||
export default class OfficeRolesService extends BaseService {
|
||||
constructor(private officeRoleRepository: OfficeRolesRepository) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get all officeRoles
|
||||
* @throws {Error} If officeRoles cannot be get
|
||||
*/
|
||||
public get(query: Prisma.OfficeRolesFindManyArgs) {
|
||||
return this.officeRoleRepository.findMany(query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get a officeRole by uid
|
||||
* @throws {Error} If officeRole cannot be get by uid
|
||||
*/
|
||||
public getByUid(uid: string, query?: Prisma.OfficeRolesInclude) {
|
||||
return this.officeRoleRepository.findOneByUid(uid, query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get a officeRole by uid
|
||||
* @throws {Error} If officeRole cannot be get by uid
|
||||
*/
|
||||
public getByUidWithOffice(uid: string) {
|
||||
return this.officeRoleRepository.findOneByUidWithOffice(uid);
|
||||
}
|
||||
}
|
27
src/services/notary/OfficesService/OfficesService.ts
Normal file
27
src/services/notary/OfficesService/OfficesService.ts
Normal file
@ -0,0 +1,27 @@
|
||||
import { Prisma } from "@prisma/client";
|
||||
import OfficesRepository from "@Repositories/OfficesRepository";
|
||||
import BaseService from "@Services/BaseService";
|
||||
import { Service } from "typedi";
|
||||
|
||||
@Service()
|
||||
export default class OfficesService extends BaseService {
|
||||
constructor(private officeRepository: OfficesRepository) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get all offices
|
||||
* @throws {Error} If offices cannot be get
|
||||
*/
|
||||
public async get(query: Prisma.OfficesFindManyArgs) {
|
||||
return this.officeRepository.findMany(query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get a office by uid
|
||||
* @throws {Error} If office cannot be get
|
||||
*/
|
||||
public async getByUid(uid: string, query?: Prisma.OfficesInclude) {
|
||||
return this.officeRepository.findOneByUid(uid, query);
|
||||
}
|
||||
}
|
28
src/services/notary/RolesService/RolesService.ts
Normal file
28
src/services/notary/RolesService/RolesService.ts
Normal file
@ -0,0 +1,28 @@
|
||||
import BaseService from "@Services/BaseService";
|
||||
import "reflect-metadata";
|
||||
import { Service } from "typedi";
|
||||
import RolesRepository from "@Repositories/RolesRepository";
|
||||
import { Prisma } from "@prisma/client";
|
||||
|
||||
@Service()
|
||||
export default class RolesService extends BaseService {
|
||||
constructor(private roleRepository: RolesRepository) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get all roles
|
||||
* @throws {Error} If roles cannot be get
|
||||
*/
|
||||
public get(query: Prisma.RolesFindManyArgs) {
|
||||
return this.roleRepository.findMany(query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get a role by uid
|
||||
* @throws {Error} If role cannot be get by uid
|
||||
*/
|
||||
public getByUid(uid: string, query?: Prisma.RolesInclude) {
|
||||
return this.roleRepository.findOneByUid(uid, query);
|
||||
}
|
||||
}
|
28
src/services/notary/RulesService/RulesService.ts
Normal file
28
src/services/notary/RulesService/RulesService.ts
Normal file
@ -0,0 +1,28 @@
|
||||
import BaseService from "@Services/BaseService";
|
||||
import "reflect-metadata";
|
||||
import { Service } from "typedi";
|
||||
import RulesRepository from "@Repositories/RulesRepository";
|
||||
import { Prisma } from "@prisma/client";
|
||||
|
||||
@Service()
|
||||
export default class RulesService extends BaseService {
|
||||
constructor(private ruleRepository: RulesRepository) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get all rules
|
||||
* @throws {Error} If rules cannot be get
|
||||
*/
|
||||
public get(query: Prisma.RulesFindManyArgs) {
|
||||
return this.ruleRepository.findMany(query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get a rule by uid
|
||||
* @throws {Error} If rule cannot be get by uid
|
||||
*/
|
||||
public getByUid(uid: string, query?: Prisma.RulesInclude) {
|
||||
return this.ruleRepository.findOneByUid(uid, query);
|
||||
}
|
||||
}
|
61
src/services/notary/UsersService/UsersService.ts
Normal file
61
src/services/notary/UsersService/UsersService.ts
Normal file
@ -0,0 +1,61 @@
|
||||
import BaseService from "@Services/BaseService";
|
||||
import "reflect-metadata";
|
||||
import { Service } from "typedi";
|
||||
import UsersRepository from "@Repositories/UsersRepository";
|
||||
import User from "le-coffre-resources/dist/Notary";
|
||||
import { Prisma, Users } from "@prisma/client";
|
||||
|
||||
@Service()
|
||||
export default class UsersService extends BaseService {
|
||||
constructor(private userRepository: UsersRepository) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get all users
|
||||
* @throws {Error} If users cannot be get
|
||||
*/
|
||||
public get(query: Prisma.UsersFindManyArgs) {
|
||||
return this.userRepository.findMany(query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Create a user
|
||||
* @throws {Error} If user couldn't be created
|
||||
*/
|
||||
public create(userEntity: User): Promise<Users> {
|
||||
return this.userRepository.create(userEntity);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Modify a user
|
||||
* @throws {Error} If user modification failed
|
||||
*/
|
||||
public update(uid: string, userEntity: User): Promise<Users> {
|
||||
return this.userRepository.update(uid, userEntity);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get a user by uid
|
||||
* @throws {Error} If user cannot be get by uid
|
||||
*/
|
||||
public getByUid(uid: string, query?: Prisma.UsersInclude) {
|
||||
return this.userRepository.findOneByUid(uid, query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get a user by uid with office
|
||||
* @throws {Error} If user cannot be get by uid
|
||||
*/
|
||||
public getByUidWithOffice(uid: string) {
|
||||
return this.userRepository.findOneByUidWithOffice(uid);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get a user by uid
|
||||
* @throws {Error} If user cannot be get by uid
|
||||
*/
|
||||
public getByProvider(providerName: string, id: string) {
|
||||
return this.userRepository.findOneByProvider(providerName, id);
|
||||
}
|
||||
}
|
@ -38,7 +38,15 @@ export default class CustomersService extends BaseService {
|
||||
* @description : Get a customer by uid
|
||||
* @throws {Error} If customer cannot be get by uid
|
||||
*/
|
||||
public async getByUid(uid: string, query?: any): Promise<Customers | null> {
|
||||
public async getByUid(uid: string, query?: Prisma.CustomersInclude): Promise<Customers | null> {
|
||||
return this.customerRepository.findOneByUid(uid, query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get a customer by contact uid
|
||||
* @throws {Error} If customer cannot be get by contact uid
|
||||
*/
|
||||
public async getByContact(contactUid: string): Promise<Customers | null> {
|
||||
return this.customerRepository.findOneByContact(contactUid);
|
||||
}
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ export default class DocumentsService extends BaseService {
|
||||
* @description : Get a document by uid
|
||||
* @throws {Error} If document cannot be get by uid
|
||||
*/
|
||||
public async getByUid(uid: string, query?: Prisma.DocumentsInclude) {
|
||||
public async getByUid(uid: string, query?: Prisma.DocumentsInclude): Promise<Documents | null> {
|
||||
return this.documentsRepository.findOneByUid(uid, query);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user