updates
This commit is contained in:
@@ -1,34 +1,68 @@
|
||||
import { deleteInterest } from '~/server/utils/nocodb';
|
||||
import { deleteInterest, getInterestById } from '~/server/utils/nocodb';
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const startTime = Date.now();
|
||||
const xTagHeader = getRequestHeader(event, "x-tag");
|
||||
console.log('[delete-interest] Request received with x-tag:', xTagHeader);
|
||||
console.log('[delete-interest] =========================');
|
||||
console.log('[delete-interest] Request received at:', new Date().toISOString());
|
||||
console.log('[delete-interest] x-tag:', xTagHeader);
|
||||
|
||||
if (!xTagHeader || (xTagHeader !== "094ut234" && xTagHeader !== "pjnvü1230")) {
|
||||
console.error('[delete-interest] Authentication failed - invalid x-tag:', xTagHeader);
|
||||
console.log('[delete-interest] Duration:', Date.now() - startTime, 'ms');
|
||||
throw createError({ statusCode: 401, statusMessage: "unauthenticated" });
|
||||
}
|
||||
|
||||
try {
|
||||
const body = await readBody(event);
|
||||
const { id } = body;
|
||||
console.log('[delete-interest] Request body:', { id });
|
||||
console.log('[delete-interest] Request body:', JSON.stringify(body, null, 2));
|
||||
|
||||
if (!id) {
|
||||
console.error('[delete-interest] Missing ID in request');
|
||||
console.log('[delete-interest] Duration:', Date.now() - startTime, 'ms');
|
||||
throw createError({ statusCode: 400, statusMessage: "ID is required" });
|
||||
}
|
||||
|
||||
console.log('[delete-interest] Deleting interest:', id);
|
||||
// Pre-delete verification
|
||||
console.log('[delete-interest] Pre-delete verification - checking if record exists...');
|
||||
try {
|
||||
const existingRecord = await getInterestById(id);
|
||||
console.log('[delete-interest] Record found:', {
|
||||
id: existingRecord.Id,
|
||||
name: existingRecord['Full Name'],
|
||||
email: existingRecord['Email Address']
|
||||
});
|
||||
} catch (verifyError: any) {
|
||||
console.error('[delete-interest] Pre-delete verification failed:', verifyError);
|
||||
if (verifyError.statusCode === 404 || verifyError.status === 404) {
|
||||
console.error('[delete-interest] Record does not exist - cannot delete');
|
||||
throw createError({ statusCode: 404, statusMessage: "Record not found" });
|
||||
}
|
||||
}
|
||||
|
||||
console.log('[delete-interest] Proceeding with deletion for ID:', id);
|
||||
const result = await deleteInterest(id);
|
||||
console.log('[delete-interest] Successfully deleted interest:', id);
|
||||
console.log('[delete-interest] Delete operation completed successfully');
|
||||
console.log('[delete-interest] Result:', JSON.stringify(result, null, 2));
|
||||
console.log('[delete-interest] Duration:', Date.now() - startTime, 'ms');
|
||||
console.log('[delete-interest] =========================');
|
||||
|
||||
return result;
|
||||
} catch (error) {
|
||||
console.error('[delete-interest] Error occurred:', error);
|
||||
console.error('[delete-interest] Error stack:', error instanceof Error ? error.stack : 'No stack trace');
|
||||
} catch (error: any) {
|
||||
console.error('[delete-interest] =========================');
|
||||
console.error('[delete-interest] ERROR OCCURRED');
|
||||
console.error('[delete-interest] Error type:', error.constructor.name);
|
||||
console.error('[delete-interest] Error message:', error.message);
|
||||
console.error('[delete-interest] Error status:', error.statusCode || error.status || 'unknown');
|
||||
console.error('[delete-interest] Error stack:', error.stack || 'No stack trace');
|
||||
console.error('[delete-interest] Full error object:', JSON.stringify(error, null, 2));
|
||||
console.error('[delete-interest] Duration:', Date.now() - startTime, 'ms');
|
||||
console.error('[delete-interest] =========================');
|
||||
|
||||
if (error instanceof Error) {
|
||||
if (error.statusCode || error.status) {
|
||||
throw error; // Re-throw if it's already a proper error
|
||||
} else if (error instanceof Error) {
|
||||
throw createError({ statusCode: 500, statusMessage: error.message });
|
||||
} else {
|
||||
throw createError({
|
||||
|
||||
@@ -84,7 +84,6 @@ export const updateInterest = async (id: string, data: Partial<Interest>, retryC
|
||||
"Depth",
|
||||
"Created At",
|
||||
"Source",
|
||||
"Place of Residence",
|
||||
"Contact Method Preferred",
|
||||
"Request Form Sent",
|
||||
"Berth Number",
|
||||
@@ -198,7 +197,6 @@ export const createInterest = async (data: Partial<Interest>) => {
|
||||
"Width",
|
||||
"Depth",
|
||||
"Source",
|
||||
"Place of Residence",
|
||||
"Contact Method Preferred",
|
||||
"Lead Category",
|
||||
"EOI Status",
|
||||
@@ -243,10 +241,27 @@ export const createInterest = async (data: Partial<Interest>) => {
|
||||
};
|
||||
|
||||
export const deleteInterest = async (id: string) => {
|
||||
console.log('[nocodb.deleteInterest] Deleting interest:', id);
|
||||
const startTime = Date.now();
|
||||
console.log('[nocodb.deleteInterest] =========================');
|
||||
console.log('[nocodb.deleteInterest] DELETE operation started at:', new Date().toISOString());
|
||||
console.log('[nocodb.deleteInterest] Target ID:', id);
|
||||
|
||||
const url = createTableUrl(Table.Interest);
|
||||
console.log('[nocodb.deleteInterest] URL:', url);
|
||||
|
||||
const requestBody = {
|
||||
"Id": parseInt(id)
|
||||
};
|
||||
|
||||
console.log('[nocodb.deleteInterest] Request configuration:');
|
||||
console.log(' Method: DELETE');
|
||||
console.log(' URL:', url);
|
||||
console.log(' Headers:', {
|
||||
"xc-token": getNocoDbConfiguration().token ? "***" + getNocoDbConfiguration().token.slice(-4) : "not set",
|
||||
"Content-Type": "application/json"
|
||||
});
|
||||
console.log(' Body:', JSON.stringify(requestBody, null, 2));
|
||||
|
||||
try {
|
||||
// According to NocoDB API docs, DELETE requires ID in the body
|
||||
const result = await $fetch(url, {
|
||||
@@ -255,15 +270,26 @@ export const deleteInterest = async (id: string) => {
|
||||
"xc-token": getNocoDbConfiguration().token,
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
body: {
|
||||
"Id": parseInt(id)
|
||||
}
|
||||
body: requestBody
|
||||
});
|
||||
console.log('[nocodb.deleteInterest] Delete successful for ID:', id);
|
||||
|
||||
console.log('[nocodb.deleteInterest] DELETE successful');
|
||||
console.log('[nocodb.deleteInterest] Response:', JSON.stringify(result, null, 2));
|
||||
console.log('[nocodb.deleteInterest] Duration:', Date.now() - startTime, 'ms');
|
||||
console.log('[nocodb.deleteInterest] =========================');
|
||||
|
||||
return result;
|
||||
} catch (error) {
|
||||
console.error('[nocodb.deleteInterest] Delete failed:', error);
|
||||
console.error('[nocodb.deleteInterest] Error details:', error instanceof Error ? error.message : 'Unknown error');
|
||||
} catch (error: any) {
|
||||
console.error('[nocodb.deleteInterest] =========================');
|
||||
console.error('[nocodb.deleteInterest] DELETE FAILED');
|
||||
console.error('[nocodb.deleteInterest] Error type:', error.constructor.name);
|
||||
console.error('[nocodb.deleteInterest] Error message:', error.message);
|
||||
console.error('[nocodb.deleteInterest] Error status:', error.statusCode || error.status || 'unknown');
|
||||
console.error('[nocodb.deleteInterest] Error data:', error.data);
|
||||
console.error('[nocodb.deleteInterest] Error stack:', error.stack || 'No stack trace');
|
||||
console.error('[nocodb.deleteInterest] Full error:', JSON.stringify(error, null, 2));
|
||||
console.error('[nocodb.deleteInterest] Duration:', Date.now() - startTime, 'ms');
|
||||
console.error('[nocodb.deleteInterest] =========================');
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user