fix erros & access
This commit is contained in:
parent
6ceb96ea4c
commit
99985590bc
@ -25,14 +25,17 @@ export default class CustomersController extends ApiController {
|
||||
protected async get(req: Request, response: Response) {
|
||||
try {
|
||||
//get query
|
||||
let query;
|
||||
let query: Prisma.CustomersFindManyArgs = {};
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
if (query.where?.uid) {
|
||||
this.httpBadRequest(response, "You can't filter by uid");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const officeId: string = req.body.user.office_Id;
|
||||
if (query.where?.office_folders?.some?.office_uid) delete query.where.office_folders.some.office_uid;
|
||||
if (query.where?.office_folders?.some?.office?.uid) delete query.where?.office_folders?.some?.office?.uid;
|
||||
if (query.where?.office_folders) delete query.where.office_folders;
|
||||
const customerWhereInput: Prisma.CustomersWhereInput = { ...query.where, office_folders: { some: { office_uid: officeId } } };
|
||||
query.where = customerWhereInput;
|
||||
|
||||
@ -50,7 +53,6 @@ export default class CustomersController extends ApiController {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @description Create a new customer
|
||||
*/
|
||||
@ -128,27 +130,29 @@ export default class CustomersController extends ApiController {
|
||||
return;
|
||||
}
|
||||
|
||||
const customers = await this.customersService.get({
|
||||
where: {
|
||||
contact: { email: customerEntity.contact?.email },
|
||||
office_folders: {
|
||||
some: {
|
||||
office_uid: req.body.user.office_Id,
|
||||
if (customerEntity.contact?.email) {
|
||||
const customers = await this.customersService.get({
|
||||
where: {
|
||||
contact: { email: customerEntity.contact?.email },
|
||||
office_folders: {
|
||||
some: {
|
||||
office_uid: req.body.user.office_Id,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
if (customers.length != 0) {
|
||||
try {
|
||||
customers.forEach((customer) => {
|
||||
if (customer.uid != uid) {
|
||||
throw new Error("email déjà utilisé");
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
this.httpValidationError(response, [{ property: "email", constraints: { unique: "email déjà utilisé" } }]);
|
||||
return;
|
||||
if (customers.length != 0) {
|
||||
try {
|
||||
customers.forEach((customer) => {
|
||||
if (customer.uid != uid) {
|
||||
throw new Error("email déjà utilisé");
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
this.httpValidationError(response, [{ property: "email", constraints: { unique: "email déjà utilisé" } }]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -29,6 +29,10 @@ export default class DeedTypesController extends ApiController {
|
||||
let query: Prisma.DeedTypesFindManyArgs = {};
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
if(query.where?.uid) {
|
||||
this.httpBadRequest(response, "You can't filter by uid");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (req.query["search"] && typeof req.query["search"] === "string") {
|
||||
|
@ -29,6 +29,10 @@ export default class DeedsController extends ApiController {
|
||||
let query: Prisma.DeedsFindManyArgs = {};
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
if(query.where?.uid) {
|
||||
this.httpBadRequest(response, "You can't filter by uid");
|
||||
return;
|
||||
}
|
||||
}
|
||||
const officeId: string = req.body.user.office_Id;
|
||||
const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
|
||||
|
@ -29,6 +29,10 @@ export default class DocumentTypesController extends ApiController {
|
||||
let query: Prisma.DocumentTypesFindManyArgs = {};
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
if(query.where?.uid) {
|
||||
this.httpBadRequest(response, "You can't filter by uid");
|
||||
return;
|
||||
}
|
||||
}
|
||||
const officeId: string = req.body.user.office_Id;
|
||||
const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
|
||||
|
@ -30,6 +30,10 @@ export default class DocumentsController extends ApiController {
|
||||
let query: Prisma.DocumentsFindManyArgs = {};
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
if(query.where?.uid) {
|
||||
this.httpBadRequest(response, "You can't filter by uid");
|
||||
return;
|
||||
}
|
||||
}
|
||||
const officeId: string = req.body.user.office_Id;
|
||||
const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId };
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { Response, Request } from "express";
|
||||
import { Controller, Delete, Get } from "@ControllerPattern/index";
|
||||
import { Controller, Get } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import { Service } from "typedi";
|
||||
import FilesService from "@Services/common/FilesService/FilesService";
|
||||
@ -28,6 +28,10 @@ export default class FilesController extends ApiController {
|
||||
let query: Prisma.FilesFindManyArgs = {};
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
if(query.where?.uid) {
|
||||
this.httpBadRequest(response, "You can't filter by uid");
|
||||
return;
|
||||
}
|
||||
}
|
||||
const officeId: string = req.body.user.office_Id;
|
||||
const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
|
||||
@ -75,44 +79,6 @@ export default class FilesController extends ApiController {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Delete a specific File
|
||||
*/
|
||||
@Delete("/api/v1/admin/files/:uid", [authHandler, roleHandler, 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
|
||||
*/
|
||||
|
@ -28,6 +28,10 @@ export default class OfficeFoldersController extends ApiController {
|
||||
let query: Prisma.OfficeFoldersFindManyArgs = {};
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
if(query.where?.uid) {
|
||||
this.httpBadRequest(response, "You can't filter by uid");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (req.query["search"] && typeof req.query["search"] === "string") {
|
||||
|
@ -29,6 +29,10 @@ export default class OfficeRolesController extends ApiController {
|
||||
let query: Prisma.OfficeRolesFindManyArgs = {};
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
if(query.where?.uid) {
|
||||
this.httpBadRequest(response, "You can't filter by uid");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (req.query["search"] && typeof req.query["search"] === "string") {
|
||||
|
@ -3,7 +3,7 @@ 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 { Offices, Prisma } 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";
|
||||
@ -22,9 +22,13 @@ export default class OfficesController extends ApiController {
|
||||
protected async get(req: Request, response: Response) {
|
||||
try {
|
||||
//get query
|
||||
let query;
|
||||
let query: Prisma.OfficesFindManyArgs = {};
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
if (query.where?.uid) {
|
||||
this.httpBadRequest(response, "You can't filter by uid");
|
||||
return;
|
||||
}
|
||||
}
|
||||
//call service to get prisma entity
|
||||
const officesEntities: Offices[] = await this.officesService.get(query);
|
||||
|
@ -7,6 +7,7 @@ import { Role } from "le-coffre-resources/dist/Admin";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
import roleHandler from "@App/middlewares/RolesHandler";
|
||||
import { Prisma } from "@prisma/client";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
@ -22,9 +23,13 @@ export default class RolesController extends ApiController {
|
||||
protected async get(req: Request, response: Response) {
|
||||
try {
|
||||
//get query
|
||||
let query;
|
||||
let query: Prisma.RolesFindManyArgs = {};
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
if (query.where?.uid) {
|
||||
this.httpBadRequest(response, "You can't filter by uid");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//call service to get prisma entity
|
||||
|
@ -7,6 +7,7 @@ import { Rule } from "le-coffre-resources/dist/Admin";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
import roleHandler from "@App/middlewares/RolesHandler";
|
||||
import { Prisma } from "@prisma/client";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
@ -22,9 +23,13 @@ export default class RulesController extends ApiController {
|
||||
protected async get(req: Request, response: Response) {
|
||||
try {
|
||||
//get query
|
||||
let query;
|
||||
let query: Prisma.RulesFindManyArgs = {};
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
if (query.where?.uid) {
|
||||
this.httpBadRequest(response, "You can't filter by uid");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//call service to get prisma entity
|
||||
|
@ -29,6 +29,10 @@ export default class UsersController extends ApiController {
|
||||
let query: Prisma.UsersFindManyArgs = {};
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
if(query.where?.uid) {
|
||||
this.httpBadRequest(response, "You can't filter by uid");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (req.query["search"] && typeof req.query["search"] === "string") {
|
||||
|
@ -28,6 +28,10 @@ export default class DocumentsController extends ApiController {
|
||||
let query: Prisma.DocumentsFindManyArgs = {};
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
if(query.where?.uid) {
|
||||
this.httpBadRequest(response, "You can't filter by uid");
|
||||
return;
|
||||
}
|
||||
}
|
||||
const email: string = req.body.user.email;
|
||||
if (!email) {
|
||||
@ -66,7 +70,7 @@ export default class DocumentsController extends ApiController {
|
||||
return;
|
||||
}
|
||||
//get query
|
||||
let query: Prisma.DocumentsInclude = {};
|
||||
let query;
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
if (query.folder) delete query.folder;
|
||||
|
@ -34,6 +34,10 @@ export default class FilesController extends ApiController {
|
||||
let query: Prisma.FilesFindManyArgs = {};
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
if (query.where?.uid) {
|
||||
this.httpBadRequest(response, "You can't filter by uid");
|
||||
return;
|
||||
}
|
||||
}
|
||||
const email: string = req.body.user.email;
|
||||
if (!email) {
|
||||
@ -144,19 +148,22 @@ export default class FilesController extends ApiController {
|
||||
return;
|
||||
}
|
||||
|
||||
const fileFound = await this.filesService.getByUid(uid);
|
||||
const fileFound = await this.filesService.getByUid(uid, { document: { include: { files: true, document_type: true } } });
|
||||
|
||||
if (!fileFound) {
|
||||
this.httpNotFoundRequest(response, "file not found");
|
||||
return;
|
||||
}
|
||||
|
||||
const fileFoundEntity = File.hydrate<File>(fileFound, { strategy: "excludeAll" });
|
||||
|
||||
//call service to get prisma entity
|
||||
const fileEntity = await this.filesService.deleteKeyAndArchive(uid);
|
||||
|
||||
if (!fileEntity) {
|
||||
this.httpNotFoundRequest(response, "file not found");
|
||||
return;
|
||||
if (
|
||||
!(fileFoundEntity.document!.files?.find((file) => file.archived_at === null && file.uid !== uid)) &&
|
||||
fileFoundEntity.document!.document_type!.name === "Autres documents"
|
||||
) {
|
||||
await this.documentService.delete(fileFoundEntity.document!.uid!);
|
||||
}
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
|
@ -7,9 +7,6 @@ import { OfficeFolders, Prisma } from "@prisma/client";
|
||||
import { OfficeFolder } from "le-coffre-resources/dist/Customer";
|
||||
import officeFolderHandler from "@App/middlewares/CustomerHandler/FolderHandler";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
// import authHandler from "@App/middlewares/AuthHandler";
|
||||
// import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
// import folderHandler from "@App/middlewares/OfficeMembershipHandlers/FolderHandler";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
@ -28,6 +25,10 @@ export default class OfficeFoldersController extends ApiController {
|
||||
let query: Prisma.OfficeFoldersFindManyArgs = {};
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
if(query.where?.uid) {
|
||||
this.httpBadRequest(response, "You can't filter by uid");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const email: string = req.body.user.email;
|
||||
@ -79,7 +80,7 @@ export default class OfficeFoldersController extends ApiController {
|
||||
|
||||
const email: string = req.body.user.email;
|
||||
|
||||
let query: Prisma.OfficeFoldersInclude = {};
|
||||
let query;
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
if (query?.customers) delete query.customers;
|
||||
@ -95,7 +96,9 @@ export default class OfficeFoldersController extends ApiController {
|
||||
//Hydrate ressource with prisma entity
|
||||
const officeFolder = OfficeFolder.hydrate<OfficeFolder>(officeFolderEntity, { strategy: "excludeAll" });
|
||||
|
||||
officeFolder.customers = officeFolder.customers!.filter((customer) => customer.contact?.email === email);
|
||||
if(officeFolder.customers) {
|
||||
officeFolder.customers = officeFolder.customers!.filter((customer) => customer.contact?.email === email);
|
||||
}
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, officeFolder);
|
||||
|
@ -27,6 +27,10 @@ export default class CustomersController extends ApiController {
|
||||
let query: Prisma.CustomersFindManyArgs = {};
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
if(query.where?.uid) {
|
||||
this.httpBadRequest(response, "You can't filter by uid");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const officeId: string = req.body.user.office_Id;
|
||||
|
@ -28,6 +28,10 @@ export default class DeedTypesController extends ApiController {
|
||||
let query: Prisma.DeedTypesFindManyArgs = {};
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
if(query.where?.uid) {
|
||||
this.httpBadRequest(response, "You can't filter by uid");
|
||||
return;
|
||||
}
|
||||
}
|
||||
const officeId: string = req.body.user.office_Id;
|
||||
const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
|
||||
|
@ -28,11 +28,15 @@ export default class DeedsController extends ApiController {
|
||||
let query: Prisma.DeedsFindManyArgs = {};
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
if(query.where?.uid) {
|
||||
this.httpBadRequest(response, "You can't filter by uid");
|
||||
return;
|
||||
}
|
||||
}
|
||||
const officeId: string = req.body.user.office_Id;
|
||||
const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
|
||||
if(!query.where) query.where = { deed_type : {office: officeWhereInput}};
|
||||
query.where.deed_type!.office = officeWhereInput;
|
||||
if(query.where?.deed_type) delete query.where.deed_type;
|
||||
query.where = {...query.where, deed_type : {office: officeWhereInput}};
|
||||
|
||||
//call service to get prisma entity
|
||||
const deedEntities: Deeds[] = await this.deedsService.get(query);
|
||||
|
@ -27,6 +27,10 @@ export default class DocumentTypesController extends ApiController {
|
||||
let query: Prisma.DocumentTypesFindManyArgs = {};
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
if(query.where?.uid) {
|
||||
this.httpBadRequest(response, "You can't filter by uid");
|
||||
return;
|
||||
}
|
||||
}
|
||||
const officeId: string = req.body.user.office_Id;
|
||||
const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
|
||||
|
@ -35,6 +35,10 @@ export default class DocumentsController extends ApiController {
|
||||
let query: Prisma.DocumentsFindManyArgs = {};
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
if(query.where?.uid) {
|
||||
this.httpBadRequest(response, "You can't filter by uid");
|
||||
return;
|
||||
}
|
||||
}
|
||||
const officeId: string = req.body.user.office_Id;
|
||||
const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId };
|
||||
@ -120,6 +124,11 @@ export default class DocumentsController extends ApiController {
|
||||
return;
|
||||
}
|
||||
|
||||
if(documentFound.document_status === EDocumentStatus.REFUSED || documentFound.document_status === EDocumentStatus.VALIDATED) {
|
||||
this.httpForbidden(response, "You are not allowed to update a VALIDATED or REFUSED document");
|
||||
return;
|
||||
}
|
||||
|
||||
//init Document resource with request body values
|
||||
const documentEntity = Document.hydrate<Document>(req.body);
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { Response, Request } from "express";
|
||||
import { Controller, Delete, Get } from "@ControllerPattern/index";
|
||||
import { Controller, Get } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import { Service } from "typedi";
|
||||
import FilesService from "@Services/common/FilesService/FilesService";
|
||||
@ -27,6 +27,10 @@ export default class FilesController extends ApiController {
|
||||
let query: Prisma.FilesFindManyArgs = {};
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
if(query.where?.uid) {
|
||||
this.httpBadRequest(response, "You can't filter by uid");
|
||||
return;
|
||||
}
|
||||
}
|
||||
const officeId: string = req.body.user.office_Id;
|
||||
const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
|
||||
@ -74,44 +78,6 @@ export default class FilesController extends ApiController {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
|
@ -275,6 +275,10 @@ export default class OfficeFoldersController extends ApiController {
|
||||
let query: Prisma.OfficeFolderAnchorsFindManyArgs = {};
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
if(query.where?.uid) {
|
||||
this.httpBadRequest(response, "You can't filter by uid");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
query.where = {
|
||||
|
@ -27,6 +27,10 @@ export default class OfficeFoldersController extends ApiController {
|
||||
let query: Prisma.OfficeFoldersFindManyArgs = {};
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
if(query.where?.uid) {
|
||||
this.httpBadRequest(response, "You can't filter by uid");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (req.query["search"] && typeof req.query["search"] === "string") {
|
||||
@ -186,7 +190,7 @@ export default class OfficeFoldersController extends ApiController {
|
||||
}
|
||||
|
||||
//call service to get prisma entity
|
||||
const officeFolderEntityUpdated = await this.officeFoldersService.update(uid, officefolderToUpdate);
|
||||
const officeFolderEntityUpdated = await this.officeFoldersService.updateStatus(uid, officefolderToUpdate);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const officeFolders = OfficeFolder.hydrate<OfficeFolder>(officeFolderEntityUpdated, {
|
||||
@ -232,7 +236,7 @@ export default class OfficeFoldersController extends ApiController {
|
||||
await validateOrReject(officefolderToUpdate, { groups: ["updateFolder"], forbidUnknownValues: false });
|
||||
|
||||
//call service to get prisma entity
|
||||
const officeFolderEntityUpdated = await this.officeFoldersService.update(uid, officefolderToUpdate);
|
||||
const officeFolderEntityUpdated = await this.officeFoldersService.updateStatus(uid, officefolderToUpdate);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const officeFolders = OfficeFolder.hydrate<OfficeFolder>(officeFolderEntityUpdated, {
|
||||
|
@ -26,6 +26,10 @@ export default class OfficeRolesController extends ApiController {
|
||||
let query: Prisma.OfficeRolesFindManyArgs = {};
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
if(query.where?.uid) {
|
||||
this.httpBadRequest(response, "You can't filter by uid");
|
||||
return;
|
||||
}
|
||||
}
|
||||
const officeId: string = req.body.user.office_Id;
|
||||
const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
|
||||
|
@ -3,7 +3,7 @@ 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 { Offices, Prisma } 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";
|
||||
@ -21,9 +21,13 @@ export default class OfficesController extends ApiController {
|
||||
protected async get(req: Request, response: Response) {
|
||||
try {
|
||||
//get query
|
||||
let query;
|
||||
let query: Prisma.OfficesFindManyArgs = {};
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
if (query.where?.uid) {
|
||||
this.httpBadRequest(response, "You can't filter by uid");
|
||||
return;
|
||||
}
|
||||
}
|
||||
//call service to get prisma entity
|
||||
const officesEntities: Offices[] = await this.officesService.get(query);
|
||||
|
@ -6,6 +6,7 @@ import { Service } from "typedi";
|
||||
import { Role } from "le-coffre-resources/dist/Notary";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
import { Prisma } from "@prisma/client";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
@ -21,9 +22,13 @@ export default class RolesController extends ApiController {
|
||||
protected async get(req: Request, response: Response) {
|
||||
try {
|
||||
//get query
|
||||
let query;
|
||||
let query: Prisma.RolesFindManyArgs = {};
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
if (query.where?.uid) {
|
||||
this.httpBadRequest(response, "You can't filter by uid");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//call service to get prisma entity
|
||||
|
@ -6,6 +6,7 @@ import { Service } from "typedi";
|
||||
import { Rule } from "le-coffre-resources/dist/Notary";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
import { Prisma } from "@prisma/client";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
@ -21,9 +22,13 @@ export default class RulesController extends ApiController {
|
||||
protected async get(req: Request, response: Response) {
|
||||
try {
|
||||
//get query
|
||||
let query;
|
||||
let query: Prisma.RulesFindManyArgs = {};
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
if (query.where?.uid) {
|
||||
this.httpBadRequest(response, "You can't filter by uid");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
query.where = {
|
||||
|
@ -22,12 +22,14 @@ export default class UserNotificationController extends ApiController {
|
||||
protected async get(req: Request, response: Response) {
|
||||
try {
|
||||
//get query
|
||||
let query: any = {};
|
||||
let query: Prisma.UserNotificationsFindManyArgs = {};
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
if (query.where?.uid) {
|
||||
this.httpBadRequest(response, "You can't filter by uid");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const userId: string = req.body.user.userId;
|
||||
if(query.where?.user_uid) delete query.where.user_uid;
|
||||
if(query.where?.user?.uid) delete query.where.user.uid;
|
||||
|
@ -26,6 +26,10 @@ export default class UsersController extends ApiController {
|
||||
let query: Prisma.UsersFindManyArgs = {};
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
if(query.where?.uid) {
|
||||
this.httpBadRequest(response, "You can't filter by uid");
|
||||
return;
|
||||
}
|
||||
}
|
||||
const officeId: string = req.body.user.office_Id;
|
||||
const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
|
||||
|
@ -25,17 +25,21 @@ export default class CustomersController extends ApiController {
|
||||
protected async get(req: Request, response: Response) {
|
||||
try {
|
||||
//get query
|
||||
let query;
|
||||
let query: Prisma.CustomersFindManyArgs = {};
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
if (query.where?.uid) {
|
||||
this.httpBadRequest(response, "You can't filter by uid");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const officeId: string = req.body.user.office_Id;
|
||||
if(query.where?.office_folders?.some?.office_uid) delete query.where.office_folders.some.office_uid;
|
||||
if(query.where?.office_folders?.some?.office?.uid) delete query.where?.office_folders?.some?.office?.uid;
|
||||
const customerWhereInput: Prisma.CustomersWhereInput = { ...query.where, office_folders: { some: { office_uid: officeId } }};
|
||||
if (query.where?.office_folders?.some?.office_uid) delete query.where.office_folders.some.office_uid;
|
||||
if (query.where?.office_folders?.some?.office?.uid) delete query.where?.office_folders?.some?.office?.uid;
|
||||
const customerWhereInput: Prisma.CustomersWhereInput = { ...query.where, office_folders: { some: { office_uid: officeId } } };
|
||||
query.where = customerWhereInput;
|
||||
|
||||
|
||||
//call service to get prisma entity
|
||||
const customersEntities = await this.customersService.get(query);
|
||||
|
||||
@ -50,7 +54,6 @@ export default class CustomersController extends ApiController {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @description Create a new customer
|
||||
*/
|
||||
@ -128,27 +131,29 @@ export default class CustomersController extends ApiController {
|
||||
return;
|
||||
}
|
||||
|
||||
const customers = await this.customersService.get({
|
||||
where: {
|
||||
contact: { email: customerEntity.contact?.email },
|
||||
office_folders: {
|
||||
some: {
|
||||
office_uid: req.body.user.office_Id,
|
||||
if (customerEntity.contact?.email) {
|
||||
const customers = await this.customersService.get({
|
||||
where: {
|
||||
contact: { email: customerEntity.contact?.email },
|
||||
office_folders: {
|
||||
some: {
|
||||
office_uid: req.body.user.office_Id,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
if (customers.length != 0) {
|
||||
try {
|
||||
customers.forEach((customer) => {
|
||||
if (customer.uid != uid) {
|
||||
throw new Error("email déjà utilisé");
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
this.httpValidationError(response, [{ property: "email", constraints: { unique: "email déjà utilisé" } }]);
|
||||
return;
|
||||
if (customers.length != 0) {
|
||||
try {
|
||||
customers.forEach((customer) => {
|
||||
if (customer.uid != uid) {
|
||||
throw new Error("email déjà utilisé");
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
this.httpValidationError(response, [{ property: "email", constraints: { unique: "email déjà utilisé" } }]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -189,7 +194,7 @@ export default class CustomersController extends ApiController {
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
}
|
||||
|
||||
|
||||
const customerEntity = await this.customersService.getByUid(uid, query);
|
||||
|
||||
if (!customerEntity) {
|
||||
|
@ -29,6 +29,10 @@ export default class DeedTypesController extends ApiController {
|
||||
let query: Prisma.DeedTypesFindManyArgs = {};
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
if(query.where?.uid) {
|
||||
this.httpBadRequest(response, "You can't filter by uid");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (req.query["search"] && typeof req.query["search"] === "string") {
|
||||
|
@ -29,6 +29,10 @@ export default class DeedsController extends ApiController {
|
||||
let query: Prisma.DeedsFindManyArgs = {};
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
if(query.where?.uid) {
|
||||
this.httpBadRequest(response, "You can't filter by uid");
|
||||
return;
|
||||
}
|
||||
}
|
||||
const officeId: string = req.body.user.office_Id;
|
||||
const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
|
||||
|
@ -29,6 +29,10 @@ export default class DocumentTypesController extends ApiController {
|
||||
let query: Prisma.DocumentTypesFindManyArgs = {};
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
if(query.where?.uid) {
|
||||
this.httpBadRequest(response, "You can't filter by uid");
|
||||
return;
|
||||
}
|
||||
}
|
||||
const officeId: string = req.body.user.office_Id;
|
||||
const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
|
||||
|
@ -30,6 +30,10 @@ export default class DocumentsController extends ApiController {
|
||||
let query: Prisma.DocumentsFindManyArgs = {};
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
if(query.where?.uid) {
|
||||
this.httpBadRequest(response, "You can't filter by uid");
|
||||
return;
|
||||
}
|
||||
}
|
||||
const officeId: string = req.body.user.office_Id;
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { Response, Request } from "express";
|
||||
import { Controller, Delete, Get } from "@ControllerPattern/index";
|
||||
import { Controller, Get } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import { Service } from "typedi";
|
||||
import FilesService from "@Services/common/FilesService/FilesService";
|
||||
@ -28,6 +28,10 @@ export default class FilesController extends ApiController {
|
||||
let query: Prisma.FilesFindManyArgs = {};
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
if(query.where?.uid) {
|
||||
this.httpBadRequest(response, "You can't filter by uid");
|
||||
return;
|
||||
}
|
||||
}
|
||||
const officeId: string = req.body.user.office_Id;
|
||||
const officeWhereInput: Prisma.OfficesWhereInput = { uid: officeId } ;
|
||||
@ -76,44 +80,6 @@ export default class FilesController extends ApiController {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Delete a specific File
|
||||
*/
|
||||
@Delete("/api/v1/super-admin/files/:uid", [authHandler, roleHandler, 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
|
||||
*/
|
||||
|
@ -28,6 +28,10 @@ export default class OfficeFoldersController extends ApiController {
|
||||
let query: Prisma.OfficeFoldersFindManyArgs = {};
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
if(query.where?.uid) {
|
||||
this.httpBadRequest(response, "You can't filter by uid");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (req.query["search"] && typeof req.query["search"] === "string") {
|
||||
|
@ -28,6 +28,10 @@ export default class OfficeRolesController extends ApiController {
|
||||
let query: Prisma.OfficeRolesFindManyArgs = {};
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
if(query.where?.uid) {
|
||||
this.httpBadRequest(response, "You can't filter by uid");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if(req.query["search"] && typeof req.query["search"] === "string") {
|
||||
|
@ -3,7 +3,7 @@ import { Controller, Get, Post, Put } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import OfficesService from "@Services/super-admin/OfficesService/OfficesService";
|
||||
import { Service } from "typedi";
|
||||
import { Offices } from "@prisma/client";
|
||||
import { Offices, Prisma } from "@prisma/client";
|
||||
import { Office as OfficeResource } from "le-coffre-resources/dist/SuperAdmin";
|
||||
import { validateOrReject } from "class-validator";
|
||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
@ -23,9 +23,13 @@ export default class OfficesController extends ApiController {
|
||||
protected async get(req: Request, response: Response) {
|
||||
try {
|
||||
//get query
|
||||
let query;
|
||||
let query: Prisma.OfficesFindManyArgs = {};
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
if (query.where?.uid) {
|
||||
this.httpBadRequest(response, "You can't filter by uid");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if(req.query["search"] && typeof req.query["search"] === "string") {
|
||||
|
@ -8,6 +8,7 @@ import { Role } from "le-coffre-resources/dist/SuperAdmin";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
import roleHandler from "@App/middlewares/RolesHandler";
|
||||
import { Prisma } from "@prisma/client";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
@ -23,9 +24,13 @@ export default class RolesController extends ApiController {
|
||||
protected async get(req: Request, response: Response) {
|
||||
try {
|
||||
//get query
|
||||
let query;
|
||||
let query: Prisma.RolesFindManyArgs = {};
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
if (query.where?.uid) {
|
||||
this.httpBadRequest(response, "You can't filter by uid");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//call service to get prisma entity
|
||||
|
@ -8,6 +8,7 @@ import { Rule } from "le-coffre-resources/dist/SuperAdmin";
|
||||
import authHandler from "@App/middlewares/AuthHandler";
|
||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
import roleHandler from "@App/middlewares/RolesHandler";
|
||||
import { Prisma } from "@prisma/client";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
@ -23,9 +24,13 @@ export default class RulesController extends ApiController {
|
||||
protected async get(req: Request, response: Response) {
|
||||
try {
|
||||
//get query
|
||||
let query;
|
||||
let query: Prisma.RulesFindManyArgs = {};
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
if (query.where?.uid) {
|
||||
this.httpBadRequest(response, "You can't filter by uid");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//call service to get prisma entity
|
||||
|
@ -10,6 +10,7 @@ import ruleHandler from "@App/middlewares/RulesHandler";
|
||||
import roleHandler from "@App/middlewares/RolesHandler";
|
||||
import RolesService from "@Services/super-admin/RolesService/RolesService";
|
||||
import OfficeRolesService from "@Services/super-admin/OfficeRolesService/OfficeRolesService";
|
||||
import { Prisma } from "@prisma/client";
|
||||
|
||||
@Controller()
|
||||
@Service()
|
||||
@ -25,9 +26,13 @@ export default class UsersController extends ApiController {
|
||||
protected async get(req: Request, response: Response) {
|
||||
try {
|
||||
//get query
|
||||
let query;
|
||||
let query: Prisma.UsersFindManyArgs = {};
|
||||
if (req.query["q"]) {
|
||||
query = JSON.parse(req.query["q"] as string);
|
||||
if (query.where?.uid) {
|
||||
this.httpBadRequest(response, "You can't filter by uid");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (req.query["search"] && typeof req.query["search"] === "string") {
|
||||
|
@ -55,6 +55,18 @@ export default class OfficeFoldersRepository extends BaseRepository {
|
||||
return this.model.create({ ...createArgs, include: { stakeholders: true } });
|
||||
}
|
||||
|
||||
public async updateStatus(uid: string, status: EFolderStatus, archived_description: string | null) {
|
||||
return this.model.update({
|
||||
where: {
|
||||
uid: uid,
|
||||
},
|
||||
data: {
|
||||
status: status,
|
||||
archived_description: archived_description,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Update data of an office folder
|
||||
*/
|
||||
@ -67,8 +79,6 @@ export default class OfficeFoldersRepository extends BaseRepository {
|
||||
folder_number: officeFolder.folder_number,
|
||||
name: officeFolder.name,
|
||||
description: officeFolder.description,
|
||||
status: EFolderStatus[officeFolder.status as keyof typeof EFolderStatus],
|
||||
archived_description: officeFolder.archived_description,
|
||||
stakeholders: {
|
||||
set: officeFolder.stakeholders?.map((stakeholder) => ({
|
||||
uid: stakeholder.uid!,
|
||||
|
@ -34,6 +34,14 @@ export default class DocumentsService extends BaseService {
|
||||
return this.documentsRepository.create(document);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Delete a document
|
||||
* @throws {Error} If document cannot be created
|
||||
*/
|
||||
public async delete(uid: string): Promise<Documents> {
|
||||
return this.documentsRepository.delete(uid);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Modify a document
|
||||
* @throws {Error} If document cannot be modified
|
||||
|
@ -3,7 +3,7 @@ import OfficeFoldersRepository from "@Repositories/OfficeFoldersRepository";
|
||||
import BaseService from "@Services/BaseService";
|
||||
import { OfficeFolder } from "le-coffre-resources/dist/Notary";
|
||||
import { Service } from "typedi";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import { EFolderStatus, Prisma } from "@prisma/client";
|
||||
import DeedsService from "../DeedsService/DeedsService";
|
||||
|
||||
@Service()
|
||||
@ -41,6 +41,14 @@ export default class OfficeFoldersService extends BaseService {
|
||||
return this.officeFoldersRepository.update(officeFolderuid, officeFolderEntity);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Modify a folder status
|
||||
* @throws {Error} If folder cannot be modified
|
||||
*/
|
||||
public async updateStatus(uid: string, officeFolderEntity: OfficeFolder) {
|
||||
return this.officeFoldersRepository.updateStatus(uid,officeFolderEntity.status as EFolderStatus, officeFolderEntity.archived_description);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get a folder by uid
|
||||
* @throws {Error} If folder cannot be get by uid
|
||||
|
Loading…
x
Reference in New Issue
Block a user