add notification middlewares

This commit is contained in:
OxSaitama 2023-10-24 10:24:03 +02:00
parent e72d4e9203
commit 6ceb96ea4c
3 changed files with 11 additions and 3 deletions

View File

@ -70,6 +70,7 @@ export default class DocumentsController extends ApiController {
if (req.query["q"]) {
query = JSON.parse(req.query["q"] as string);
if (query.folder) delete query.folder;
}
const documentEntity = await this.documentsService.getByUid(uid, query);
@ -85,6 +86,7 @@ export default class DocumentsController extends ApiController {
//success
this.httpSuccess(response, document);
} catch (error) {
console.log(error);
this.httpInternalError(response);
return;
}

View File

@ -6,6 +6,7 @@ import UserNotification from "le-coffre-resources/dist/Notary/UserNotification";
import UserNotificationService from "@Services/common/UserNotificationService/UserNotificationService";
import authHandler from "@App/middlewares/AuthHandler";
import { Prisma } from "@prisma/client";
import roleHandler from "@App/middlewares/RolesHandler";
@Controller()
@Service()
@ -17,7 +18,7 @@ export default class UserNotificationController extends ApiController {
/**
* @description Get all customers
*/
@Get("/api/v1/notary/notifications", [authHandler])
@Get("/api/v1/notary/notifications", [authHandler, roleHandler])
protected async get(req: Request, response: Response) {
try {
//get query
@ -51,7 +52,7 @@ export default class UserNotificationController extends ApiController {
/**
* @description Modify a specific customer by uid
*/
@Put("/api/v1/notary/notifications/:uid", [authHandler])
@Put("/api/v1/notary/notifications/:uid", [authHandler, roleHandler])
protected async put(req: Request, response: Response) {
try {
const uid = req.params["uid"];
@ -94,7 +95,7 @@ export default class UserNotificationController extends ApiController {
/**
* @description Get a specific customer by uid
*/
@Get("/api/v1/notary/notifications/:uid", [authHandler])
@Get("/api/v1/notary/notifications/:uid", [authHandler, roleHandler])
protected async getOneByUid(req: Request, response: Response) {
try {
const uid = req.params["uid"];

View File

@ -7,6 +7,11 @@ export default async function roleHandler(req: Request, response: Response, next
const namespace = req.path && req.path.split("/")[3];
const role = req.body.user.role;
if(!role) {
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized without role");
return;
}
if (namespace != "notary" && role != namespace && role != "super-admin") {
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this role");
return;