63 lines
1.9 KiB
TypeScript
63 lines
1.9 KiB
TypeScript
import { getBerthById } from '~/server/utils/nocodb';
|
|
import { requireAuth } from '~/server/utils/auth';
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
console.log('[test-berth-with-parties] Testing berth with interested parties...');
|
|
|
|
// Check authentication
|
|
await requireAuth(event);
|
|
|
|
try {
|
|
// Get a berth ID from query params or use a default
|
|
const query = getQuery(event);
|
|
const berthId = query.id as string || '1'; // Default to berth ID 1 (A1)
|
|
|
|
console.log('[test-berth-with-parties] Fetching berth:', berthId);
|
|
const berth = await getBerthById(berthId);
|
|
|
|
// Extract interested parties info
|
|
const interestedParties = berth['Interested Parties'];
|
|
let partiesInfo = null;
|
|
|
|
if (interestedParties) {
|
|
if (Array.isArray(interestedParties)) {
|
|
partiesInfo = {
|
|
type: 'array',
|
|
count: interestedParties.length,
|
|
parties: interestedParties.map(party => ({
|
|
id: party.Id,
|
|
name: party['Full Name'],
|
|
email: party['Email Address'],
|
|
salesLevel: party['Sales Process Level'],
|
|
eoiStatus: party['EOI Status']
|
|
}))
|
|
};
|
|
} else if (typeof interestedParties === 'number') {
|
|
partiesInfo = {
|
|
type: 'number',
|
|
count: interestedParties,
|
|
note: 'This is just a count - should have been replaced with actual data'
|
|
};
|
|
} else {
|
|
partiesInfo = {
|
|
type: typeof interestedParties,
|
|
value: interestedParties
|
|
};
|
|
}
|
|
}
|
|
|
|
return {
|
|
berthId: berth.Id,
|
|
mooringNumber: berth['Mooring Number'],
|
|
interestedPartiesField: partiesInfo,
|
|
success: Array.isArray(interestedParties) && interestedParties.length > 0
|
|
};
|
|
} catch (error: any) {
|
|
console.error('[test-berth-with-parties] Error:', error);
|
|
return {
|
|
error: error.message || 'Unknown error',
|
|
details: error
|
|
};
|
|
}
|
|
});
|