FEAT: Remove test-specific berth handler and related functionality
This commit is contained in:
parent
e4f4f0285a
commit
45f0a3527e
|
|
@ -1,147 +0,0 @@
|
|||
import { requireAuth } from '~/server/utils/auth';
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
console.log('[test-berth-interested-parties] Testing berth interested parties...');
|
||||
|
||||
// Check authentication
|
||||
await requireAuth(event);
|
||||
|
||||
try {
|
||||
const config = useRuntimeConfig().nocodb;
|
||||
|
||||
// First, let's get all berths and see which ones have interested parties
|
||||
const berthsResponse = await $fetch(`${config.url}/api/v2/tables/mczgos9hr3oa9qc/records`, {
|
||||
headers: {
|
||||
"xc-token": config.token,
|
||||
},
|
||||
params: {
|
||||
limit: 100,
|
||||
fields: '*'
|
||||
}
|
||||
});
|
||||
|
||||
const berths = (berthsResponse as any).list || [];
|
||||
console.log('[test-berth-interested-parties] Total berths:', berths.length);
|
||||
|
||||
// Find berths with interested parties
|
||||
const berthsWithParties = berths.filter((b: any) =>
|
||||
b['Interested Parties'] && Array.isArray(b['Interested Parties']) && b['Interested Parties'].length > 0
|
||||
);
|
||||
|
||||
console.log('[test-berth-interested-parties] Berths with interested parties:', berthsWithParties.length);
|
||||
|
||||
if (berthsWithParties.length === 0) {
|
||||
return {
|
||||
message: "No berths found with interested parties",
|
||||
totalBerths: berths.length,
|
||||
berthsWithParties: 0
|
||||
};
|
||||
}
|
||||
|
||||
// Take the first berth with interested parties for testing
|
||||
const testBerth = berthsWithParties[0];
|
||||
console.log('[test-berth-interested-parties] Test berth:', {
|
||||
id: testBerth.Id,
|
||||
mooringNumber: testBerth['Mooring Number'],
|
||||
interestedPartiesCount: testBerth['Interested Parties'].length
|
||||
});
|
||||
|
||||
// Log the raw interested parties data
|
||||
console.log('[test-berth-interested-parties] Raw Interested Parties data:',
|
||||
JSON.stringify(testBerth['Interested Parties'], null, 2)
|
||||
);
|
||||
|
||||
// Analyze the structure
|
||||
const firstParty = testBerth['Interested Parties'][0];
|
||||
const partyAnalysis = {
|
||||
type: typeof firstParty,
|
||||
isArray: Array.isArray(firstParty),
|
||||
isObject: firstParty && typeof firstParty === 'object',
|
||||
value: firstParty,
|
||||
keys: firstParty && typeof firstParty === 'object' && !Array.isArray(firstParty)
|
||||
? Object.keys(firstParty)
|
||||
: []
|
||||
};
|
||||
|
||||
console.log('[test-berth-interested-parties] First party analysis:', partyAnalysis);
|
||||
|
||||
// Try to extract IDs
|
||||
const extractedIds = testBerth['Interested Parties'].map((party: any) => {
|
||||
if (typeof party === 'number') return { id: party, type: 'number' };
|
||||
if (typeof party === 'string') return { id: party, type: 'string' };
|
||||
if (party && typeof party === 'object') {
|
||||
return {
|
||||
id: party.Id || party.id || party.ID || party._id || null,
|
||||
type: 'object',
|
||||
keys: Object.keys(party)
|
||||
};
|
||||
}
|
||||
return { id: null, type: 'unknown' };
|
||||
});
|
||||
|
||||
console.log('[test-berth-interested-parties] Extracted IDs:', extractedIds);
|
||||
|
||||
// Try to fetch one interest if we have an ID
|
||||
let fetchedInterest = null;
|
||||
const validId = extractedIds.find((item: any) => item.id !== null);
|
||||
|
||||
if (validId && validId.id) {
|
||||
try {
|
||||
const interestId = typeof validId.id === 'string' ? validId.id : validId.id.toString();
|
||||
fetchedInterest = await $fetch(`${config.url}/api/v2/tables/mbs9hjauug4eseo/records/${interestId}`, {
|
||||
headers: {
|
||||
"xc-token": config.token,
|
||||
}
|
||||
});
|
||||
console.log('[test-berth-interested-parties] Successfully fetched interest:', interestId);
|
||||
} catch (error) {
|
||||
console.error('[test-berth-interested-parties] Failed to fetch interest:', error);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
testBerth: {
|
||||
id: testBerth.Id,
|
||||
mooringNumber: testBerth['Mooring Number'],
|
||||
interestedPartiesCount: testBerth['Interested Parties'].length
|
||||
},
|
||||
rawInterestedParties: testBerth['Interested Parties'],
|
||||
firstPartyAnalysis: partyAnalysis,
|
||||
extractedIds: extractedIds,
|
||||
fetchedInterest: fetchedInterest,
|
||||
recommendation: determineRecommendation(testBerth['Interested Parties'])
|
||||
};
|
||||
} catch (error: any) {
|
||||
console.error('[test-berth-interested-parties] Error:', error);
|
||||
return {
|
||||
error: error.message || 'Unknown error',
|
||||
details: error
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
function determineRecommendation(interestedParties: any[]): string {
|
||||
if (!interestedParties || interestedParties.length === 0) {
|
||||
return "No interested parties found";
|
||||
}
|
||||
|
||||
const firstParty = interestedParties[0];
|
||||
|
||||
if (typeof firstParty === 'number') {
|
||||
return "Interested parties are stored as number IDs. Population logic should handle this format.";
|
||||
}
|
||||
|
||||
if (typeof firstParty === 'string') {
|
||||
return "Interested parties are stored as string IDs. Population logic should parse these.";
|
||||
}
|
||||
|
||||
if (firstParty && typeof firstParty === 'object') {
|
||||
const keys = Object.keys(firstParty);
|
||||
if (keys.includes('Id') || keys.includes('id')) {
|
||||
return "Interested parties are objects with ID fields. Population logic looks correct.";
|
||||
}
|
||||
return `Interested parties are objects but with unexpected keys: ${keys.join(', ')}`;
|
||||
}
|
||||
|
||||
return "Unknown format for interested parties data";
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
import { getBerthById } from '~/server/utils/nocodb';
|
||||
import { getBerthById, getInterestById } from '~/server/utils/nocodb';
|
||||
import { requireAuth } from '~/server/utils/auth';
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
|
|
@ -18,6 +18,7 @@ export default defineEventHandler(async (event) => {
|
|||
// Extract interested parties info
|
||||
const interestedParties = berth['Interested Parties'];
|
||||
let partiesInfo = null;
|
||||
let directFetchComparison = null;
|
||||
|
||||
if (interestedParties) {
|
||||
if (Array.isArray(interestedParties)) {
|
||||
|
|
@ -29,9 +30,40 @@ export default defineEventHandler(async (event) => {
|
|||
name: party['Full Name'],
|
||||
email: party['Email Address'],
|
||||
salesLevel: party['Sales Process Level'],
|
||||
eoiStatus: party['EOI Status']
|
||||
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',
|
||||
|
|
@ -50,6 +82,7 @@ export default defineEventHandler(async (event) => {
|
|||
berthId: berth.Id,
|
||||
mooringNumber: berth['Mooring Number'],
|
||||
interestedPartiesField: partiesInfo,
|
||||
directFetchComparison,
|
||||
success: Array.isArray(interestedParties) && interestedParties.length > 0
|
||||
};
|
||||
} catch (error: any) {
|
||||
|
|
|
|||
|
|
@ -1,121 +0,0 @@
|
|||
import { requireAuth } from '~/server/utils/auth';
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
console.log('[test-specific-berth] Testing specific berth data...');
|
||||
|
||||
// Check authentication
|
||||
await requireAuth(event);
|
||||
|
||||
try {
|
||||
const query = getQuery(event);
|
||||
const berthId = query.id as string;
|
||||
|
||||
if (!berthId) {
|
||||
// Get first few berths to find one to test
|
||||
const config = useRuntimeConfig().nocodb;
|
||||
const berthsResponse = await $fetch(`${config.url}/api/v2/tables/mczgos9hr3oa9qc/records`, {
|
||||
headers: {
|
||||
"xc-token": config.token,
|
||||
},
|
||||
params: {
|
||||
limit: 10,
|
||||
fields: '*'
|
||||
}
|
||||
});
|
||||
|
||||
const berths = (berthsResponse as any).list || [];
|
||||
return {
|
||||
message: "No berth ID provided. Here are the first 10 berths:",
|
||||
berths: berths.map((b: any) => ({
|
||||
id: b.Id,
|
||||
mooringNumber: b['Mooring Number'],
|
||||
hasInterestedParties: !!b['Interested Parties'],
|
||||
interestedPartiesCount: Array.isArray(b['Interested Parties']) ? b['Interested Parties'].length : 0,
|
||||
interestedPartiesRaw: b['Interested Parties']
|
||||
}))
|
||||
};
|
||||
}
|
||||
|
||||
const config = useRuntimeConfig().nocodb;
|
||||
|
||||
// Fetch the specific berth
|
||||
const berth = await $fetch(`${config.url}/api/v2/tables/mczgos9hr3oa9qc/records/${berthId}`, {
|
||||
headers: {
|
||||
"xc-token": config.token,
|
||||
},
|
||||
params: {
|
||||
fields: '*'
|
||||
}
|
||||
});
|
||||
|
||||
console.log('[test-specific-berth] Raw berth data:', JSON.stringify(berth, null, 2));
|
||||
|
||||
// Check all fields to find potential interested parties
|
||||
const allFields = Object.keys(berth as any);
|
||||
const potentialLinkFields = allFields.filter(field => {
|
||||
const value = (berth as any)[field];
|
||||
return value && (Array.isArray(value) || (typeof value === 'object' && !field.includes('Created') && !field.includes('Updated')));
|
||||
});
|
||||
|
||||
// Try to fetch linked records using the links API
|
||||
let linkedRecordsAttempts = [];
|
||||
|
||||
// Try different possible field IDs for interested parties
|
||||
const possibleFieldIds = [
|
||||
'cj7v7bb9pa5eyo3', // This is used for "Berths" in interest table
|
||||
// Add other possible field IDs here if we discover them
|
||||
];
|
||||
|
||||
for (const fieldId of possibleFieldIds) {
|
||||
try {
|
||||
const linkUrl = `${config.url}/api/v2/tables/mczgos9hr3oa9qc/links/${fieldId}/records/${berthId}`;
|
||||
console.log('[test-specific-berth] Trying link URL:', linkUrl);
|
||||
|
||||
const linkedRecords = await $fetch(linkUrl, {
|
||||
headers: {
|
||||
"xc-token": config.token,
|
||||
}
|
||||
}).catch(err => ({
|
||||
error: err.message || 'Failed',
|
||||
fieldId: fieldId,
|
||||
status: err.statusCode || err.status
|
||||
}));
|
||||
|
||||
linkedRecordsAttempts.push({
|
||||
fieldId,
|
||||
result: linkedRecords
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('[test-specific-berth] Link fetch error:', error);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
berthId: (berth as any).Id,
|
||||
mooringNumber: (berth as any)['Mooring Number'],
|
||||
allFields: allFields,
|
||||
potentialLinkFields: potentialLinkFields.map(field => ({
|
||||
fieldName: field,
|
||||
value: (berth as any)[field],
|
||||
type: typeof (berth as any)[field],
|
||||
isArray: Array.isArray((berth as any)[field]),
|
||||
length: Array.isArray((berth as any)[field]) ? (berth as any)[field].length : undefined
|
||||
})),
|
||||
interestedPartiesField: {
|
||||
exists: 'Interested Parties' in (berth as any),
|
||||
value: (berth as any)['Interested Parties'],
|
||||
type: typeof (berth as any)['Interested Parties'],
|
||||
isArray: Array.isArray((berth as any)['Interested Parties']),
|
||||
length: Array.isArray((berth as any)['Interested Parties']) ? (berth as any)['Interested Parties'].length : undefined
|
||||
},
|
||||
linkedRecordsAttempts: linkedRecordsAttempts,
|
||||
rawBerth: berth
|
||||
};
|
||||
} catch (error: any) {
|
||||
console.error('[test-specific-berth] Error:', error);
|
||||
return {
|
||||
error: error.message || 'Unknown error',
|
||||
details: error
|
||||
};
|
||||
}
|
||||
});
|
||||
Loading…
Reference in New Issue