port-nimara-client-portal/server/api/create-interest.ts

38 lines
1.3 KiB
TypeScript
Raw Normal View History

2025-06-03 21:04:22 +02:00
import { createInterest } from "../utils/nocodb";
import { requireAuth } from "../utils/auth";
2025-06-03 21:04:22 +02:00
export default defineEventHandler(async (event) => {
console.log('[create-interest] Request received');
2025-06-03 21:04:22 +02:00
// Check authentication (x-tag header OR Keycloak session)
await requireAuth(event);
2025-06-03 21:04:22 +02:00
try {
const body = await readBody(event);
console.log('[create-interest] Request body fields:', body ? Object.keys(body) : 'none');
2025-06-03 21:04:22 +02:00
if (!body || Object.keys(body).length === 0) {
console.error('[create-interest] No data provided');
2025-06-03 21:04:22 +02:00
throw createError({ statusCode: 400, statusMessage: "No data provided" });
}
console.log('[create-interest] Creating new interest with fields:', Object.keys(body));
2025-06-03 21:04:22 +02:00
const createdInterest = await createInterest(body);
console.log('[create-interest] Successfully created interest with ID:', createdInterest.Id);
2025-06-03 21:04:22 +02:00
return createdInterest;
} catch (error) {
console.error('[create-interest] Error occurred:', error);
console.error('[create-interest] Error stack:', error instanceof Error ? error.stack : 'No stack trace');
2025-06-03 21:04:22 +02:00
if (error instanceof Error) {
throw createError({ statusCode: 500, statusMessage: error.message });
} else {
throw createError({
statusCode: 500,
statusMessage: "An unexpected error occurred",
});
}
}
});