import { dataSource } from "../../data-source"; import { role } from "../../entity/management/role"; import DatabaseActionException from "../../exceptions/databaseActionException"; import InternalException from "../../exceptions/internalException"; export default abstract class RoleService { /** * @description get roles * @returns {Promise>} */ static async getAll(): Promise> { return await dataSource .getRepository(role) .createQueryBuilder("role") .leftJoinAndSelect("role.permissions", "role_permissions") .orderBy("role", "ASC") .getMany() .then((res) => { return res; }) .catch((err) => { throw new DatabaseActionException("SELECT", "roles", err); }); } /** * @description get role by id * @param id number * @returns {Promise} */ static async getById(id: number): Promise { return await dataSource .getRepository(role) .createQueryBuilder("role") .leftJoinAndSelect("role.permissions", "role_permissions") .where("role.id = :id", { id: id }) .getOneOrFail() .then((res) => { return res; }) .catch((err) => { throw new DatabaseActionException("SELECT", "role", err); }); } }