import { Request, Response, NextFunction } from "express";

export const roleMiddleware =
(allowedRoles: string[]) => {

    return (
        req: any,
        res: Response,
        next: NextFunction
    ) => {

        const userRole =
        req.user.roleName;

        if (
            !allowedRoles.includes(
                userRole
            )
        ) {

            return res.status(403).json({
                message:
                "No tiene permisos para realizar esta acción"
            });
        }

        next();
    };
};