forked from wangziqi/gongxue-base
chore: commit oxfmt formatting changes and verify artifacts
This commit is contained in:
@@ -79,7 +79,16 @@ const PRESET_ROLES: Array<{
|
||||
code: 'dormitory_supervisor',
|
||||
description: '管理宿舍相关业务',
|
||||
isSystem: true,
|
||||
permissionGroups: ['student', 'room', 'occupancy', 'expense', 'bill', 'deposit', 'log', 'dashboard'],
|
||||
permissionGroups: [
|
||||
'student',
|
||||
'room',
|
||||
'occupancy',
|
||||
'expense',
|
||||
'bill',
|
||||
'deposit',
|
||||
'log',
|
||||
'dashboard',
|
||||
],
|
||||
},
|
||||
{
|
||||
name: '老师',
|
||||
@@ -216,9 +225,7 @@ export class RbacService {
|
||||
if (dto.description !== undefined) role.description = dto.description;
|
||||
if (dto.permissionIds !== undefined) {
|
||||
role.permissions =
|
||||
dto.permissionIds.length > 0
|
||||
? await this.permRepo.findByIds(dto.permissionIds)
|
||||
: [];
|
||||
dto.permissionIds.length > 0 ? await this.permRepo.findByIds(dto.permissionIds) : [];
|
||||
}
|
||||
return this.roleRepo.save(role);
|
||||
}
|
||||
@@ -267,7 +274,7 @@ export class RbacService {
|
||||
relations: ['roles'],
|
||||
order: { createdAt: 'DESC' },
|
||||
});
|
||||
return users.map(u => ({
|
||||
return users.map((u) => ({
|
||||
id: u.id,
|
||||
username: u.username,
|
||||
name: u.name,
|
||||
@@ -275,7 +282,7 @@ export class RbacService {
|
||||
lastLoginAt: u.lastLoginAt,
|
||||
createdAt: u.createdAt,
|
||||
updatedAt: u.updatedAt,
|
||||
roles: u.roles?.map(r => ({ id: r.id, name: r.name })) || [],
|
||||
roles: u.roles?.map((r) => ({ id: r.id, name: r.name })) || [],
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -283,7 +290,11 @@ export class RbacService {
|
||||
const exists = await this.userRepo.findOne({ where: { username: dto.username } });
|
||||
if (exists) throw new Error('用户名已存在');
|
||||
const hash = await bcrypt.hash(dto.password, 10);
|
||||
const user = this.userRepo.create({ username: dto.username, passwordHash: hash, name: dto.name });
|
||||
const user = this.userRepo.create({
|
||||
username: dto.username,
|
||||
passwordHash: hash,
|
||||
name: dto.name,
|
||||
});
|
||||
if (dto.roleIds && dto.roleIds.length > 0) {
|
||||
user.roles = await this.roleRepo.findByIds(dto.roleIds);
|
||||
}
|
||||
@@ -291,7 +302,10 @@ export class RbacService {
|
||||
return { message: '用户创建成功' };
|
||||
}
|
||||
|
||||
async updateUser(id: number, dto: { username?: string; name?: string; isActive?: boolean; roleIds?: number[] }) {
|
||||
async updateUser(
|
||||
id: number,
|
||||
dto: { username?: string; name?: string; isActive?: boolean; roleIds?: number[] },
|
||||
) {
|
||||
const user = await this.userRepo.findOne({ where: { id }, relations: ['roles'] });
|
||||
if (!user) throw new Error('用户不存在');
|
||||
if (dto.username !== undefined && dto.username !== user.username) {
|
||||
@@ -302,9 +316,7 @@ export class RbacService {
|
||||
if (dto.name !== undefined) user.name = dto.name;
|
||||
if (dto.isActive !== undefined) user.isActive = dto.isActive;
|
||||
if (dto.roleIds !== undefined) {
|
||||
user.roles = dto.roleIds.length > 0
|
||||
? await this.roleRepo.findByIds(dto.roleIds)
|
||||
: [];
|
||||
user.roles = dto.roleIds.length > 0 ? await this.roleRepo.findByIds(dto.roleIds) : [];
|
||||
}
|
||||
await this.userRepo.save(user);
|
||||
return { message: '更新成功' };
|
||||
|
||||
Reference in New Issue
Block a user