const system = require("../../../system");
const Dao = require("../../dao.base");
class RoleauthDao extends Dao {
  constructor() {
    super(Dao.getModelName(RoleauthDao));
  }

  async delByRoleId(role_id, t) {
    var sql = "DELETE FROM uc_role_auth WHERE role_id = :role_id";
    await this.customUpdate(sql, {
      role_id: role_id
    }, t) || [];
  }

  async authIdsByRoleIds(roleIds) {
    if (!roleIds || roleIds.length == 0) {
      return [];
    }
    let sql = "SELECT auth_id FROM uc_role_auth WHERE role_id IN (:roleIds)";
    let roles = await this.customQuery(sql, {roleIds: roleIds});
    if (!roles || roles.length == 0) {
      return [];
    }

    let rs = [];
    for (let role of roles) {
      rs.push(role.auth_id);
    }
    return rs;
  }
}
module.exports = RoleauthDao;