| 1234567891011121314151617181920 |
- import { DataSource } from 'typeorm';
- import { Role } from '../entities/role.entity';
- import { GenericCrudService } from '@d8d/shared-crud';
- export class RoleService extends GenericCrudService<Role> {
- constructor(dataSource: DataSource) {
- super(dataSource, Role);
- }
- // 可以添加角色特有的业务逻辑方法
- async getRoleByName(name: string): Promise<Role | null> {
- return this.repository.findOneBy({ name });
- }
- async hasPermission(roleId: number, permission: string): Promise<boolean> {
- const role = await this.getById(roleId);
- if (!role) return false;
- return role.permissions.includes(permission);
- }
- }
|