From 95f2c8a8bc04f638e3f2806d6271005504dc3915 Mon Sep 17 00:00:00 2001 From: Max S Date: Tue, 10 Sep 2024 18:38:15 +0200 Subject: [PATCH] :truck: delete filesNotaryHandler middleware --- src/app/api/notary/FilesNotaryController.ts | 5 +- .../FilesNotaryHandler.ts | 48 ------------------- 2 files changed, 2 insertions(+), 51 deletions(-) delete mode 100644 src/app/middlewares/OfficeMembershipHandlers/FilesNotaryHandler.ts diff --git a/src/app/api/notary/FilesNotaryController.ts b/src/app/api/notary/FilesNotaryController.ts index 2fb116e2..9b7e6742 100644 --- a/src/app/api/notary/FilesNotaryController.ts +++ b/src/app/api/notary/FilesNotaryController.ts @@ -1,5 +1,4 @@ import authHandler from "@App/middlewares/AuthHandler"; -import FilesNotaryHandler from "@App/middlewares/OfficeMembershipHandlers/FilesNotaryHandler"; import ApiController from "@Common/system/controller-pattern/ApiController"; import { Controller, Get } from "@ControllerPattern/index"; import { Prisma } from "@prisma/client"; @@ -52,7 +51,7 @@ export default class FilesNotaryController extends ApiController { /** * @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) { const uid = req.params["uid"]; if (!uid) { @@ -80,7 +79,7 @@ export default class FilesNotaryController extends ApiController { /** * @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) { try { const uid = req.params["uid"]; diff --git a/src/app/middlewares/OfficeMembershipHandlers/FilesNotaryHandler.ts b/src/app/middlewares/OfficeMembershipHandlers/FilesNotaryHandler.ts deleted file mode 100644 index b3453183..00000000 --- a/src/app/middlewares/OfficeMembershipHandlers/FilesNotaryHandler.ts +++ /dev/null @@ -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; - } -}