diff --git a/server/src/service/user.service.ts b/server/src/service/user.service.ts index eccf7f5..104f4b7 100644 --- a/server/src/service/user.service.ts +++ b/server/src/service/user.service.ts @@ -21,7 +21,10 @@ export class UserService { async list(query: { page?: any; pageSize?: any; keyword?: string; status?: number; roleId?: number }): Promise { const page = Number(query.page) || 1; const pageSize = Number(query.pageSize) || 10; - const where: any = {}; + // 排除内置管理员账号(id=1) + const where: any = { + id: { [Op.ne]: 1 } + }; if (query.keyword) { where[Op.or] = [{ username: { [Op.like]: `%${query.keyword}%` } }, { realName: { [Op.like]: `%${query.keyword}%` } }, { phone: { [Op.like]: `%${query.keyword}%` } }]; @@ -154,6 +157,15 @@ export class UserService { } async update(id: string, data: any): Promise { + // 禁止编辑内置管理员账号 + if (Number(id) === 1) { + return { + code: 400, + message: "内置管理员账号不允许编辑", + data: null + }; + } + const user = await this.userModel.findByPk(id); if (!user) { @@ -282,6 +294,15 @@ export class UserService { } async updateStatus(id: string, status: number): Promise { + // 禁止修改内置管理员账号状态 + if (Number(id) === 1) { + return { + code: 400, + message: "内置管理员账号状态不允许修改", + data: null + }; + } + const user = await this.userModel.findByPk(id); if (!user) {