mirror of
https://github.com/rmoren97/mc-manager.git
synced 2026-03-28 17:26:47 -07:00
fix: update server admin route
This commit is contained in:
parent
8b856b4b8d
commit
bb6844a20b
@ -4,6 +4,7 @@ import connectToDatabase from '@/lib/mongodb'
|
||||
import { Server, User } from '@/lib/models'
|
||||
import { isValidObjectId } from '@/lib/input-validation'
|
||||
import { createAuditLog, getClientIP } from '@/lib/audit'
|
||||
import mongoose from 'mongoose'
|
||||
|
||||
// DELETE /api/servers/[id]/admins/[userId] — Remove a server admin
|
||||
export async function DELETE(
|
||||
@ -42,11 +43,13 @@ export async function DELETE(
|
||||
return NextResponse.json({ error: 'Cannot remove the last admin from a server' }, { status: 400 })
|
||||
}
|
||||
|
||||
server.admins = server.admins.filter((a) => a.toString() !== userId)
|
||||
await server.save()
|
||||
|
||||
const removedUser = await User.findById(userId, { username: 1 }).lean()
|
||||
|
||||
await Server.updateOne(
|
||||
{ _id: id },
|
||||
{ $pull: { admins: new mongoose.Types.ObjectId(userId) } }
|
||||
)
|
||||
|
||||
await createAuditLog({
|
||||
action: 'server_admin_removed',
|
||||
entityType: 'server',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user