diff --git a/src/app/api/admin/CustomersController.ts b/src/app/api/admin/CustomersController.ts index c0aa1c49..90e05691 100644 --- a/src/app/api/admin/CustomersController.ts +++ b/src/app/api/admin/CustomersController.ts @@ -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; + } } } diff --git a/src/app/api/admin/DeedTypesController.ts b/src/app/api/admin/DeedTypesController.ts index 3963128e..9bacb358 100644 --- a/src/app/api/admin/DeedTypesController.ts +++ b/src/app/api/admin/DeedTypesController.ts @@ -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") { diff --git a/src/app/api/admin/DeedsController.ts b/src/app/api/admin/DeedsController.ts index 00a2fa20..7f027366 100644 --- a/src/app/api/admin/DeedsController.ts +++ b/src/app/api/admin/DeedsController.ts @@ -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 } ; diff --git a/src/app/api/admin/DocumentTypesController.ts b/src/app/api/admin/DocumentTypesController.ts index 582cd2f2..2cb864ce 100644 --- a/src/app/api/admin/DocumentTypesController.ts +++ b/src/app/api/admin/DocumentTypesController.ts @@ -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 } ; diff --git a/src/app/api/admin/DocumentsController.ts b/src/app/api/admin/DocumentsController.ts index 8911c769..32310c0b 100644 --- a/src/app/api/admin/DocumentsController.ts +++ b/src/app/api/admin/DocumentsController.ts @@ -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 }; diff --git a/src/app/api/admin/FilesController.ts b/src/app/api/admin/FilesController.ts index 583d3ddc..c2964d26 100644 --- a/src/app/api/admin/FilesController.ts +++ b/src/app/api/admin/FilesController.ts @@ -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(fileEntity, { strategy: "excludeAll" }); - - //success - this.httpSuccess(response, file); - } catch (error) { - this.httpInternalError(response, error); - return; - } - } - /** * @description Get a specific File by uid */ diff --git a/src/app/api/admin/OfficeFoldersController.ts b/src/app/api/admin/OfficeFoldersController.ts index 2284ae19..612ad17f 100644 --- a/src/app/api/admin/OfficeFoldersController.ts +++ b/src/app/api/admin/OfficeFoldersController.ts @@ -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") { diff --git a/src/app/api/admin/OfficeRolesController.ts b/src/app/api/admin/OfficeRolesController.ts index bd989779..5226a859 100644 --- a/src/app/api/admin/OfficeRolesController.ts +++ b/src/app/api/admin/OfficeRolesController.ts @@ -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") { diff --git a/src/app/api/admin/OfficesController.ts b/src/app/api/admin/OfficesController.ts index 546d240f..ded83057 100644 --- a/src/app/api/admin/OfficesController.ts +++ b/src/app/api/admin/OfficesController.ts @@ -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); diff --git a/src/app/api/admin/RolesController.ts b/src/app/api/admin/RolesController.ts index 634bd92e..a94b522c 100644 --- a/src/app/api/admin/RolesController.ts +++ b/src/app/api/admin/RolesController.ts @@ -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 diff --git a/src/app/api/admin/RulesController.ts b/src/app/api/admin/RulesController.ts index 55526601..eb95ed94 100644 --- a/src/app/api/admin/RulesController.ts +++ b/src/app/api/admin/RulesController.ts @@ -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 diff --git a/src/app/api/admin/UsersController.ts b/src/app/api/admin/UsersController.ts index cc4cde87..bf839fe7 100644 --- a/src/app/api/admin/UsersController.ts +++ b/src/app/api/admin/UsersController.ts @@ -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") { diff --git a/src/app/api/customer/DocumentsController.ts b/src/app/api/customer/DocumentsController.ts index 5d6142fb..ac14ca79 100644 --- a/src/app/api/customer/DocumentsController.ts +++ b/src/app/api/customer/DocumentsController.ts @@ -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; diff --git a/src/app/api/customer/FilesController.ts b/src/app/api/customer/FilesController.ts index c2947a9c..a5795688 100644 --- a/src/app/api/customer/FilesController.ts +++ b/src/app/api/customer/FilesController.ts @@ -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(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 diff --git a/src/app/api/customer/OfficeFoldersController.ts b/src/app/api/customer/OfficeFoldersController.ts index 899e346a..a3bfd8fe 100644 --- a/src/app/api/customer/OfficeFoldersController.ts +++ b/src/app/api/customer/OfficeFoldersController.ts @@ -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(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); diff --git a/src/app/api/notary/CustomersController.ts b/src/app/api/notary/CustomersController.ts index f5bc1789..0c63db1f 100644 --- a/src/app/api/notary/CustomersController.ts +++ b/src/app/api/notary/CustomersController.ts @@ -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; diff --git a/src/app/api/notary/DeedTypesController.ts b/src/app/api/notary/DeedTypesController.ts index a1f44f4a..cb5845bf 100644 --- a/src/app/api/notary/DeedTypesController.ts +++ b/src/app/api/notary/DeedTypesController.ts @@ -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 } ; diff --git a/src/app/api/notary/DeedsController.ts b/src/app/api/notary/DeedsController.ts index 52c664da..c436f898 100644 --- a/src/app/api/notary/DeedsController.ts +++ b/src/app/api/notary/DeedsController.ts @@ -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); diff --git a/src/app/api/notary/DocumentTypesController.ts b/src/app/api/notary/DocumentTypesController.ts index 8071a296..91e3bced 100644 --- a/src/app/api/notary/DocumentTypesController.ts +++ b/src/app/api/notary/DocumentTypesController.ts @@ -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 } ; diff --git a/src/app/api/notary/DocumentsController.ts b/src/app/api/notary/DocumentsController.ts index f23a27f0..7e866c8e 100644 --- a/src/app/api/notary/DocumentsController.ts +++ b/src/app/api/notary/DocumentsController.ts @@ -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(req.body); diff --git a/src/app/api/notary/FilesController.ts b/src/app/api/notary/FilesController.ts index 26334d08..46a4969b 100644 --- a/src/app/api/notary/FilesController.ts +++ b/src/app/api/notary/FilesController.ts @@ -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(fileEntity, { strategy: "excludeAll" }); - - //success - this.httpSuccess(response, file); - } catch (error) { - this.httpInternalError(response, error); - return; - } - } - /** * @description Get a specific File by uid */ diff --git a/src/app/api/notary/OfficeFolderAnchorsController.ts b/src/app/api/notary/OfficeFolderAnchorsController.ts index efb31606..cb16501b 100644 --- a/src/app/api/notary/OfficeFolderAnchorsController.ts +++ b/src/app/api/notary/OfficeFolderAnchorsController.ts @@ -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 = { diff --git a/src/app/api/notary/OfficeFoldersController.ts b/src/app/api/notary/OfficeFoldersController.ts index f8dca5ad..d10af72a 100644 --- a/src/app/api/notary/OfficeFoldersController.ts +++ b/src/app/api/notary/OfficeFoldersController.ts @@ -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(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(officeFolderEntityUpdated, { diff --git a/src/app/api/notary/OfficeRolesController.ts b/src/app/api/notary/OfficeRolesController.ts index 55aea36a..fce3401c 100644 --- a/src/app/api/notary/OfficeRolesController.ts +++ b/src/app/api/notary/OfficeRolesController.ts @@ -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 } ; diff --git a/src/app/api/notary/OfficesController.ts b/src/app/api/notary/OfficesController.ts index 52b8fede..f2ab1615 100644 --- a/src/app/api/notary/OfficesController.ts +++ b/src/app/api/notary/OfficesController.ts @@ -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); diff --git a/src/app/api/notary/RolesController.ts b/src/app/api/notary/RolesController.ts index 29da8bbd..11508e89 100644 --- a/src/app/api/notary/RolesController.ts +++ b/src/app/api/notary/RolesController.ts @@ -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 diff --git a/src/app/api/notary/RulesController.ts b/src/app/api/notary/RulesController.ts index 435a27c1..988c916e 100644 --- a/src/app/api/notary/RulesController.ts +++ b/src/app/api/notary/RulesController.ts @@ -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 = { diff --git a/src/app/api/notary/UserNotificationController.ts b/src/app/api/notary/UserNotificationController.ts index 970a150b..6d5d3074 100644 --- a/src/app/api/notary/UserNotificationController.ts +++ b/src/app/api/notary/UserNotificationController.ts @@ -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; diff --git a/src/app/api/notary/UsersController.ts b/src/app/api/notary/UsersController.ts index edb6b071..b92955ee 100644 --- a/src/app/api/notary/UsersController.ts +++ b/src/app/api/notary/UsersController.ts @@ -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 } ; diff --git a/src/app/api/super-admin/CustomersController.ts b/src/app/api/super-admin/CustomersController.ts index 05ef2c6a..fdb8ff01 100644 --- a/src/app/api/super-admin/CustomersController.ts +++ b/src/app/api/super-admin/CustomersController.ts @@ -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) { diff --git a/src/app/api/super-admin/DeedTypesController.ts b/src/app/api/super-admin/DeedTypesController.ts index 5ab62ce1..840ad792 100644 --- a/src/app/api/super-admin/DeedTypesController.ts +++ b/src/app/api/super-admin/DeedTypesController.ts @@ -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") { diff --git a/src/app/api/super-admin/DeedsController.ts b/src/app/api/super-admin/DeedsController.ts index a06de5ad..899af01d 100644 --- a/src/app/api/super-admin/DeedsController.ts +++ b/src/app/api/super-admin/DeedsController.ts @@ -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 } ; diff --git a/src/app/api/super-admin/DocumentTypesController.ts b/src/app/api/super-admin/DocumentTypesController.ts index 85dc6896..1880d8be 100644 --- a/src/app/api/super-admin/DocumentTypesController.ts +++ b/src/app/api/super-admin/DocumentTypesController.ts @@ -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 } ; diff --git a/src/app/api/super-admin/DocumentsController.ts b/src/app/api/super-admin/DocumentsController.ts index 73750914..01ce4402 100644 --- a/src/app/api/super-admin/DocumentsController.ts +++ b/src/app/api/super-admin/DocumentsController.ts @@ -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; diff --git a/src/app/api/super-admin/FilesController.ts b/src/app/api/super-admin/FilesController.ts index cb1b7f8d..38e119d6 100644 --- a/src/app/api/super-admin/FilesController.ts +++ b/src/app/api/super-admin/FilesController.ts @@ -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(fileEntity, { strategy: "excludeAll" }); - - //success - this.httpSuccess(response, file); - } catch (error) { - this.httpInternalError(response, error); - return; - } - } - /** * @description Get a specific File by uid */ diff --git a/src/app/api/super-admin/OfficeFoldersController.ts b/src/app/api/super-admin/OfficeFoldersController.ts index 200dc117..988c55c4 100644 --- a/src/app/api/super-admin/OfficeFoldersController.ts +++ b/src/app/api/super-admin/OfficeFoldersController.ts @@ -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") { diff --git a/src/app/api/super-admin/OfficeRolesController.ts b/src/app/api/super-admin/OfficeRolesController.ts index 802c223e..dd30cca6 100644 --- a/src/app/api/super-admin/OfficeRolesController.ts +++ b/src/app/api/super-admin/OfficeRolesController.ts @@ -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") { diff --git a/src/app/api/super-admin/OfficesController.ts b/src/app/api/super-admin/OfficesController.ts index f4edab79..05c0bc15 100644 --- a/src/app/api/super-admin/OfficesController.ts +++ b/src/app/api/super-admin/OfficesController.ts @@ -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") { diff --git a/src/app/api/super-admin/RolesController.ts b/src/app/api/super-admin/RolesController.ts index 372c02c5..f1a4428e 100644 --- a/src/app/api/super-admin/RolesController.ts +++ b/src/app/api/super-admin/RolesController.ts @@ -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 diff --git a/src/app/api/super-admin/RulesController.ts b/src/app/api/super-admin/RulesController.ts index 6f2f21a4..248de337 100644 --- a/src/app/api/super-admin/RulesController.ts +++ b/src/app/api/super-admin/RulesController.ts @@ -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 diff --git a/src/app/api/super-admin/UsersController.ts b/src/app/api/super-admin/UsersController.ts index a4a63b51..c45aa8bc 100644 --- a/src/app/api/super-admin/UsersController.ts +++ b/src/app/api/super-admin/UsersController.ts @@ -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") { diff --git a/src/common/repositories/OfficeFoldersRepository.ts b/src/common/repositories/OfficeFoldersRepository.ts index 67d40456..5205dc18 100644 --- a/src/common/repositories/OfficeFoldersRepository.ts +++ b/src/common/repositories/OfficeFoldersRepository.ts @@ -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!, diff --git a/src/services/customer/DocumentsService/DocumentsService.ts b/src/services/customer/DocumentsService/DocumentsService.ts index b162f5dc..e999dc46 100644 --- a/src/services/customer/DocumentsService/DocumentsService.ts +++ b/src/services/customer/DocumentsService/DocumentsService.ts @@ -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 { + return this.documentsRepository.delete(uid); + } + /** * @description : Modify a document * @throws {Error} If document cannot be modified diff --git a/src/services/notary/OfficeFoldersService/OfficeFoldersService.ts b/src/services/notary/OfficeFoldersService/OfficeFoldersService.ts index 689b4bb3..a96d5467 100644 --- a/src/services/notary/OfficeFoldersService/OfficeFoldersService.ts +++ b/src/services/notary/OfficeFoldersService/OfficeFoldersService.ts @@ -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