import { NextRequest, NextResponse } from "next/server"; import { users } from "../../mockData"; export async function PUT( request: NextRequest, { params }: { params: { id: string } } ) { const { id } = params; if (!id) { return NextResponse.json({ error: "User ID is required" }, { status: 400 }); } const body = await request.json(); const { firstName, lastName, email, phone, role } = body; // Find the user by id const userIndex = users.findIndex((u) => u.id === id); if (userIndex === -1) { return NextResponse.json({ error: "User not found" }, { status: 404 }); } // Update the user fields users[userIndex] = { ...users[userIndex], firstName: firstName ?? users[userIndex].firstName, lastName: lastName ?? users[userIndex].lastName, email: email ?? users[userIndex].email, phone: phone ?? users[userIndex].phone, authorities: role ? [role] : users[userIndex].authorities, }; return NextResponse.json(users[userIndex], { status: 200 }); }