Add debug logging and update API authentication
- Add comprehensive logging to all interest API endpoints and NocoDB utilities - Update create-interest and delete-interest endpoints to accept additional x-tag value - Add missing imports for deleteInterest and updateInterest functions - Log request details, processing steps, and errors for better debugging
This commit is contained in:
@@ -38,6 +38,9 @@ export const getInterestById = async (id: string) =>
|
||||
});
|
||||
|
||||
export const updateInterest = async (id: string, data: Partial<Interest>) => {
|
||||
console.log('[nocodb.updateInterest] Updating interest:', id);
|
||||
console.log('[nocodb.updateInterest] Data fields:', Object.keys(data));
|
||||
|
||||
// Create a clean data object that matches the InterestsRequest schema
|
||||
// Remove any properties that are not in the schema or shouldn't be sent
|
||||
const cleanData: Record<string, any> = {};
|
||||
@@ -74,6 +77,11 @@ export const updateInterest = async (id: string, data: Partial<Interest>) => {
|
||||
"Contract Sent Status",
|
||||
"Deposit 10% Status",
|
||||
"Contract Status",
|
||||
// Add the EOI link fields
|
||||
"EOI Client Link",
|
||||
"EOI David Link",
|
||||
"EOI Oscar Link",
|
||||
"EOI Document"
|
||||
];
|
||||
|
||||
// Filter the data to only include allowed fields
|
||||
@@ -83,19 +91,31 @@ export const updateInterest = async (id: string, data: Partial<Interest>) => {
|
||||
}
|
||||
}
|
||||
|
||||
return $fetch<Interest>(createTableUrl(Table.Interest), {
|
||||
method: "PATCH",
|
||||
headers: {
|
||||
"xc-token": getNocoDbConfiguration().token,
|
||||
},
|
||||
body: {
|
||||
Id: id, // This identifies the record to update
|
||||
...cleanData, // These are the fields to update
|
||||
},
|
||||
});
|
||||
console.log('[nocodb.updateInterest] Clean data fields:', Object.keys(cleanData));
|
||||
|
||||
const url = `${createTableUrl(Table.Interest)}/${id}`;
|
||||
console.log('[nocodb.updateInterest] URL:', url);
|
||||
|
||||
try {
|
||||
const result = await $fetch<Interest>(url, {
|
||||
method: "PATCH",
|
||||
headers: {
|
||||
"xc-token": getNocoDbConfiguration().token,
|
||||
},
|
||||
body: cleanData
|
||||
});
|
||||
console.log('[nocodb.updateInterest] Update successful for ID:', id);
|
||||
return result;
|
||||
} catch (error) {
|
||||
console.error('[nocodb.updateInterest] Update failed:', error);
|
||||
console.error('[nocodb.updateInterest] Error details:', error instanceof Error ? error.message : 'Unknown error');
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
export const createInterest = async (data: Partial<Interest>) => {
|
||||
console.log('[nocodb.createInterest] Creating interest with fields:', Object.keys(data));
|
||||
|
||||
// Create a clean data object that matches the InterestsRequest schema
|
||||
const cleanData: Record<string, any> = {};
|
||||
|
||||
@@ -137,22 +157,47 @@ export const createInterest = async (data: Partial<Interest>) => {
|
||||
delete cleanData["Berth Recommendations"];
|
||||
delete cleanData.Berth;
|
||||
|
||||
return $fetch<Interest>(createTableUrl(Table.Interest), {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"xc-token": getNocoDbConfiguration().token,
|
||||
},
|
||||
body: cleanData,
|
||||
});
|
||||
console.log('[nocodb.createInterest] Clean data fields:', Object.keys(cleanData));
|
||||
const url = createTableUrl(Table.Interest);
|
||||
console.log('[nocodb.createInterest] URL:', url);
|
||||
|
||||
try {
|
||||
const result = await $fetch<Interest>(url, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"xc-token": getNocoDbConfiguration().token,
|
||||
},
|
||||
body: cleanData,
|
||||
});
|
||||
console.log('[nocodb.createInterest] Created interest with ID:', result.Id);
|
||||
return result;
|
||||
} catch (error) {
|
||||
console.error('[nocodb.createInterest] Create failed:', error);
|
||||
console.error('[nocodb.createInterest] Error details:', error instanceof Error ? error.message : 'Unknown error');
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
export const deleteInterest = async (id: string) =>
|
||||
$fetch(`${createTableUrl(Table.Interest)}/${id}`, {
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
"xc-token": getNocoDbConfiguration().token,
|
||||
},
|
||||
});
|
||||
export const deleteInterest = async (id: string) => {
|
||||
console.log('[nocodb.deleteInterest] Deleting interest:', id);
|
||||
const url = `${createTableUrl(Table.Interest)}/${id}`;
|
||||
console.log('[nocodb.deleteInterest] URL:', url);
|
||||
|
||||
try {
|
||||
const result = await $fetch(url, {
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
"xc-token": getNocoDbConfiguration().token,
|
||||
},
|
||||
});
|
||||
console.log('[nocodb.deleteInterest] Delete successful for ID:', id);
|
||||
return result;
|
||||
} catch (error) {
|
||||
console.error('[nocodb.deleteInterest] Delete failed:', error);
|
||||
console.error('[nocodb.deleteInterest] Error details:', error instanceof Error ? error.message : 'Unknown error');
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
export const triggerWebhook = async (url: string, payload: any) =>
|
||||
$fetch(url, {
|
||||
|
||||
Reference in New Issue
Block a user