add notification middlewares
This commit is contained in:
parent
e72d4e9203
commit
6ceb96ea4c
@ -70,6 +70,7 @@ export default class DocumentsController extends ApiController {
|
|||||||
if (req.query["q"]) {
|
if (req.query["q"]) {
|
||||||
query = JSON.parse(req.query["q"] as string);
|
query = JSON.parse(req.query["q"] as string);
|
||||||
if (query.folder) delete query.folder;
|
if (query.folder) delete query.folder;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const documentEntity = await this.documentsService.getByUid(uid, query);
|
const documentEntity = await this.documentsService.getByUid(uid, query);
|
||||||
@ -85,6 +86,7 @@ export default class DocumentsController extends ApiController {
|
|||||||
//success
|
//success
|
||||||
this.httpSuccess(response, document);
|
this.httpSuccess(response, document);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
this.httpInternalError(response);
|
this.httpInternalError(response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import UserNotification from "le-coffre-resources/dist/Notary/UserNotification";
|
|||||||
import UserNotificationService from "@Services/common/UserNotificationService/UserNotificationService";
|
import UserNotificationService from "@Services/common/UserNotificationService/UserNotificationService";
|
||||||
import authHandler from "@App/middlewares/AuthHandler";
|
import authHandler from "@App/middlewares/AuthHandler";
|
||||||
import { Prisma } from "@prisma/client";
|
import { Prisma } from "@prisma/client";
|
||||||
|
import roleHandler from "@App/middlewares/RolesHandler";
|
||||||
|
|
||||||
@Controller()
|
@Controller()
|
||||||
@Service()
|
@Service()
|
||||||
@ -17,7 +18,7 @@ export default class UserNotificationController extends ApiController {
|
|||||||
/**
|
/**
|
||||||
* @description Get all customers
|
* @description Get all customers
|
||||||
*/
|
*/
|
||||||
@Get("/api/v1/notary/notifications", [authHandler])
|
@Get("/api/v1/notary/notifications", [authHandler, roleHandler])
|
||||||
protected async get(req: Request, response: Response) {
|
protected async get(req: Request, response: Response) {
|
||||||
try {
|
try {
|
||||||
//get query
|
//get query
|
||||||
@ -51,7 +52,7 @@ export default class UserNotificationController extends ApiController {
|
|||||||
/**
|
/**
|
||||||
* @description Modify a specific customer by uid
|
* @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) {
|
protected async put(req: Request, response: Response) {
|
||||||
try {
|
try {
|
||||||
const uid = req.params["uid"];
|
const uid = req.params["uid"];
|
||||||
@ -94,7 +95,7 @@ export default class UserNotificationController extends ApiController {
|
|||||||
/**
|
/**
|
||||||
* @description Get a specific customer by uid
|
* @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) {
|
protected async getOneByUid(req: Request, response: Response) {
|
||||||
try {
|
try {
|
||||||
const uid = req.params["uid"];
|
const uid = req.params["uid"];
|
||||||
|
@ -7,6 +7,11 @@ export default async function roleHandler(req: Request, response: Response, next
|
|||||||
const namespace = req.path && req.path.split("/")[3];
|
const namespace = req.path && req.path.split("/")[3];
|
||||||
const role = req.body.user.role;
|
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") {
|
if (namespace != "notary" && role != namespace && role != "super-admin") {
|
||||||
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this role");
|
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this role");
|
||||||
return;
|
return;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user