api call optimized

This commit is contained in:
dimitar committed 2026-03-11 03:43:34 +01:00
1 parent 97436c6823
commit 612259f020
12 files changed
+727 -177

No files matched your search

+41 -4
View File
@@ -72,7 +72,16 @@ export class FitnessGoalsService {
throw new Error(`Failed to fetch goals: ${response.status}`);
}
return await response.json();
const result = await response.json();
// Handle standardized API response format
// API returns: { success: true, data: [...], meta: {...} }
if (result.success && result.data) {
return Array.isArray(result.data) ? result.data : [];
}
// Fallback for legacy format (direct array)
return Array.isArray(result) ? result : [];
} catch (error) {
log.error("Failed to fetch fitness goals", error);
throw error;
@@ -99,7 +108,15 @@ export class FitnessGoalsService {
throw new Error(error.error || "Failed to create goal");
}
return await response.json();
const result = await response.json();
// Handle standardized API response format
if (result.success && result.data) {
return result.data;
}
// Fallback for legacy format
return result;
} catch (error) {
log.error("Failed to create fitness goal", error);
throw error;
@@ -126,7 +143,15 @@ export class FitnessGoalsService {
throw new Error("Failed to update goal");
}
return await response.json();
const result = await response.json();
// Handle standardized API response format
if (result.success && result.data) {
return result.data;
}
// Fallback for legacy format
return result;
} catch (error) {
log.error("Failed to update fitness goal", error);
throw error;
@@ -156,7 +181,16 @@ export class FitnessGoalsService {
throw new Error("Failed to complete goal");
}
return await response.json();
const result = await response.json();
// Note: Complete endpoint returns direct object (legacy format)
// Handle standardized API response format (if migrated)
if (result.success && result.data) {
return result.data;
}
// Fallback for legacy format (current implementation)
return result;
} catch (error) {
log.error("Failed to complete fitness goal", error);
throw error;
@@ -177,6 +211,9 @@ export class FitnessGoalsService {
if (!response.ok) {
throw new Error("Failed to delete goal");
}
// DELETE endpoint returns: { success: true, data: { deleted: true }, meta: {...} }
// No need to parse the result for void return type
} catch (error) {
log.error("Failed to delete fitness goal", error);
throw error;