import { dataSource } from "../data-source"; import { rolePermission } from "../entity/role_permission"; import { userPermission } from "../entity/user_permission"; import InternalException from "../exceptions/internalException"; export default abstract class RolePermissionService { /** * @description get permission by role * @param roleId number * @returns {Promise>} */ static async getByRole(roleId: number): Promise> { return await dataSource .getRepository(rolePermission) .createQueryBuilder("permission") .where("permission.roleId = :roleId", { roleId: roleId }) .getMany() .then((res) => { return res; }) .catch((err) => { throw new InternalException("permissions not found by role", err); }); } /** * @description get permission by roles * @param roleIds Array * @returns {Promise>} */ static async getByRoles(roleIds: Array): Promise> { return await dataSource .getRepository(rolePermission) .createQueryBuilder("permission") .where("permission.roleId IN (:...roleIds)", { roleIds: roleIds }) .getMany() .then((res) => { return res; }) .catch((err) => { throw new InternalException("permissions not found by roles", err); }); } }