2025-06-15 16:18:29 +02:00
|
|
|
import { getInterestById } from "../utils/nocodb";
|
|
|
|
|
import { requireAuth } from "../utils/auth";
|
|
|
|
|
|
2025-05-29 07:32:13 +02:00
|
|
|
export default defineEventHandler(async (event) => {
|
2025-06-15 16:18:29 +02:00
|
|
|
console.log('[get-interest-by-id] Request received');
|
2025-05-29 07:32:13 +02:00
|
|
|
|
2025-06-15 16:18:29 +02:00
|
|
|
// Check authentication (x-tag header OR Keycloak session)
|
|
|
|
|
await requireAuth(event);
|
2025-05-29 07:32:13 +02:00
|
|
|
|
|
|
|
|
const query = getQuery(event);
|
|
|
|
|
const { id } = query;
|
2025-06-09 23:33:20 +02:00
|
|
|
console.log('[get-interest-by-id] Request for ID:', id);
|
2025-05-29 07:32:13 +02:00
|
|
|
|
|
|
|
|
if (!id) {
|
2025-06-09 23:33:20 +02:00
|
|
|
console.error('[get-interest-by-id] Missing ID in request');
|
2025-05-29 07:32:13 +02:00
|
|
|
throw createError({ statusCode: 400, statusMessage: "ID is required" });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
2025-06-09 23:33:20 +02:00
|
|
|
console.log('[get-interest-by-id] Fetching interest:', id);
|
2025-05-29 07:32:13 +02:00
|
|
|
const interest = await getInterestById(id as string);
|
2025-06-09 23:33:20 +02:00
|
|
|
console.log('[get-interest-by-id] Successfully fetched interest:', id);
|
2025-06-11 16:05:19 +02:00
|
|
|
|
|
|
|
|
// Debug documensoID field specifically
|
|
|
|
|
console.log('[get-interest-by-id] DEBUGGING documensoID field:', {
|
|
|
|
|
id: interest.Id,
|
|
|
|
|
documensoID: interest['documensoID'],
|
|
|
|
|
documensoID_type: typeof interest['documensoID'],
|
|
|
|
|
documensoID_raw: JSON.stringify(interest['documensoID']),
|
|
|
|
|
documensoID_exists: 'documensoID' in interest,
|
|
|
|
|
documensoID_truthy: !!interest['documensoID'],
|
|
|
|
|
all_keys: Object.keys(interest).filter(key => key.toLowerCase().includes('documen')),
|
|
|
|
|
signature_links: {
|
|
|
|
|
client: interest['Signature Link Client'],
|
|
|
|
|
cc: interest['Signature Link CC'],
|
|
|
|
|
developer: interest['Signature Link Developer']
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2025-05-29 07:32:13 +02:00
|
|
|
return interest;
|
2025-06-09 23:33:20 +02:00
|
|
|
} catch (error: any) {
|
|
|
|
|
console.error('[get-interest-by-id] Error occurred:', error);
|
|
|
|
|
console.error('[get-interest-by-id] Error details:', error instanceof Error ? error.message : 'Unknown error');
|
|
|
|
|
|
|
|
|
|
// Check if it's a 404 error
|
|
|
|
|
if (error.statusCode === 404 || error.status === 404) {
|
|
|
|
|
console.error('[get-interest-by-id] Interest not found with ID:', id);
|
|
|
|
|
throw createError({
|
|
|
|
|
statusCode: 404,
|
|
|
|
|
statusMessage: `Interest not found with ID: ${id}. It may have been deleted or not yet synchronized.`
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-29 07:32:13 +02:00
|
|
|
if (error instanceof Error) {
|
|
|
|
|
throw createError({ statusCode: 500, statusMessage: error.message });
|
|
|
|
|
} else {
|
|
|
|
|
throw createError({
|
|
|
|
|
statusCode: 500,
|
|
|
|
|
statusMessage: "An unexpected error occurred",
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|