24 lines
784 B
TypeScript
24 lines
784 B
TypeScript
|
|
import { Injectable, NotFoundException } from '@nestjs/common';
|
||
|
|
import { InjectRepository } from '@nestjs/typeorm';
|
||
|
|
import { Repository, FindOptionsOrder } from 'typeorm';
|
||
|
|
import { SysRole } from '../../entity/sysRole.entity';
|
||
|
|
|
||
|
|
@Injectable()
|
||
|
|
export class SysRoleService {
|
||
|
|
constructor(
|
||
|
|
@InjectRepository(SysRole)
|
||
|
|
private readonly roleRepo: Repository<SysRole>,
|
||
|
|
) {}
|
||
|
|
|
||
|
|
async list(siteId: number): Promise<SysRole[]> {
|
||
|
|
const order: FindOptionsOrder<SysRole> = { role_id: 'ASC' };
|
||
|
|
return this.roleRepo.find({ where: { site_id: siteId }, order });
|
||
|
|
}
|
||
|
|
|
||
|
|
async detail(roleId: number): Promise<SysRole> {
|
||
|
|
const role = await this.roleRepo.findOne({ where: { role_id: roleId } });
|
||
|
|
if (!role) throw new NotFoundException('角色不存在');
|
||
|
|
return role;
|
||
|
|
}
|
||
|
|
}
|