refacto error messages

This commit is contained in:
OxSaitama 2023-07-11 14:41:23 +02:00
parent ae4812c0dc
commit 7022e41fcb
9 changed files with 27 additions and 26 deletions

View File

@ -20,7 +20,7 @@ export default async function deedHandler(req: Request, response: Response, next
} }
if (deed.deed_type.office.uid != officeId) { 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; return;
} }
} }
@ -34,7 +34,7 @@ export default async function deedHandler(req: Request, response: Response, next
return; return;
} }
if (deedTypeWithOffice.office?.uid != officeId) { 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; return;
} }
}); });

View File

@ -12,7 +12,7 @@ export default async function deedTypeHandler(req: Request, response: Response,
const office = req.body.office; const office = req.body.office;
if (office && office.uid != officeId) { 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; return;
} }
@ -26,7 +26,7 @@ export default async function deedTypeHandler(req: Request, response: Response,
} }
if (deedType.office.uid != officeId) { 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; return;
} }
} }
@ -40,7 +40,7 @@ export default async function deedTypeHandler(req: Request, response: Response,
return; return;
} }
if (documentTypeWithOffice.office?.uid != officeId) { 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; return;
} }
}); });

View File

@ -21,7 +21,7 @@ export default async function documentHandler(req: Request, response: Response,
return; return;
} }
if (officeFolderWithOffice.office?.uid != officeId) { 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; return;
} }
} }
@ -34,7 +34,7 @@ export default async function documentHandler(req: Request, response: Response,
return; return;
} }
if (documentTypeWithOffice.office?.uid != officeId) { 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; return;
} }
} }

View File

@ -9,7 +9,7 @@ export default async function documentTypeHandler(req: Request, response: Respon
const office = req.body.office; const office = req.body.office;
if (office && office.uid != officeId) { 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; return;
} }
@ -23,7 +23,7 @@ export default async function documentTypeHandler(req: Request, response: Respon
} }
if (documentType.office.uid != officeId) { 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; return;
} }
} }

View File

@ -17,7 +17,7 @@ export default async function fileHandler(req: Request, response: Response, next
return; return;
} }
if (documentWithOffice.folder.office?.uid != officeId) { 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; return;
} }
} }
@ -33,7 +33,7 @@ export default async function fileHandler(req: Request, response: Response, next
return; return;
} }
if (file.document.folder.office.uid != officeId) { 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; return;
} }
} }

View File

@ -2,7 +2,7 @@ import HttpCodes from "@Common/system/controller-pattern/HttpCodes";
import { NextFunction, Request, Response } from "express"; import { NextFunction, Request, Response } from "express";
import Container from "typedi"; import Container from "typedi";
import OfficeFoldersService from "@Services/super-admin/OfficeFoldersService/OfficeFoldersService"; 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) { export default async function folderHandler(req: Request, response: Response, next: NextFunction) {
const officeId = req.body.user.office_Id; 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) { if (office && office.uid != officeId) {
console.log("wrong office"); console.log("wrong office");
response.status(HttpCodes.UNAUTHORIZED).send("Not authorized with this office"); response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office");
return; return;
} }
if (deed) { if (deed) {
const deedService = Container.get(DeedsService); const deedTypeService = Container.get(DeedTypesService);
const deedWithOffice = await deedService.getByUidWithOffice(deed.uid!); console.log("deed : ",deed);
if (!deedWithOffice) { const deedTypeWithOffice = await deedTypeService.getByUidWithOffice(deed.deed_type.uid!);
response.sendStatus(HttpCodes.NOT_FOUND); if (!deedTypeWithOffice) {
response.status(HttpCodes.NOT_FOUND).send("Deed type not found");
return; return;
} }
if (deedWithOffice.deed_type.office.uid != officeId) { if (deedTypeWithOffice.office.uid != officeId) {
response.status(HttpCodes.UNAUTHORIZED).send("Not authorized with this deed type"); response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this deed type");
return; return;
} }
} }
@ -51,7 +52,7 @@ export default async function folderHandler(req: Request, response: Response, ne
} }
if (officeFolder.office.uid != officeId) { 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; return;
} }
} }

View File

@ -9,7 +9,7 @@ export default async function officeRoleHandler(req: Request, response: Response
const office = req.body.office; const office = req.body.office;
if (office && office.uid != officeId) { 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; return;
} }
@ -23,7 +23,7 @@ export default async function officeRoleHandler(req: Request, response: Response
} }
if (officeRole.office.uid != officeId) { 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; return;
} }
} }

View File

@ -9,7 +9,7 @@ export default async function userHandler(req: Request, response: Response, next
const office = req.body.office_membership; const office = req.body.office_membership;
if (office && office.uid != officeId) { 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; return;
} }
@ -23,7 +23,7 @@ export default async function userHandler(req: Request, response: Response, next
} }
if (user.office_membership.uid != officeId) { 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; return;
} }
} }

View File

@ -8,12 +8,12 @@ export default async function ruleHandler(req: Request, response: Response, next
const role = req.body.user.role; const role = req.body.user.role;
if (namespace != "notary" && role != namespace) { 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; return;
} }
if (!rules.includes(req.method + " " + service)) { 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; return;
} }