FEAT: Enhance getBerths and getBerthById functions to populate interested parties details
This commit is contained in:
parent
150f7f9aa9
commit
d0632b2839
|
|
@ -442,8 +442,35 @@ export const getBerths = async () => {
|
|||
|
||||
console.log('[nocodb.getBerths] Successfully fetched berths, count:', result.list?.length || 0);
|
||||
|
||||
// Sort berths by letter zone and then by number using Mooring Number
|
||||
// Process each berth to populate interested parties details
|
||||
if (result.list && Array.isArray(result.list)) {
|
||||
console.log('[nocodb.getBerths] Processing berths to populate interested parties...');
|
||||
|
||||
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;
|
||||
try {
|
||||
const interestDetails = await getInterestById(interestId.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
|
||||
}
|
||||
}
|
||||
return party;
|
||||
})
|
||||
);
|
||||
|
||||
berth['Interested Parties'] = interestedPartiesDetails;
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
// Sort berths by letter zone and then by number using Mooring Number
|
||||
result.list.sort((a, b) => {
|
||||
const berthA = a['Mooring Number'] || '';
|
||||
const berthB = b['Mooring Number'] || '';
|
||||
|
|
@ -470,7 +497,7 @@ export const getBerths = async () => {
|
|||
return berthA.localeCompare(berthB);
|
||||
});
|
||||
|
||||
console.log('[nocodb.getBerths] Berths sorted by zone and number');
|
||||
console.log('[nocodb.getBerths] Berths sorted by zone and number with populated interested parties');
|
||||
}
|
||||
|
||||
return result;
|
||||
|
|
@ -485,18 +512,43 @@ export const getBerthById = async (id: string) => {
|
|||
console.log('[nocodb.getBerthById] Fetching berth ID:', id);
|
||||
|
||||
try {
|
||||
// Use basic query first to avoid 404 field expansion errors
|
||||
// First fetch the basic berth data
|
||||
const result = await $fetch<Berth>(`${createTableUrl(Table.Berth)}/${id}`, {
|
||||
headers: {
|
||||
"xc-token": getNocoDbConfiguration().token,
|
||||
},
|
||||
params: {
|
||||
// Start with basic fields only
|
||||
fields: '*'
|
||||
}
|
||||
});
|
||||
|
||||
console.log('[nocodb.getBerthById] Successfully fetched berth:', result.Id);
|
||||
|
||||
// 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;
|
||||
try {
|
||||
console.log('[nocodb.getBerthById] Fetching interest details for ID:', interestId);
|
||||
const interestDetails = await getInterestById(interestId.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
|
||||
}
|
||||
}
|
||||
return party;
|
||||
})
|
||||
);
|
||||
|
||||
result['Interested Parties'] = interestedPartiesDetails;
|
||||
console.log('[nocodb.getBerthById] Populated interested parties details');
|
||||
}
|
||||
|
||||
return result;
|
||||
} catch (error: any) {
|
||||
console.error('[nocodb.getBerthById] Error fetching berth:', error);
|
||||
|
|
|
|||
Loading…
Reference in New Issue