2025-06-03 21:04:22 +02:00
|
|
|
import { createInterest } from "../utils/nocodb";
|
2025-06-15 16:13:22 +02:00
|
|
|
import { requireAuth } from "../utils/auth";
|
2025-06-03 21:04:22 +02:00
|
|
|
|
|
|
|
|
export default defineEventHandler(async (event) => {
|
2025-06-15 16:13:22 +02:00
|
|
|
console.log('[create-interest] Request received');
|
2025-06-03 21:04:22 +02:00
|
|
|
|
2025-06-15 16:13: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);
|
2025-06-09 23:19:52 +02:00
|
|
|
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) {
|
2025-06-09 23:19:52 +02:00
|
|
|
console.error('[create-interest] No data provided');
|
2025-06-03 21:04:22 +02:00
|
|
|
throw createError({ statusCode: 400, statusMessage: "No data provided" });
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-09 23:19:52 +02:00
|
|
|
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);
|
2025-06-09 23:19:52 +02:00
|
|
|
console.log('[create-interest] Successfully created interest with ID:', createdInterest.Id);
|
|
|
|
|
|
2025-06-03 21:04:22 +02:00
|
|
|
return createdInterest;
|
|
|
|
|
} catch (error) {
|
2025-06-09 23:19:52 +02:00
|
|
|
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",
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|