fixes of broken fucntions

This commit is contained in:
Desktop
2025-11-16 04:56:48 +05:00
parent 5eb2464d2d
commit 5908115686
8 changed files with 141 additions and 46 deletions

View File

@@ -640,34 +640,24 @@ export async function autoClusterKeywords(keywordIds: number[], sectorId?: numbe
const requestBody = { ids: keywordIds, sector_id: sectorId };
try {
// fetchAPI will automatically extract data from unified format
// For action endpoints, response is {success: true, data: {...}}
// fetchAPI extracts and returns the data field, so response should already be the data object
// fetchAPI extracts data from unified format {success: true, data: {...}}
// So response is already the data object: {task_id: "...", ...}
const response = await fetchAPI(endpoint, {
method: 'POST',
body: JSON.stringify(requestBody),
});
// After fetchAPI processing, response should be the data object (not wrapped in success/data)
// But check if it's still wrapped (shouldn't happen, but for safety)
// Wrap extracted data with success: true for frontend compatibility
if (response && typeof response === 'object') {
if ('success' in response && response.success === false) {
// Error response - return as-is
return response as any;
}
// If response has data field, extract it
if ('data' in response && response.data) {
return { success: true, ...response.data } as any;
}
// Response is already the data object (after fetchAPI extraction)
// Ensure it has success: true
if (!('success' in response)) {
return { success: true, ...response } as any;
}
return { success: true, ...response } as any;
}
return response as any;
return { success: true, ...response } as any;
} catch (error: any) {
// Error responses are thrown by fetchAPI, but wrap them for consistency
if (error.response && typeof error.response === 'object') {
return { success: false, error: error.message, ...error.response } as any;
}
throw error;
}
}
@@ -677,13 +667,24 @@ export async function autoGenerateIdeas(clusterIds: number[]): Promise<{ success
const requestBody = { ids: clusterIds };
try {
// fetchAPI extracts data from unified format {success: true, data: {...}}
// So response is already the data object: {task_id: "...", ...}
const response = await fetchAPI(endpoint, {
method: 'POST',
body: JSON.stringify(requestBody),
});
return response;
// Wrap extracted data with success: true for frontend compatibility
if (response && typeof response === 'object') {
return { success: true, ...response } as any;
}
return { success: true, ...response } as any;
} catch (error: any) {
// Error responses are thrown by fetchAPI, but wrap them for consistency
if (error.response && typeof error.response === 'object') {
return { success: false, error: error.message, ...error.response } as any;
}
throw error;
}
}
@@ -693,13 +694,24 @@ export async function generateSingleIdea(ideaId: string | number, clusterId: num
const requestBody = { cluster_id: clusterId };
try {
// fetchAPI extracts data from unified format {success: true, data: {...}}
// So response is already the data object: {task_id: "...", ...}
const response = await fetchAPI(endpoint, {
method: 'POST',
body: JSON.stringify(requestBody),
});
return response;
// Wrap extracted data with success: true for frontend compatibility
if (response && typeof response === 'object') {
return { success: true, ...response } as any;
}
return { success: true, ...response } as any;
} catch (error: any) {
// Error responses are thrown by fetchAPI, but wrap them for consistency
if (error.response && typeof error.response === 'object') {
return { success: false, error: error.message, ...error.response } as any;
}
throw error;
}
}
@@ -1000,13 +1012,24 @@ export async function autoGenerateContent(ids: number[]): Promise<{ success: boo
const requestBody = { ids };
try {
// fetchAPI extracts data from unified format {success: true, data: {...}}
// So response is already the data object: {task_id: "...", ...}
const response = await fetchAPI(endpoint, {
method: 'POST',
body: JSON.stringify(requestBody),
});
return response;
// Wrap extracted data with success: true for frontend compatibility
if (response && typeof response === 'object') {
return { success: true, ...response } as any;
}
return { success: true, ...response } as any;
} catch (error: any) {
// Error responses are thrown by fetchAPI, but wrap them for consistency
if (error.response && typeof error.response === 'object') {
return { success: false, error: error.message, ...error.response } as any;
}
throw error;
}
}
@@ -1016,13 +1039,24 @@ export async function autoGenerateImages(taskIds: number[]): Promise<{ success:
const requestBody = { task_ids: taskIds };
try {
// fetchAPI extracts data from unified format {success: true, data: {...}}
// So response is already the data object: {task_id: "...", ...}
const response = await fetchAPI(endpoint, {
method: 'POST',
body: JSON.stringify(requestBody),
});
return response;
// Wrap extracted data with success: true for frontend compatibility
if (response && typeof response === 'object') {
return { success: true, ...response } as any;
}
return { success: true, ...response } as any;
} catch (error: any) {
// Error responses are thrown by fetchAPI, but wrap them for consistency
if (error.response && typeof error.response === 'object') {
return { success: false, error: error.message, ...error.response } as any;
}
throw error;
}
}