"use strict";async function cacheRoles(){try{const e=await getRoles();await redis.set("roles",JSON.stringify(e),"EX",3600)}catch(e){console_1.logger.error("ROLE","Redis error",e)}}async function getRoles(){return(await db_1.models.role.findAll({include:[{model:db_1.models.permission,as:"permissions",through:{attributes:[]}}]})).map(e=>e.get({plain:!0}))}async function getRole(e){const s=await db_1.models.role.findOne({where:{id:e},include:[{model:db_1.models.permission,as:"permissions",through:{attributes:[]}}]});return s?s.get({plain:!0}):null}Object.defineProperty(exports,"__esModule",{value:!0});exports.roleStoreSchema=exports.roleUpdateSchema=exports.baseRoleSchema=void 0;exports.cacheRoles=cacheRoles;exports.getRoles=getRoles;exports.getRole=getRole;const db_1=require("@b/db"),redis_1=require("@b/utils/redis"),console_1=require("@b/utils/console"),redis=redis_1.RedisSingleton.getInstance();cacheRoles();const schema_1=require("@b/utils/schema"),id=(0,schema_1.baseStringSchema)("ID of the role"),name=(0,schema_1.baseStringSchema)("Name of the role"),permissions={type:"array",items:{type:"string",description:"ID of the permission"}};exports.baseRoleSchema={id:id,name:name,permissions:permissions};exports.roleUpdateSchema={type:"object",properties:{name:name,permissions:permissions},required:["name","permissions"]};exports.roleStoreSchema={description:"Role created or updated successfully",content:{"application/json":{schema:{type:"object",properties:exports.baseRoleSchema}}}};