// app/api/user/route.ts import { NextRequest, NextResponse } from "next/server"; export const users = [ { merchantId: 100987998, id: "bc6a8a55-13bc-4538-8255-cd0cec3bb4e9", mame: "Jacob", username: "lspaddy", firstName: "Paddy", lastName: "Man", email: "patrick@omegasys.eu", phone: "", jobTitle: "", enabled: true, authorities: [ "ROLE_IIN", "ROLE_FIRST_APPROVER", "ROLE_RULES_ADMIN", "ROLE_TRANSACTION_VIEWER", "ROLE_IIN_ADMIN", "ROLE_USER_PSP_ACCOUNT", ], allowedMerchantIds: [100987998], created: "2025-05-04T15:32:48.432Z", disabledBy: null, disabledDate: null, disabledReason: null, incidentNotes: false, lastLogin: "", lastMandatoryUpdated: "2025-05-04T15:32:48.332Z", marketingNewsletter: false, releaseNotes: false, requiredActions: ["CONFIGURE_TOTP", "UPDATE_PASSWORD"], twoFactorCondition: "required", twoFactorCredentials: [], }, { merchantId: 100987998, mame: "Jacob", id: "382eed15-1e21-41fa-b1f3-0c1adb3af714", username: "lsterence", firstName: "Terence", lastName: "User", email: "terence@omegasys.eu", phone: "", jobTitle: "", enabled: true, authorities: ["ROLE_IIN", "ROLE_FIRST_APPROVER", "ROLE_RULES_ADMIN"], allowedMerchantIds: [100987998], created: "2025-05-04T15:32:48.432Z", disabledBy: null, disabledDate: null, disabledReason: null, incidentNotes: false, lastLogin: "", lastMandatoryUpdated: "2025-05-04T15:32:48.332Z", marketingNewsletter: false, releaseNotes: false, requiredActions: ["CONFIGURE_TOTP", "UPDATE_PASSWORD"], twoFactorCondition: "required", twoFactorCredentials: [], }, ]; export async function GET() { return NextResponse.json(users); } export async function POST(request: NextRequest) { const body = await request.json(); // Use the first user as a template const templateUser = users[0]; // Create the new user by spreading the template and then the body (body fields override template) const newUser = { ...templateUser, ...body, id: typeof crypto !== "undefined" && crypto.randomUUID ? crypto.randomUUID() : Math.random().toString(36).substring(2, 15), created: new Date().toISOString(), }; users.push(newUser); return NextResponse.json(newUser, { status: 201 }); } // To call the POST function from the client side, you can use fetch like this: /* Example usage in a React component or any client-side JS: const createUser = async (userData) => { const res = await fetch('/api/dashboard/admin/users', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify(userData), }); if (!res.ok) { // handle error throw new Error('Failed to create user'); } const newUser = await res.json(); return newUser; }; // Usage: createUser({ username: "newuser", firstName: "New", lastName: "User", email: "newuser@example.com", // ...other fields as needed }).then(user => { console.log('Created user:', user); }).catch(err => { console.error(err); }); */