FEAT: Enhance getBerths and test-specific-berth functionality to improve interested parties handling and debugging

This commit is contained in:
2025-06-17 17:04:45 +02:00
parent d9f359d874
commit 843205a529
2 changed files with 172 additions and 14 deletions

View File

@@ -446,26 +446,63 @@ export const getBerths = async () => {
if (result.list && Array.isArray(result.list)) {
console.log('[nocodb.getBerths] Processing berths to populate interested parties...');
// Count berths with interested parties
const berthsWithParties = result.list.filter(b =>
b['Interested Parties'] && Array.isArray(b['Interested Parties']) && b['Interested Parties'].length > 0
);
console.log('[nocodb.getBerths] Berths with interested parties:', berthsWithParties.length);
// Log first berth with interested parties for debugging
if (berthsWithParties.length > 0) {
const firstBerth = berthsWithParties[0];
if (firstBerth && firstBerth['Interested Parties']) {
console.log('[nocodb.getBerths] First berth with parties:', {
id: firstBerth.Id,
mooringNumber: firstBerth['Mooring Number'],
partiesCount: firstBerth['Interested Parties'].length,
firstParty: firstBerth['Interested Parties'][0]
});
}
}
await Promise.all(
result.list.map(async (berth) => {
if (berth['Interested Parties'] && Array.isArray(berth['Interested Parties'])) {
const interestedPartiesDetails = await Promise.all(
berth['Interested Parties'].map(async (party: any) => {
if (party && (party.Id || party.id)) {
const interestId = party.Id || party.id;
if (berth['Interested Parties'] && Array.isArray(berth['Interested Parties']) && berth['Interested Parties'].length > 0) {
console.log(`[nocodb.getBerths] Processing ${berth['Interested Parties'].length} parties for berth ${berth['Mooring Number']}`);
// Extract IDs from various possible formats
const partyIds = berth['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: any) => id !== null && !isNaN(id));
console.log(`[nocodb.getBerths] Extracted ${partyIds.length} valid IDs for berth ${berth['Mooring Number']}:`, partyIds);
if (partyIds.length > 0) {
const interestedPartiesDetails = await Promise.all(
partyIds.map(async (partyId: number) => {
try {
const interestDetails = await getInterestById(interestId.toString());
console.log(`[nocodb.getBerths] Fetching interest ${partyId} for berth ${berth['Mooring Number']}`);
const interestDetails = await getInterestById(partyId.toString());
return interestDetails;
} catch (error) {
console.error('[nocodb.getBerths] Failed to fetch interest details for ID:', interestId, error);
return party; // Return original party if fetch fails
console.error(`[nocodb.getBerths] Failed to fetch interest ${partyId}:`, error);
return { Id: partyId, 'Full Name': `Interest #${partyId}` } as any;
}
}
return party;
})
);
berth['Interested Parties'] = interestedPartiesDetails;
})
);
berth['Interested Parties'] = interestedPartiesDetails;
console.log(`[nocodb.getBerths] Populated ${interestedPartiesDetails.length} parties for berth ${berth['Mooring Number']}`);
} else {
console.log(`[nocodb.getBerths] No valid party IDs found for berth ${berth['Mooring Number']}`);
}
}
})
);