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) {
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;
}
});

View File

@ -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;
}
});

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}