const User = require("../../../models").users;
const Profile = require("../../../models").profiles;
const Roles = require("../../../models").roles;
const Department = require("../../../models").departments;
const CryptoJS = require("crypto-js");
var key = CryptoJS.enc.Base64.parse("4gt71TxD1e4P3433");
var iv  = CryptoJS.enc.Base64.parse("4gt71TxD1e4P3433");
const {randomString} = require("../../helpers/randomString");


exports.adminUser =  async (req, res) =>{
try {
    let allRoles = []
    const roles = await Roles.findAll({where:{active:true}});
    for (const role of roles){
        const userCount = await User.count({
            where:{
                second_role:role.id
            }
        })
        allRoles.push({
            role:role.alias,
            count:userCount
        });
    }
    return res.render("admin/roles.ejs", 
    {
        user: req.user, 
        sessions:req.sessions,
        roles:allRoles,
    } )
} catch (error) {
    console.log(error)
    return res.status(500).send({success:false, message:error.message});
}
};