import { getNocoDbConfiguration } from "../utils/nocodb"; import { requireAuth } from "../utils/auth"; export default defineEventHandler(async (event) => { console.log('[get-berth-by-id] Request received'); // Check authentication (x-tag header OR Keycloak session) await requireAuth(event); try { const query = getQuery(event); const berthId = query.id; if (!berthId) { throw createError({ statusCode: 400, statusMessage: "Berth ID is required" }); } const config = getNocoDbConfiguration(); const berthsTableId = "mczgos9hr3oa9qc"; console.log('[get-berth-by-id] Fetching berth with ID:', berthId); // Fetch berth with linked interested parties const berth = await $fetch(`${config.url}/api/v2/tables/${berthsTableId}/records/${berthId}`, { headers: { "xc-token": config.token, }, params: { // Expand the "Interested Parties" linked field to get full interest records fields: '*,Interested Parties.*' } }); console.log('[get-berth-by-id] Successfully fetched berth:', berthId); return berth; } catch (error) { console.error('[get-berth-by-id] Error occurred:', error); console.error('[get-berth-by-id] Error details:', error instanceof Error ? error.message : 'Unknown error'); throw error; } });