Add user management admin page with role, status, and profile editing
- New /users page with search, inline editing, role/status changes, and deletion - Model: added updateUserRole, updateUserStatus, deleteUser functions - API: PUT /api/v1/users/[id] now supports role and status fields, added DELETE - Safety: cannot change own role/status or delete own account Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -142,3 +142,27 @@ export async function promoteToAdmin(userId: number): Promise<void> {
|
||||
})
|
||||
.where(eq(users.id, userId));
|
||||
}
|
||||
|
||||
export async function updateUserRole(userId: number, role: User["role"]): Promise<User | null> {
|
||||
const now = nowIso();
|
||||
const [updated] = await db
|
||||
.update(users)
|
||||
.set({ role, updatedAt: now })
|
||||
.where(eq(users.id, userId))
|
||||
.returning();
|
||||
return updated ? parseDbUser(updated) : null;
|
||||
}
|
||||
|
||||
export async function updateUserStatus(userId: number, status: string): Promise<User | null> {
|
||||
const now = nowIso();
|
||||
const [updated] = await db
|
||||
.update(users)
|
||||
.set({ status, updatedAt: now })
|
||||
.where(eq(users.id, userId))
|
||||
.returning();
|
||||
return updated ? parseDbUser(updated) : null;
|
||||
}
|
||||
|
||||
export async function deleteUser(userId: number): Promise<void> {
|
||||
await db.delete(users).where(eq(users.id, userId));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user