const jwt = require('jsonwebtoken')
const User = require("../../models").users
const Role = require("../../models").roles

const staff = async (req, res, next) => {
    try {
        const userRole = await Role.findAll({
            where:{
                active:1, //1 Active
            }
        })


       if(req.user.role != userRole[1].name){
        return res.status(401).send({
            statusCode: "401",
            success: false,
            message: "Error",
            error: `You are not authorised to have access to Super Admin dashboard`
        })
       }
       next()
       
    } catch (e) {
        console.log()
        return res.status(401).send({
            statusCode: "401",
            success: false,
            message: "Error",
            error: e.message
        })
    }

}

module.exports = staff