From 7022e41fcb4417ec6b51f1a640a390dd4a1e0391 Mon Sep 17 00:00:00 2001 From: OxSaitama Date: Tue, 11 Jul 2023 14:41:23 +0200 Subject: [PATCH] refacto error messages --- .../OfficeMembershipHandlers/DeedHandler.ts | 4 ++-- .../DeedTypeHandler.ts | 6 +++--- .../DocumentHandler.ts | 4 ++-- .../DocumentTypeHandler.ts | 4 ++-- .../OfficeMembershipHandlers/FileHandler.ts | 4 ++-- .../OfficeMembershipHandlers/FolderHandler.ts | 19 ++++++++++--------- .../OfficeRoleHandler.ts | 4 ++-- .../OfficeMembershipHandlers/UserHandler.ts | 4 ++-- src/app/middlewares/RulesHandler.ts | 4 ++-- 9 files changed, 27 insertions(+), 26 deletions(-) diff --git a/src/app/middlewares/OfficeMembershipHandlers/DeedHandler.ts b/src/app/middlewares/OfficeMembershipHandlers/DeedHandler.ts index a32c02d9..7ca6d7fc 100644 --- a/src/app/middlewares/OfficeMembershipHandlers/DeedHandler.ts +++ b/src/app/middlewares/OfficeMembershipHandlers/DeedHandler.ts @@ -20,7 +20,7 @@ export default async function deedHandler(req: Request, response: Response, next } if (deed.deed_type.office.uid != officeId) { - response.status(HttpCodes.UNAUTHORIZED).send("Not authorized with this office"); + response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office"); return; } } @@ -34,7 +34,7 @@ export default async function deedHandler(req: Request, response: Response, next return; } if (deedTypeWithOffice.office?.uid != officeId) { - response.status(HttpCodes.UNAUTHORIZED).send("Not authorized with this office"); + response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office"); return; } }); diff --git a/src/app/middlewares/OfficeMembershipHandlers/DeedTypeHandler.ts b/src/app/middlewares/OfficeMembershipHandlers/DeedTypeHandler.ts index e00f8344..2836b3d5 100644 --- a/src/app/middlewares/OfficeMembershipHandlers/DeedTypeHandler.ts +++ b/src/app/middlewares/OfficeMembershipHandlers/DeedTypeHandler.ts @@ -12,7 +12,7 @@ export default async function deedTypeHandler(req: Request, response: Response, const office = req.body.office; if (office && office.uid != officeId) { - response.status(HttpCodes.UNAUTHORIZED).send("Not authorized with this office"); + response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office"); return; } @@ -26,7 +26,7 @@ export default async function deedTypeHandler(req: Request, response: Response, } if (deedType.office.uid != officeId) { - response.status(HttpCodes.UNAUTHORIZED).send("Not authorized with this office"); + response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office"); return; } } @@ -40,7 +40,7 @@ export default async function deedTypeHandler(req: Request, response: Response, return; } if (documentTypeWithOffice.office?.uid != officeId) { - response.status(HttpCodes.UNAUTHORIZED).send("Not authorized with this office"); + response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office"); return; } }); diff --git a/src/app/middlewares/OfficeMembershipHandlers/DocumentHandler.ts b/src/app/middlewares/OfficeMembershipHandlers/DocumentHandler.ts index 790b844e..62470f16 100644 --- a/src/app/middlewares/OfficeMembershipHandlers/DocumentHandler.ts +++ b/src/app/middlewares/OfficeMembershipHandlers/DocumentHandler.ts @@ -21,7 +21,7 @@ export default async function documentHandler(req: Request, response: Response, return; } if (officeFolderWithOffice.office?.uid != officeId) { - response.status(HttpCodes.UNAUTHORIZED).send("Not authorized with this office"); + response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office"); return; } } @@ -34,7 +34,7 @@ export default async function documentHandler(req: Request, response: Response, return; } if (documentTypeWithOffice.office?.uid != officeId) { - response.status(HttpCodes.UNAUTHORIZED).send("Not authorized with this office"); + response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office"); return; } } diff --git a/src/app/middlewares/OfficeMembershipHandlers/DocumentTypeHandler.ts b/src/app/middlewares/OfficeMembershipHandlers/DocumentTypeHandler.ts index 908df26e..250487cd 100644 --- a/src/app/middlewares/OfficeMembershipHandlers/DocumentTypeHandler.ts +++ b/src/app/middlewares/OfficeMembershipHandlers/DocumentTypeHandler.ts @@ -9,7 +9,7 @@ export default async function documentTypeHandler(req: Request, response: Respon const office = req.body.office; if (office && office.uid != officeId) { - response.status(HttpCodes.UNAUTHORIZED).send("Not authorized with this office"); + response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office"); return; } @@ -23,7 +23,7 @@ export default async function documentTypeHandler(req: Request, response: Respon } if (documentType.office.uid != officeId) { - response.status(HttpCodes.UNAUTHORIZED).send("Not authorized with this office"); + response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office"); return; } } diff --git a/src/app/middlewares/OfficeMembershipHandlers/FileHandler.ts b/src/app/middlewares/OfficeMembershipHandlers/FileHandler.ts index 27ce2cd3..d91ad586 100644 --- a/src/app/middlewares/OfficeMembershipHandlers/FileHandler.ts +++ b/src/app/middlewares/OfficeMembershipHandlers/FileHandler.ts @@ -17,7 +17,7 @@ export default async function fileHandler(req: Request, response: Response, next return; } if (documentWithOffice.folder.office?.uid != officeId) { - response.status(HttpCodes.UNAUTHORIZED).send("Not authorized with this office"); + response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office"); return; } } @@ -33,7 +33,7 @@ export default async function fileHandler(req: Request, response: Response, next return; } if (file.document.folder.office.uid != officeId) { - response.status(HttpCodes.UNAUTHORIZED).send("Not authorized with this office"); + response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office"); return; } } diff --git a/src/app/middlewares/OfficeMembershipHandlers/FolderHandler.ts b/src/app/middlewares/OfficeMembershipHandlers/FolderHandler.ts index 2450eea7..e63d8782 100644 --- a/src/app/middlewares/OfficeMembershipHandlers/FolderHandler.ts +++ b/src/app/middlewares/OfficeMembershipHandlers/FolderHandler.ts @@ -2,7 +2,7 @@ import HttpCodes from "@Common/system/controller-pattern/HttpCodes"; import { NextFunction, Request, Response } from "express"; import Container from "typedi"; import OfficeFoldersService from "@Services/super-admin/OfficeFoldersService/OfficeFoldersService"; -import DeedsService from "@Services/super-admin/DeedsService/DeedsService"; +import DeedTypesService from "@Services/super-admin/DeedTypesService/DeedTypesService"; export default async function folderHandler(req: Request, response: Response, next: NextFunction) { const officeId = req.body.user.office_Id; @@ -13,19 +13,20 @@ export default async function folderHandler(req: Request, response: Response, ne if (office && office.uid != officeId) { console.log("wrong office"); - response.status(HttpCodes.UNAUTHORIZED).send("Not authorized with this office"); + response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office"); return; } if (deed) { - const deedService = Container.get(DeedsService); - const deedWithOffice = await deedService.getByUidWithOffice(deed.uid!); - if (!deedWithOffice) { - response.sendStatus(HttpCodes.NOT_FOUND); + const deedTypeService = Container.get(DeedTypesService); + console.log("deed : ",deed); + const deedTypeWithOffice = await deedTypeService.getByUidWithOffice(deed.deed_type.uid!); + if (!deedTypeWithOffice) { + response.status(HttpCodes.NOT_FOUND).send("Deed type not found"); return; } - if (deedWithOffice.deed_type.office.uid != officeId) { - response.status(HttpCodes.UNAUTHORIZED).send("Not authorized with this deed type"); + if (deedTypeWithOffice.office.uid != officeId) { + response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this deed type"); return; } } @@ -51,7 +52,7 @@ export default async function folderHandler(req: Request, response: Response, ne } if (officeFolder.office.uid != officeId) { - response.status(HttpCodes.UNAUTHORIZED).send("Not authorized with this office"); + response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office"); return; } } diff --git a/src/app/middlewares/OfficeMembershipHandlers/OfficeRoleHandler.ts b/src/app/middlewares/OfficeMembershipHandlers/OfficeRoleHandler.ts index b1a33629..51716731 100644 --- a/src/app/middlewares/OfficeMembershipHandlers/OfficeRoleHandler.ts +++ b/src/app/middlewares/OfficeMembershipHandlers/OfficeRoleHandler.ts @@ -9,7 +9,7 @@ export default async function officeRoleHandler(req: Request, response: Response const office = req.body.office; if (office && office.uid != officeId) { - response.status(HttpCodes.UNAUTHORIZED).send("Not authorized with this office"); + response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office"); return; } @@ -23,7 +23,7 @@ export default async function officeRoleHandler(req: Request, response: Response } if (officeRole.office.uid != officeId) { - response.status(HttpCodes.UNAUTHORIZED).send("Not authorized with this office"); + response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office"); return; } } diff --git a/src/app/middlewares/OfficeMembershipHandlers/UserHandler.ts b/src/app/middlewares/OfficeMembershipHandlers/UserHandler.ts index d66c88bf..a0a82207 100644 --- a/src/app/middlewares/OfficeMembershipHandlers/UserHandler.ts +++ b/src/app/middlewares/OfficeMembershipHandlers/UserHandler.ts @@ -9,7 +9,7 @@ export default async function userHandler(req: Request, response: Response, next const office = req.body.office_membership; if (office && office.uid != officeId) { - response.status(HttpCodes.UNAUTHORIZED).send("Not authorized with this office"); + response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office"); return; } @@ -23,7 +23,7 @@ export default async function userHandler(req: Request, response: Response, next } if (user.office_membership.uid != officeId) { - response.status(HttpCodes.UNAUTHORIZED).send("Not authorized with this office"); + response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office"); return; } } diff --git a/src/app/middlewares/RulesHandler.ts b/src/app/middlewares/RulesHandler.ts index 08aff7e1..89df35a9 100644 --- a/src/app/middlewares/RulesHandler.ts +++ b/src/app/middlewares/RulesHandler.ts @@ -8,12 +8,12 @@ export default async function ruleHandler(req: Request, response: Response, next const role = req.body.user.role; if (namespace != "notary" && role != namespace) { - response.status(HttpCodes.UNAUTHORIZED).send("Not authorized with this role"); + response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this role"); return; } if (!rules.includes(req.method + " " + service)) { - response.status(HttpCodes.UNAUTHORIZED).send("Not authorized with those rules"); + response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with those rules"); return; }