fix(admin): platform/users SELECT uid not id, UPDATE WHERE user not user_id
This commit is contained in:
parent
0a02e14bda
commit
4d4a0dc886
@ -79,20 +79,20 @@ export async function PATCH(req: NextRequest) {
|
|||||||
|
|
||||||
// Get user ids from uids
|
// Get user ids from uids
|
||||||
const uidPlaceholders = ids.map((_, i) => `$${i + 1}`).join(", ");
|
const uidPlaceholders = ids.map((_, i) => `$${i + 1}`).join(", ");
|
||||||
const uidResult = await query<{ id: number }>(
|
const uidResult = await query<{ uid: string }>(
|
||||||
`SELECT id FROM "user" WHERE uid IN (${uidPlaceholders})`,
|
`SELECT uid FROM "user" WHERE uid IN (${uidPlaceholders})`,
|
||||||
ids
|
ids
|
||||||
);
|
);
|
||||||
const userIds = uidResult.rows.map((r) => r.id);
|
const uids = uidResult.rows.map((r) => r.uid);
|
||||||
|
|
||||||
if (!userIds.length) {
|
if (!uids.length) {
|
||||||
return NextResponse.json({ error: "未找到匹配的用户" }, { status: 404 });
|
return NextResponse.json({ error: "未找到匹配的用户" }, { status: 404 });
|
||||||
}
|
}
|
||||||
|
|
||||||
const idPlaceholders = userIds.map((_, i) => `$${i + 1}`).join(", ");
|
const uidPlaceholders2 = uids.map((_, i) => `$${i + 1}`).join(", ");
|
||||||
await query(
|
await query(
|
||||||
`UPDATE user_password SET is_active = $${userIds.length + 1}, updated_at = NOW() WHERE user_id IN (${idPlaceholders})`,
|
`UPDATE user_password SET is_active = $${uids.length + 1}, updated_at = NOW() WHERE "user" IN (${uidPlaceholders2})`,
|
||||||
[...userIds, isActive]
|
[...uids, isActive]
|
||||||
);
|
);
|
||||||
|
|
||||||
const adminUserId = parseInt(req.headers.get("x-admin-user-id") || "0", 10);
|
const adminUserId = parseInt(req.headers.get("x-admin-user-id") || "0", 10);
|
||||||
@ -102,13 +102,13 @@ export async function PATCH(req: NextRequest) {
|
|||||||
username: adminUsername,
|
username: adminUsername,
|
||||||
action: "update",
|
action: "update",
|
||||||
resource: "user_batch_status",
|
resource: "user_batch_status",
|
||||||
resourceId: `batch(${userIds.length})`,
|
resourceId: `batch(${uids.length})`,
|
||||||
requestParams: { uidCount: ids.length, userIdCount: userIds.length, action },
|
requestParams: { uidCount: ids.length, userIdCount: uids.length, action },
|
||||||
ipAddress: req.headers.get("x-forwarded-for") || undefined,
|
ipAddress: req.headers.get("x-forwarded-for") || undefined,
|
||||||
userAgent: req.headers.get("user-agent") || undefined,
|
userAgent: req.headers.get("user-agent") || undefined,
|
||||||
});
|
});
|
||||||
|
|
||||||
return NextResponse.json({ success: true, updated: userIds.length });
|
return NextResponse.json({ success: true, updated: uids.length });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("Batch update user status error:", e);
|
console.error("Batch update user status error:", e);
|
||||||
return NextResponse.json({ error: "服务器错误" }, { status: 500 });
|
return NextResponse.json({ error: "服务器错误" }, { status: 500 });
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user