新增批量删除用户

This commit is contained in:
eoao
2026-01-22 22:22:00 +08:00
parent 8a47418c91
commit 31dbf1a9e6
10 changed files with 125 additions and 109 deletions

View File

@@ -1,7 +1,7 @@
import BizError from "../error/biz-error";
import orm from "../entity/orm";
import {oauth} from "../entity/oauth";
import { eq } from 'drizzle-orm';
import { eq, inArray } from 'drizzle-orm';
import userService from "./user-service";
import loginService from "./login-service";
import cryptoUtils from "../utils/crypto-utils";
@@ -102,7 +102,11 @@ const oauthService = {
},
async deleteByUserId(c, userId) {
await orm(c).delete(oauth).where(eq(oauth.userId, userId)).run();
await this.deleteByUserIds(c, [userId]);
},
async deleteByUserIds(c, userIds) {
await orm(c).delete(oauth).where(inArray(oauth.userId, userIds)).run();
},
//定时任务凌晨清除未绑定邮箱的oauth用户

View File

@@ -42,10 +42,12 @@ const userService = {
user.account = account;
user.name = account.name;
user.permKeys = permKeys;
user.role = roleRow
user.role = roleRow;
user.type = userRow.type;
if (c.env.admin === userRow.email) {
user.role = constant.ADMIN_ROLE
user.type = 0;
}
return user;
@@ -98,11 +100,11 @@ const userService = {
},
async physicsDelete(c, params) {
const { userId } = params
await accountService.physicsDeleteByUserIds(c, [userId])
await oauthService.deleteByUserId(c, userId);
await orm(c).delete(user).where(eq(user.userId, userId)).run();
await c.env.kv.delete(kvConst.AUTH_INFO + userId);
let { userIds } = params;
userIds = userIds.split(',').map(Number);
await accountService.physicsDeleteByUserIds(c, userIds);
await oauthService.deleteByUserIds(c, userIds);
await orm(c).delete(user).where(inArray(user.userId, userIds)).run();
},
async list(c, params) {