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(Number(req.user.role) == Number(userRole[3].id) || Number(req.user.role == Number(userRole[5].id) || Number(req.user.role) == Number(userRole[8].id) || Number(req.user.role) == Number(userRole[9].id) || Number(req.user.role) == Number(userRole[10].id))){
     
        next()

       }else{
        return res.render("login/staff.ejs", {
            error: {
                statusCode: "401",
                success: false,
                message: "Error",
                error: `You are not authorised to have access to staff dashboard`
            },
            success: {
                statusCode: "200",
                success: false,
                message: undefined,
        }
        }) 
       }
      
       
    } catch (e) {
        return res.render("login/staff.ejs", {
            error: {
                statusCode: "401",
                success: false,
                message: "Error",
                error:  e.message
            },
            success: {
                statusCode: "200",
                success: false,
                message: undefined,
        }
        })  
    }

}

module.exports = staff