34 lines
874 B
TypeScript
34 lines
874 B
TypeScript
// app/api/users/assign-group/route.ts
|
|
import { NextResponse } from 'next/server';
|
|
import { prisma } from '@/lib/prisma';
|
|
|
|
export async function POST(req: Request) {
|
|
try {
|
|
const body = await req.json();
|
|
const { userId, groupId } = body ?? {};
|
|
|
|
if (!userId) {
|
|
return NextResponse.json(
|
|
{ error: 'userId ist erforderlich.' },
|
|
{ status: 400 },
|
|
);
|
|
}
|
|
|
|
const normalizedGroupId =
|
|
!groupId || groupId === 'none' ? null : String(groupId);
|
|
|
|
await prisma.user.update({
|
|
where: { nwkennung: String(userId) },
|
|
data: { groupId: normalizedGroupId },
|
|
});
|
|
|
|
return NextResponse.json({ ok: true });
|
|
} catch (err) {
|
|
console.error('[POST /api/users/assign-group]', err);
|
|
return NextResponse.json(
|
|
{ error: 'Interner Serverfehler beim Aktualisieren der Gruppe.' },
|
|
{ status: 500 },
|
|
);
|
|
}
|
|
}
|