实现权限管理的服务
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { Injectable } from "@nestjs/common";
|
||||
import { BadRequestException, Injectable } from "@nestjs/common";
|
||||
import { InjectRepository } from "@nestjs/typeorm";
|
||||
import { Role } from "../entities/role.entity";
|
||||
import { In, Repository } from "typeorm";
|
||||
@@ -23,4 +23,21 @@ export class RoleService {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
async create(role: Pick<Role, 'name' | 'localName'>): Promise<Role> {
|
||||
const newRole = this.roleRepository.create(role);
|
||||
return this.roleRepository.save(newRole);
|
||||
}
|
||||
|
||||
async list(): Promise<Role[]> {
|
||||
return this.roleRepository.find();
|
||||
}
|
||||
|
||||
async delete(roleId: string): Promise<void> {
|
||||
const existingRole = await this.roleRepository.findOne({ where: { id: roleId } });
|
||||
if (!existingRole) {
|
||||
throw new BadRequestException('Role not found');
|
||||
}
|
||||
await this.roleRepository.delete(existingRole.id);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user