Merge branch 'fix/file-handler' into dev
This commit is contained in:
commit
fc6d20afa5
@ -7,16 +7,16 @@ import DeedTypesService from "@Services/super-admin/DeedTypesService/DeedTypesSe
|
||||
export default async function folderHandler(req: Request, response: Response, next: NextFunction) {
|
||||
try {
|
||||
const officeId = req.body.user.office_Id;
|
||||
const uid = req.path && req.path.split("/")[5];
|
||||
const uid = req.path && req.path.split("/")[-1];
|
||||
const office = req.body.office;
|
||||
const officeFolderNumber = req.body.folder_number;
|
||||
const deed = req.body.deed;
|
||||
|
||||
|
||||
if (office && office.uid != officeId) {
|
||||
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (deed && deed.deed_type) {
|
||||
const deedTypeService = Container.get(DeedTypesService);
|
||||
const deedTypeWithOffice = await deedTypeService.getByUidWithOffice(deed.deed_type.uid!);
|
||||
@ -29,9 +29,9 @@ export default async function folderHandler(req: Request, response: Response, ne
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const officeFolderService = Container.get(OfficeFoldersService);
|
||||
|
||||
|
||||
if (officeFolderNumber && req.method == "POST") {
|
||||
const officeFoldersWithSameNumber = await officeFolderService.get({
|
||||
where: { folder_number: officeFolderNumber, office: { uid: officeId } },
|
||||
@ -41,23 +41,22 @@ export default async function folderHandler(req: Request, response: Response, ne
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (uid) {
|
||||
const officeFolder = await officeFolderService.getByUidWithOffice(uid!);
|
||||
|
||||
|
||||
if (!officeFolder) {
|
||||
response.status(HttpCodes.NOT_FOUND).send("Office folder not found");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (officeFolder.office.uid != officeId) {
|
||||
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
next();
|
||||
|
||||
next();
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
response.status(HttpCodes.INTERNAL_ERROR).send("Internal server error");
|
||||
|
Loading…
x
Reference in New Issue
Block a user