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