diff --git a/src/app/api/customer/FilesController.ts b/src/app/api/customer/FilesController.ts index d5db8206..1cbe6b52 100644 --- a/src/app/api/customer/FilesController.ts +++ b/src/app/api/customer/FilesController.ts @@ -31,10 +31,15 @@ export default class FilesController extends ApiController { if (req.query["q"]) { query = JSON.parse(req.query["q"] as string); } - const customerId: string = req.body.user.customerId; - const customerWhereInput: Prisma.FilesWhereInput = { document: { depositor: { uid: customerId } } }; + const email: string = req.body.user.email; + if (!email) { + this.httpBadRequest(response, "Missing customer email"); + return; + } + if (query.where?.document?.depositor) delete query.where.document.depositor; + const customerWhereInput: Prisma.FilesWhereInput = { ...query.where, document: {depositor: { contact: { email: email } } }}; query.where = customerWhereInput; - if(query.include?.document) delete query.include.document; + if (query.include?.document) delete query.include.document; //call service to get prisma entity const fileEntities = await this.filesService.get(query); diff --git a/src/app/middlewares/CustomerHandler/DocumentHandler.ts b/src/app/middlewares/CustomerHandler/DocumentHandler.ts index 5f390ba7..2bd74e8a 100644 --- a/src/app/middlewares/CustomerHandler/DocumentHandler.ts +++ b/src/app/middlewares/CustomerHandler/DocumentHandler.ts @@ -3,9 +3,9 @@ import DocumentsService from "@Services/customer/DocumentsService/DocumentsServi import Document from "le-coffre-resources/dist/SuperAdmin/Document"; import { NextFunction, Request, Response } from "express"; import Container from "typedi"; -import ContactsService from "@Services/common/ContactService/ContactService"; import OfficeFoldersService from "@Services/super-admin/OfficeFoldersService/OfficeFoldersService"; import { OfficeFolder } from "le-coffre-resources/dist/SuperAdmin"; +import CustomersService from "@Services/super-admin/CustomersService/CustomersService"; export default async function documentHandler(req: Request, response: Response, next: NextFunction) { try { @@ -23,8 +23,8 @@ export default async function documentHandler(req: Request, response: Response, } if (document?.depositor_uid != customerId) { - const contactService = Container.get(ContactsService); - const customers = await contactService.getByEmail(customerEmail); + const customerService = Container.get(CustomersService); + const customers = await customerService.get({where: {contact: { email: customerEmail}}}); if (customers && !customers.find((customer) => customer.uid === document?.depositor_uid)) { response.status(HttpCodes.UNAUTHORIZED).send("Not authorized with this depositor"); return;