ff-admin-server/src/service/rolePermissionService.ts

45 lines
1.4 KiB
TypeScript
Raw Normal View History

2024-08-27 15:54:59 +00:00
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<Array<rolePermission>>}
*/
static async getByRole(roleId: number): Promise<Array<rolePermission>> {
return await dataSource
.getRepository(rolePermission)
.createQueryBuilder("permission")
.where("permission.roleId = :roleId", { roleId: roleId })
.getMany()
.then((res) => {
return res;
})
.catch((err) => {
2024-09-06 08:08:19 +00:00
throw new InternalException("permissions not found by role", err);
2024-08-27 15:54:59 +00:00
});
}
/**
* @description get permission by roles
* @param roleIds Array<number>
* @returns {Promise<Array<rolePermission>>}
*/
static async getByRoles(roleIds: Array<number>): Promise<Array<rolePermission>> {
return await dataSource
.getRepository(rolePermission)
.createQueryBuilder("permission")
.where("permission.roleId IN (:...roleIds)", { roleIds: roleIds })
.getMany()
.then((res) => {
return res;
})
.catch((err) => {
2024-09-06 08:08:19 +00:00
throw new InternalException("permissions not found by roles", err);
2024-08-27 15:54:59 +00:00
});
}
}