fix document & file middleware for customers
This commit is contained in:
parent
aaa0d9ba21
commit
78c7364a81
@ -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);
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user