This commit is contained in:
2025-06-09 23:42:31 +02:00
parent 2f1f970267
commit cc2cc282b9
3 changed files with 60 additions and 14 deletions

View File

@@ -12,13 +12,21 @@ export default defineEventHandler(async (event) => {
try {
const body = await readBody(event);
const { id, data } = body;
console.log('[update-interest] Request body:', { id, dataKeys: data ? Object.keys(data) : 'none' });
console.log('[update-interest] Request body:', {
id,
idType: typeof id,
dataKeys: data ? Object.keys(data) : 'none'
});
if (!id) {
console.error('[update-interest] Missing ID in request');
throw createError({ statusCode: 400, statusMessage: "ID is required" });
}
// Ensure ID is a string
const interestId = String(id);
console.log('[update-interest] Using ID:', interestId, 'Type:', typeof interestId);
if (!data || Object.keys(data).length === 0) {
console.error('[update-interest] No data provided for update');
throw createError({ statusCode: 400, statusMessage: "No data provided for update" });
@@ -31,9 +39,9 @@ export default defineEventHandler(async (event) => {
console.log('[update-interest] Removed Id from update data');
}
console.log('[update-interest] Updating interest:', id, 'with fields:', Object.keys(updateData));
const updatedInterest = await updateInterest(id, updateData);
console.log('[update-interest] Successfully updated interest:', id);
console.log('[update-interest] Updating interest:', interestId, 'with fields:', Object.keys(updateData));
const updatedInterest = await updateInterest(interestId, updateData);
console.log('[update-interest] Successfully updated interest:', interestId);
return updatedInterest;
} catch (error) {

View File

@@ -15,10 +15,17 @@ export enum Table {
Interest = "mbs9hjauug4eseo",
}
export const getNocoDbConfiguration = () => useRuntimeConfig().nocodb;
export const getNocoDbConfiguration = () => {
const config = useRuntimeConfig().nocodb;
console.log('[nocodb] Configuration URL:', config.url);
return config;
};
export const createTableUrl = (table: Table) =>
`${getNocoDbConfiguration().url}/api/v2/tables/${table}/records`;
export const createTableUrl = (table: Table) => {
const url = `${getNocoDbConfiguration().url}/api/v2/tables/${table}/records`;
console.log('[nocodb] Table URL:', url);
return url;
};
export const getInterests = async () =>
$fetch<InterestsResponse>(createTableUrl(Table.Interest), {
@@ -41,6 +48,20 @@ export const updateInterest = async (id: string, data: Partial<Interest>, retryC
console.log('[nocodb.updateInterest] Updating interest:', id, 'Retry:', retryCount);
console.log('[nocodb.updateInterest] Data fields:', Object.keys(data));
// First, try to verify the record exists
if (retryCount === 0) {
try {
console.log('[nocodb.updateInterest] Verifying record exists...');
const existingRecord = await getInterestById(id);
console.log('[nocodb.updateInterest] Record exists with ID:', existingRecord.Id);
} catch (verifyError: any) {
console.error('[nocodb.updateInterest] Failed to verify record:', verifyError);
if (verifyError.statusCode === 404 || verifyError.status === 404) {
console.error('[nocodb.updateInterest] Record verification failed - record not found');
}
}
}
// 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> = {};
@@ -97,10 +118,16 @@ export const updateInterest = async (id: string, data: Partial<Interest>, retryC
console.log('[nocodb.updateInterest] URL:', url);
try {
console.log('[nocodb.updateInterest] Sending PATCH request with headers:', {
"xc-token": getNocoDbConfiguration().token ? "***" + getNocoDbConfiguration().token.slice(-4) : "not set"
});
console.log('[nocodb.updateInterest] Request body:', JSON.stringify(cleanData, null, 2));
const result = await $fetch<Interest>(url, {
method: "PATCH",
headers: {
"xc-token": getNocoDbConfiguration().token,
"Content-Type": "application/json"
},
body: cleanData
});