diff --git a/components/BerthDetailsModal.vue b/components/BerthDetailsModal.vue index d060f23..ddf71e7 100644 --- a/components/BerthDetailsModal.vue +++ b/components/BerthDetailsModal.vue @@ -177,15 +177,15 @@
- Depth: + Draft: - {{ displayMeasurement(berth.Depth) }} + {{ displayMeasurement(berth.Draft) }}
diff --git a/server/utils/nocodb.ts b/server/utils/nocodb.ts index b290e0a..2271e84 100644 --- a/server/utils/nocodb.ts +++ b/server/utils/nocodb.ts @@ -427,68 +427,82 @@ export const getInterestByFieldAsync = async (fieldName: string, value: any): Pr export const getBerths = async () => { console.log('[nocodb.getBerths] Fetching berths from NocoDB...'); - const result = await $fetch(createTableUrl(Table.Berth), { - headers: { - "xc-token": getNocoDbConfiguration().token, - }, - params: { - limit: 1000, - // Include interested parties (expand the linked field) - fields: '*,Interested Parties.Id,Interested Parties.Full Name,Interested Parties.Sales Process Level,Interested Parties.EOI Status,Interested Parties.Contract Status' - }, - }); + try { + // First try with basic query - no field expansion to avoid 404 + const result = await $fetch(createTableUrl(Table.Berth), { + headers: { + "xc-token": getNocoDbConfiguration().token, + }, + params: { + limit: 1000, + // Start with basic fields only + fields: '*' + }, + }); - console.log('[nocodb.getBerths] Successfully fetched berths, count:', result.list?.length || 0); - - // Sort berths by letter zone and then by number using Mooring Number - if (result.list && Array.isArray(result.list)) { - result.list.sort((a, b) => { - const berthA = a['Mooring Number'] || ''; - const berthB = b['Mooring Number'] || ''; - - // Extract letter and number parts - const matchA = berthA.match(/^([A-Za-z]+)(\d+)$/); - const matchB = berthB.match(/^([A-Za-z]+)(\d+)$/); - - if (matchA && matchB) { - const [, letterA, numberA] = matchA; - const [, letterB, numberB] = matchB; + console.log('[nocodb.getBerths] Successfully fetched berths, count:', result.list?.length || 0); + + // Sort berths by letter zone and then by number using Mooring Number + if (result.list && Array.isArray(result.list)) { + result.list.sort((a, b) => { + const berthA = a['Mooring Number'] || ''; + const berthB = b['Mooring Number'] || ''; - // First sort by letter zone - const letterCompare = letterA.localeCompare(letterB); - if (letterCompare !== 0) { - return letterCompare; + // Extract letter and number parts + const matchA = berthA.match(/^([A-Za-z]+)(\d+)$/); + const matchB = berthB.match(/^([A-Za-z]+)(\d+)$/); + + if (matchA && matchB) { + const [, letterA, numberA] = matchA; + const [, letterB, numberB] = matchB; + + // First sort by letter zone + const letterCompare = letterA.localeCompare(letterB); + if (letterCompare !== 0) { + return letterCompare; + } + + // Then sort by number within the same letter zone + return parseInt(numberA) - parseInt(numberB); } - // Then sort by number within the same letter zone - return parseInt(numberA) - parseInt(numberB); - } + // Fallback to string comparison if pattern doesn't match + return berthA.localeCompare(berthB); + }); - // Fallback to string comparison if pattern doesn't match - return berthA.localeCompare(berthB); - }); + console.log('[nocodb.getBerths] Berths sorted by zone and number'); + } - console.log('[nocodb.getBerths] Berths sorted by zone and number'); + return result; + } catch (error: any) { + console.error('[nocodb.getBerths] Error fetching berths:', error); + console.error('[nocodb.getBerths] Error details:', error instanceof Error ? error.message : 'Unknown error'); + throw error; } - - return result; }; export const getBerthById = async (id: string) => { console.log('[nocodb.getBerthById] Fetching berth ID:', id); - const result = await $fetch(`${createTableUrl(Table.Berth)}/${id}`, { - headers: { - "xc-token": getNocoDbConfiguration().token, - }, - params: { - // Include interested parties (expand the linked field) - fields: '*,Interested Parties.Id,Interested Parties.Full Name,Interested Parties.Sales Process Level,Interested Parties.EOI Status,Interested Parties.Contract Status' - } - }); - - console.log('[nocodb.getBerthById] Successfully fetched berth:', result.Id); - return result; + try { + // Use basic query first to avoid 404 field expansion errors + const result = await $fetch(`${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); + return result; + } catch (error: any) { + console.error('[nocodb.getBerthById] Error fetching berth:', error); + console.error('[nocodb.getBerthById] Error details:', error instanceof Error ? error.message : 'Unknown error'); + throw error; + } }; export const updateBerth = async (id: string, data: Partial): Promise => { @@ -498,7 +512,7 @@ export const updateBerth = async (id: string, data: Partial): Promise = {}; - // Only include fields that are part of the Berth schema + // Only include fields that are part of the Berth schema (excluding formula fields) const allowedFields = [ "Mooring Number", "Area", @@ -507,7 +521,7 @@ export const updateBerth = async (id: string, data: Partial): Promise