24 lines
803 B
TypeScript
24 lines
803 B
TypeScript
import HttpCodes from "@Common/system/controller-pattern/HttpCodes";
|
|
import DocumentsService from "@Services/customer/DocumentsService/DocumentsService";
|
|
import { NextFunction, Request, Response } from "express";
|
|
import Container from "typedi";
|
|
|
|
export default async function documentHandler(req: Request, response: Response, next: NextFunction) {
|
|
const customerId = req.body.user.customerId;
|
|
const uid = req.path && req.path.split("/")[5];
|
|
|
|
if(!uid) {
|
|
response.status(HttpCodes.BAD_REQUEST).send("Missing document uid");
|
|
return;
|
|
}
|
|
|
|
const documentService = Container.get(DocumentsService);
|
|
const document = await documentService.getByUid(uid);
|
|
|
|
if(document?.depositor_uid != customerId) {
|
|
response.status(HttpCodes.UNAUTHORIZED).send("Not authorized with this depositor");
|
|
return;
|
|
}
|
|
|
|
}
|