FEAT: Enhance interest fetching in InterestDetailsModal and update getBerths and getBerthById to retrieve full details for interested parties
This commit is contained in:
parent
45f0a3527e
commit
8a4824e6fe
|
|
@ -777,7 +777,31 @@ watch(
|
||||||
async (newInterest) => {
|
async (newInterest) => {
|
||||||
if (newInterest) {
|
if (newInterest) {
|
||||||
hasUnsavedChanges.value = false;
|
hasUnsavedChanges.value = false;
|
||||||
interest.value = { ...newInterest };
|
|
||||||
|
// If we only have an ID, or if the interest seems incomplete, fetch the full record
|
||||||
|
if (newInterest.Id && (!newInterest['Full Name'] || !newInterest['Sales Process Level'])) {
|
||||||
|
console.log('[InterestDetailsModal] Fetching full interest record for ID:', newInterest.Id);
|
||||||
|
try {
|
||||||
|
const fullInterest = await $fetch<Interest>(`/api/get-interest-by-id`, {
|
||||||
|
params: {
|
||||||
|
id: newInterest.Id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
if (fullInterest) {
|
||||||
|
interest.value = { ...fullInterest };
|
||||||
|
} else {
|
||||||
|
// Fallback to what we have
|
||||||
|
interest.value = { ...newInterest };
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('[InterestDetailsModal] Failed to fetch full interest:', error);
|
||||||
|
// Fallback to what we have
|
||||||
|
interest.value = { ...newInterest };
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
interest.value = { ...newInterest };
|
||||||
|
}
|
||||||
|
|
||||||
// Load linked berths and recommendations
|
// Load linked berths and recommendations
|
||||||
await loadLinkedBerths();
|
await loadLinkedBerths();
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -1,95 +0,0 @@
|
||||||
import { getBerthById, getInterestById } 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;
|
|
||||||
let directFetchComparison = 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'],
|
|
||||||
contractStatus: party['Contract Status'],
|
|
||||||
allFields: Object.keys(party).sort()
|
|
||||||
}))
|
|
||||||
};
|
|
||||||
|
|
||||||
// Compare with direct fetch of first party
|
|
||||||
if (interestedParties.length > 0) {
|
|
||||||
try {
|
|
||||||
const firstPartyId = interestedParties[0].Id;
|
|
||||||
const directFetch = await getInterestById(firstPartyId.toString());
|
|
||||||
directFetchComparison = {
|
|
||||||
fromLinksAPI: {
|
|
||||||
id: interestedParties[0].Id,
|
|
||||||
name: interestedParties[0]['Full Name'],
|
|
||||||
salesLevel: interestedParties[0]['Sales Process Level'],
|
|
||||||
eoiStatus: interestedParties[0]['EOI Status'],
|
|
||||||
contractStatus: interestedParties[0]['Contract Status'],
|
|
||||||
fieldCount: Object.keys(interestedParties[0]).length
|
|
||||||
},
|
|
||||||
fromDirectFetch: {
|
|
||||||
id: directFetch.Id,
|
|
||||||
name: directFetch['Full Name'],
|
|
||||||
salesLevel: directFetch['Sales Process Level'],
|
|
||||||
eoiStatus: directFetch['EOI Status'],
|
|
||||||
contractStatus: directFetch['Contract Status'],
|
|
||||||
fieldCount: Object.keys(directFetch).length,
|
|
||||||
allFields: Object.keys(directFetch).sort()
|
|
||||||
}
|
|
||||||
};
|
|
||||||
} catch (err) {
|
|
||||||
directFetchComparison = { error: 'Failed to fetch directly' };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} 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,
|
|
||||||
directFetchComparison,
|
|
||||||
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
|
|
||||||
};
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
@ -493,9 +493,27 @@ export const getBerths = async () => {
|
||||||
console.log(`[nocodb.getBerths] Linked response for berth ${berth['Mooring Number']}:`, linkedResponse);
|
console.log(`[nocodb.getBerths] Linked response for berth ${berth['Mooring Number']}:`, linkedResponse);
|
||||||
|
|
||||||
if (linkedResponse && linkedResponse.list && Array.isArray(linkedResponse.list)) {
|
if (linkedResponse && linkedResponse.list && Array.isArray(linkedResponse.list)) {
|
||||||
// The linked records should be full interest records
|
// The links API returns limited data, so we need to fetch full records
|
||||||
berth['Interested Parties'] = linkedResponse.list;
|
console.log(`[nocodb.getBerths] Got ${linkedResponse.list.length} linked records, fetching full details...`);
|
||||||
console.log(`[nocodb.getBerths] Successfully fetched ${linkedResponse.list.length} interested parties for berth ${berth['Mooring Number']}`);
|
|
||||||
|
const fullInterestDetails = await Promise.all(
|
||||||
|
linkedResponse.list.map(async (linkedParty: any) => {
|
||||||
|
try {
|
||||||
|
const partyId = linkedParty.Id || linkedParty.id;
|
||||||
|
if (partyId) {
|
||||||
|
const fullDetails = await getInterestById(partyId.toString());
|
||||||
|
return fullDetails;
|
||||||
|
}
|
||||||
|
return linkedParty;
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`[nocodb.getBerths] Failed to fetch full details for party ${linkedParty.Id}:`, error);
|
||||||
|
return linkedParty;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
berth['Interested Parties'] = fullInterestDetails;
|
||||||
|
console.log(`[nocodb.getBerths] Successfully fetched full details for ${fullInterestDetails.length} interested parties for berth ${berth['Mooring Number']}`);
|
||||||
} else {
|
} else {
|
||||||
// Fallback to placeholders if API call doesn't return expected format
|
// Fallback to placeholders if API call doesn't return expected format
|
||||||
const placeholderParties = Array.from({ length: partyCount }, (_, index) => ({
|
const placeholderParties = Array.from({ length: partyCount }, (_, index) => ({
|
||||||
|
|
@ -644,9 +662,27 @@ export const getBerthById = async (id: string) => {
|
||||||
console.log(`[nocodb.getBerthById] Linked response:`, linkedResponse);
|
console.log(`[nocodb.getBerthById] Linked response:`, linkedResponse);
|
||||||
|
|
||||||
if (linkedResponse && linkedResponse.list && Array.isArray(linkedResponse.list)) {
|
if (linkedResponse && linkedResponse.list && Array.isArray(linkedResponse.list)) {
|
||||||
// The linked records should be full interest records
|
// The links API returns limited data, so we need to fetch full records
|
||||||
result['Interested Parties'] = linkedResponse.list;
|
console.log(`[nocodb.getBerthById] Got ${linkedResponse.list.length} linked records, fetching full details...`);
|
||||||
console.log(`[nocodb.getBerthById] Successfully fetched ${linkedResponse.list.length} interested parties`);
|
|
||||||
|
const fullInterestDetails = await Promise.all(
|
||||||
|
linkedResponse.list.map(async (linkedParty: any) => {
|
||||||
|
try {
|
||||||
|
const partyId = linkedParty.Id || linkedParty.id;
|
||||||
|
if (partyId) {
|
||||||
|
const fullDetails = await getInterestById(partyId.toString());
|
||||||
|
return fullDetails;
|
||||||
|
}
|
||||||
|
return linkedParty;
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`[nocodb.getBerthById] Failed to fetch full details for party ${linkedParty.Id}:`, error);
|
||||||
|
return linkedParty;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
result['Interested Parties'] = fullInterestDetails;
|
||||||
|
console.log(`[nocodb.getBerthById] Successfully fetched full details for ${fullInterestDetails.length} interested parties`);
|
||||||
} else {
|
} else {
|
||||||
// Fallback to placeholders if API call doesn't return expected format
|
// Fallback to placeholders if API call doesn't return expected format
|
||||||
const placeholderParties = Array.from({ length: partyCount }, (_, index) => ({
|
const placeholderParties = Array.from({ length: partyCount }, (_, index) => ({
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue