add document types control on office ownership
This commit is contained in:
parent
c2856de59a
commit
4e632e27ed
@ -3,6 +3,7 @@ import DeedsService from "@Services/super-admin/DeedsService/DeedsService";
|
||||
import { DocumentType } from "le-coffre-resources/dist/SuperAdmin";
|
||||
import { NextFunction, Request, Response } from "express";
|
||||
import Container from "typedi";
|
||||
import DocumentTypesService from "@Services/super-admin/DocumentTypesService/DocumentTypesService";
|
||||
|
||||
export default async function deedHandler(req: Request, response: Response, next: NextFunction) {
|
||||
const officeId = req.body.user.office_Id;
|
||||
@ -22,9 +23,15 @@ export default async function deedHandler(req: Request, response: Response, next
|
||||
return;
|
||||
}
|
||||
|
||||
if(documentTypes) {
|
||||
documentTypes.forEach((documentType) => {
|
||||
if (documentType.office?.uid != officeId) {
|
||||
if (documentTypes) {
|
||||
const documentTypeService = Container.get(DocumentTypesService);
|
||||
documentTypes.forEach(async (documentType) => {
|
||||
const deedTypeWithOffice = await documentTypeService.getByUidWithOffice(documentType.uid!);
|
||||
if (!deedTypeWithOffice) {
|
||||
response.sendStatus(HttpCodes.NOT_FOUND);
|
||||
return;
|
||||
}
|
||||
if (deedTypeWithOffice.office?.uid != officeId) {
|
||||
response.sendStatus(HttpCodes.UNAUTHORIZED);
|
||||
return;
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ import DeedTypesService from "@Services/super-admin/DeedTypesService/DeedTypesSe
|
||||
import { DocumentType } from "le-coffre-resources/dist/SuperAdmin";
|
||||
import { NextFunction, Request, Response } from "express";
|
||||
import Container from "typedi";
|
||||
import DocumentTypesService from "@Services/super-admin/DocumentTypesService/DocumentTypesService";
|
||||
|
||||
export default async function deedTypeHandler(req: Request, response: Response, next: NextFunction) {
|
||||
const officeId = req.body.user.office_Id;
|
||||
@ -31,8 +32,14 @@ export default async function deedTypeHandler(req: Request, response: Response,
|
||||
}
|
||||
|
||||
if (documentTypes) {
|
||||
documentTypes.forEach((documentType) => {
|
||||
if (documentType.office?.uid != officeId) {
|
||||
const documentTypeService = Container.get(DocumentTypesService);
|
||||
documentTypes.forEach(async(documentType) => {
|
||||
const documentTypeWithOffice = await documentTypeService.getByUidWithOffice(documentType.uid!);
|
||||
if(!documentTypeWithOffice) {
|
||||
response.sendStatus(HttpCodes.NOT_FOUND);
|
||||
return;
|
||||
}
|
||||
if (documentTypeWithOffice.office?.uid != officeId) {
|
||||
response.sendStatus(HttpCodes.UNAUTHORIZED);
|
||||
return;
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import { NextFunction, Request, Response } from "express";
|
||||
import Container from "typedi";
|
||||
import { OfficeFolder } from "le-coffre-resources/dist/SuperAdmin";
|
||||
import DocumentsService from "@Services/super-admin/DocumentsService/DocumentsService";
|
||||
import DocumentTypesService from "@Services/super-admin/DocumentTypesService/DocumentTypesService";
|
||||
|
||||
export default async function documentHandler(req: Request, response: Response, next: NextFunction) {
|
||||
const officeId = req.body.user.office_Id;
|
||||
@ -16,10 +17,18 @@ export default async function documentHandler(req: Request, response: Response,
|
||||
return;
|
||||
}
|
||||
|
||||
if (documentType && documentType.office?.uid != officeId) {
|
||||
if (documentType) {
|
||||
const documentTypeService = Container.get(DocumentTypesService);
|
||||
const documentTypeWithOffice = await documentTypeService.getByUidWithOffice(documentType.uid!);
|
||||
if(!documentTypeWithOffice) {
|
||||
response.sendStatus(HttpCodes.NOT_FOUND);
|
||||
return;
|
||||
}
|
||||
if (documentTypeWithOffice.office?.uid != officeId) {
|
||||
response.sendStatus(HttpCodes.UNAUTHORIZED);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (uid) {
|
||||
const documentService = Container.get(DocumentsService);
|
||||
|
@ -14,7 +14,7 @@ export default async function fileHandler(req: Request, response: Response, next
|
||||
return;
|
||||
}
|
||||
|
||||
if(!uid) uid = req.path && req.path.split("/")[6];
|
||||
if(uid === "download") uid = req.path && req.path.split("/")[6];
|
||||
|
||||
if (uid) {
|
||||
const fileService = Container.get(FilesService);
|
||||
|
Loading…
x
Reference in New Issue
Block a user