import HttpCodes from "@Common/system/controller-pattern/HttpCodes"; import { NextFunction, Request, Response } from "express"; import Container from "typedi"; import CustomersService from "@Services/super-admin/CustomersService/CustomersService"; export default async function customerHandler(req: Request, response: Response, next: NextFunction) { try { const officeId = req.body.user.office_Id; const uid = req.path && req.path.split("/")[5]; if (uid) { const customerService = Container.get(CustomersService); const customer = await customerService.get({where:{AND: [{uid: uid}, {office_folders: {some: {office_uid: officeId}}}]}}); if (!customer[0]) { response.status(HttpCodes.NOT_FOUND).send("Customer not found"); return; } } next(); } catch (error) { console.log(error); response.status(HttpCodes.INTERNAL_ERROR).send("Internal server error"); return; } }