FEAT: Implement debug and test endpoints for fetching and analyzing berth interested parties
This commit is contained in:
@@ -523,30 +523,47 @@ export const getBerthById = async (id: string) => {
|
||||
});
|
||||
|
||||
console.log('[nocodb.getBerthById] Successfully fetched berth:', result.Id);
|
||||
console.log('[nocodb.getBerthById] Raw Interested Parties:', JSON.stringify(result['Interested Parties'], null, 2));
|
||||
|
||||
// Now fetch and populate the interested parties details
|
||||
if (result['Interested Parties'] && Array.isArray(result['Interested Parties'])) {
|
||||
console.log('[nocodb.getBerthById] Fetching details for interested parties:', result['Interested Parties'].length);
|
||||
|
||||
const interestedPartiesDetails = await Promise.all(
|
||||
result['Interested Parties'].map(async (party: any) => {
|
||||
if (party && (party.Id || party.id)) {
|
||||
const interestId = party.Id || party.id;
|
||||
// Extract IDs from various possible formats
|
||||
const partyIds = result['Interested Parties'].map((party: any) => {
|
||||
// Handle different possible formats from NocoDB
|
||||
if (typeof party === 'number') return party;
|
||||
if (typeof party === 'string') return parseInt(party);
|
||||
if (party && typeof party === 'object') {
|
||||
// Check various possible ID field names
|
||||
return party.Id || party.id || party.ID || party._id || null;
|
||||
}
|
||||
return null;
|
||||
}).filter(id => id !== null && !isNaN(id));
|
||||
|
||||
console.log('[nocodb.getBerthById] Extracted party IDs:', partyIds);
|
||||
|
||||
// Fetch full interest records
|
||||
if (partyIds.length > 0) {
|
||||
const interestedPartiesDetails = await Promise.all(
|
||||
partyIds.map(async (partyId: number) => {
|
||||
try {
|
||||
console.log('[nocodb.getBerthById] Fetching interest details for ID:', interestId);
|
||||
const interestDetails = await getInterestById(interestId.toString());
|
||||
console.log('[nocodb.getBerthById] Fetching interest details for ID:', partyId);
|
||||
const interestDetails = await getInterestById(partyId.toString());
|
||||
return interestDetails;
|
||||
} catch (error) {
|
||||
console.error('[nocodb.getBerthById] Failed to fetch interest details for ID:', interestId, error);
|
||||
return party; // Return original party if fetch fails
|
||||
console.error('[nocodb.getBerthById] Failed to fetch interest details for ID:', partyId, error);
|
||||
// Return a placeholder object if fetch fails
|
||||
return { Id: partyId, 'Full Name': `Interest #${partyId}` } as any;
|
||||
}
|
||||
}
|
||||
return party;
|
||||
})
|
||||
);
|
||||
|
||||
result['Interested Parties'] = interestedPartiesDetails;
|
||||
console.log('[nocodb.getBerthById] Populated interested parties details');
|
||||
})
|
||||
);
|
||||
|
||||
result['Interested Parties'] = interestedPartiesDetails;
|
||||
console.log('[nocodb.getBerthById] Populated interested parties details:', interestedPartiesDetails.length);
|
||||
} else {
|
||||
console.log('[nocodb.getBerthById] No valid party IDs found to populate');
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
Reference in New Issue
Block a user