fix: 修复无法设置角色的bug

pull/213/head
xiaojunnuo 2024-10-15 11:55:59 +08:00
parent e85b441f60
commit 02fe704769
3 changed files with 39 additions and 15 deletions

View File

@ -59,26 +59,42 @@ export abstract class BaseService<T> {
return await this.getRepository().find(options);
}
/**
*
* @param where
*/
async deleteWhere(where: any) {
await this.getRepository().delete({
...where,
});
}
/**
*
* @param ids ID [1,2,3] 1,2,3
* @param where
*/
async delete(ids: any, where?: any) {
async delete(ids: string | any[], where?: any) {
const idArr = this.resolveIdArr(ids);
if (idArr.length === 0) {
return;
}
await this.getRepository().delete({
id: In(idArr),
...where,
});
await this.modifyAfter(idArr);
}
resolveIdArr(ids: string | any[]) {
if (!ids) {
throw new ValidateException('ids不能为空');
}
if (typeof ids === 'string') {
ids = ids.split(',');
return ids.split(',');
} else {
return ids;
}
if (ids.length === 0) {
return;
}
await this.getRepository().delete({
id: In(ids),
...where,
});
await this.modifyAfter(ids);
}
/**

View File

@ -237,7 +237,7 @@ export class PipelineService extends BaseService<PipelineEntity> {
});
}
async delete(id: number) {
async delete(id: any) {
await this.clearTriggers(id);
//TODO 删除storage
// const storage = new DbStorage(pipeline.userId, this.storageService);

View File

@ -29,8 +29,8 @@ export class RoleService extends BaseService<RoleEntity> {
ttl: 1000 * 60 * 10,
});
//@ts-ignore
getRepository() {
//@ts-ignore
getRepository() {
return this.repository;
}
@ -77,7 +77,7 @@ getRepository() {
return;
}
//先删除所有
await this.userRoleService.delete({ userId });
await this.userRoleService.deleteWhere({ userId });
//再添加
await this.addRoles(userId, roles);
@ -95,7 +95,7 @@ getRepository() {
}
async authz(roleId: any, permissionIds: any) {
await this.rolePermissionService.delete({ roleId });
await this.rolePermissionService.deleteWhere({ roleId });
for (const permissionId of permissionIds) {
await this.rolePermissionService.add({
roleId,
@ -125,4 +125,12 @@ getRepository() {
this.permissionCache.set(roleIdsKey, permissionSet);
return permissionSet;
}
async delete(id: any) {
const idArr = this.resolveIdArr(id);
const urs = await this.userRoleService.find({ where: { roleId: In(idArr) } });
if (urs.length > 0) {
throw new Error('该角色已被用户使用,无法删除');
}
}
}