🚚 delete filesNotaryHandler middleware

This commit is contained in:
Max S 2024-09-10 18:38:15 +02:00
parent bcd12b5317
commit 95f2c8a8bc
2 changed files with 2 additions and 51 deletions

View File

@ -1,5 +1,4 @@
import authHandler from "@App/middlewares/AuthHandler"; import authHandler from "@App/middlewares/AuthHandler";
import FilesNotaryHandler from "@App/middlewares/OfficeMembershipHandlers/FilesNotaryHandler";
import ApiController from "@Common/system/controller-pattern/ApiController"; import ApiController from "@Common/system/controller-pattern/ApiController";
import { Controller, Get } from "@ControllerPattern/index"; import { Controller, Get } from "@ControllerPattern/index";
import { Prisma } from "@prisma/client"; import { Prisma } from "@prisma/client";
@ -52,7 +51,7 @@ export default class FilesNotaryController extends ApiController {
/** /**
* @description Get a specific File by uid * @description Get a specific File by uid
*/ */
@Get("/api/v1/notary/files-notary/download/:uid", [authHandler, FilesNotaryHandler]) @Get("/api/v1/notary/files-notary/download/:uid", [authHandler])
protected async download(req: Request, response: Response) { protected async download(req: Request, response: Response) {
const uid = req.params["uid"]; const uid = req.params["uid"];
if (!uid) { if (!uid) {
@ -80,7 +79,7 @@ export default class FilesNotaryController extends ApiController {
/** /**
* @description Get a specific File by uid * @description Get a specific File by uid
*/ */
@Get("/api/v1/notary/files-notary/:uid", [authHandler, FilesNotaryHandler]) @Get("/api/v1/notary/files-notary/:uid", [authHandler])
protected async getOneByUid(req: Request, response: Response) { protected async getOneByUid(req: Request, response: Response) {
try { try {
const uid = req.params["uid"]; const uid = req.params["uid"];

View File

@ -1,48 +0,0 @@
import HttpCodes from "@Common/system/controller-pattern/HttpCodes";
import FilesNotaryService from "@Services/common/FilesNotaryService/FilesService";
import DocumentsNotaryService from "@Services/notary/DocumentsNotaryService/DocumentsNotaryService";
import { NextFunction, Request, Response } from "express";
import Container from "typedi";
export default async function FilesNotaryHandler(req: Request, response: Response, next: NextFunction) {
try {
const officeId = req.body.user.office_Id;
let uid = req.path && req.path.split("/")[5];
const document = req.body.document;
if (document) {
const documentService = Container.get(DocumentsNotaryService);
const documentWithOffice = await documentService.getByUidWithOffice(document.uid!);
if (!documentWithOffice) {
response.status(HttpCodes.NOT_FOUND).send("Document not found");
return;
}
if (documentWithOffice.folder.office?.uid != officeId) {
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office");
return;
}
}
if (uid === "download") uid = req.path && req.path.split("/")[6];
if (uid) {
const fileService = Container.get(FilesNotaryService);
const file = await fileService.getByUidWithOffice(uid!);
if (!file) {
response.status(HttpCodes.NOT_FOUND).send("File not found");
return;
}
if (file.document_notary.folder.office.uid != officeId) {
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office");
return;
}
}
next();
} catch (error) {
console.error(error);
response.status(HttpCodes.INTERNAL_ERROR).send("Internal server error");
return;
}
}