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) {
|
export default async function folderHandler(req: Request, response: Response, next: NextFunction) {
|
||||||
try {
|
try {
|
||||||
const officeId = req.body.user.office_Id;
|
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 office = req.body.office;
|
||||||
const officeFolderNumber = req.body.folder_number;
|
const officeFolderNumber = req.body.folder_number;
|
||||||
const deed = req.body.deed;
|
const deed = req.body.deed;
|
||||||
|
|
||||||
if (office && office.uid != officeId) {
|
if (office && office.uid != officeId) {
|
||||||
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office");
|
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (deed && deed.deed_type) {
|
if (deed && deed.deed_type) {
|
||||||
const deedTypeService = Container.get(DeedTypesService);
|
const deedTypeService = Container.get(DeedTypesService);
|
||||||
const deedTypeWithOffice = await deedTypeService.getByUidWithOffice(deed.deed_type.uid!);
|
const deedTypeWithOffice = await deedTypeService.getByUidWithOffice(deed.deed_type.uid!);
|
||||||
@ -29,9 +29,9 @@ export default async function folderHandler(req: Request, response: Response, ne
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const officeFolderService = Container.get(OfficeFoldersService);
|
const officeFolderService = Container.get(OfficeFoldersService);
|
||||||
|
|
||||||
if (officeFolderNumber && req.method == "POST") {
|
if (officeFolderNumber && req.method == "POST") {
|
||||||
const officeFoldersWithSameNumber = await officeFolderService.get({
|
const officeFoldersWithSameNumber = await officeFolderService.get({
|
||||||
where: { folder_number: officeFolderNumber, office: { uid: officeId } },
|
where: { folder_number: officeFolderNumber, office: { uid: officeId } },
|
||||||
@ -41,23 +41,22 @@ export default async function folderHandler(req: Request, response: Response, ne
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uid) {
|
if (uid) {
|
||||||
const officeFolder = await officeFolderService.getByUidWithOffice(uid!);
|
const officeFolder = await officeFolderService.getByUidWithOffice(uid!);
|
||||||
|
|
||||||
if (!officeFolder) {
|
if (!officeFolder) {
|
||||||
response.status(HttpCodes.NOT_FOUND).send("Office folder not found");
|
response.status(HttpCodes.NOT_FOUND).send("Office folder not found");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (officeFolder.office.uid != officeId) {
|
if (officeFolder.office.uid != officeId) {
|
||||||
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office");
|
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
next();
|
|
||||||
|
|
||||||
|
next();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
response.status(HttpCodes.INTERNAL_ERROR).send("Internal server error");
|
response.status(HttpCodes.INTERNAL_ERROR).send("Internal server error");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user