Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ jobs:
run: pnpm install --frozen-lockfile

- name: Run Type Check
run: npx tsc -b
run: npx tsc --noEmit

- name: Run Format Check
run: npx prettier . --check
Expand Down
23 changes: 23 additions & 0 deletions SparkyFitnessFrontend/src/api/Diary/waterIntakteService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { apiCall } from '@/services/api';

export interface UpdateWaterPayload {
user_id: string;
entry_date: string;
change_drinks: number;
container_id: number | null;
}

export const getWaterGoalForDate = async (date: string, userId: string) => {
return apiCall(`/goals/for-date?date=${date}&userId=${userId}`);
};

export const getWaterIntakeForDate = async (date: string, userId: string) => {
return apiCall(`/measurements/water-intake/${date}?userId=${userId}`);
};

export const updateWaterIntake = async (payload: UpdateWaterPayload) => {
return apiCall('/measurements/water-intake', {
method: 'POST',
body: payload,
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { apiCall } from '@/services/api';
import { getExerciseEntriesForDate as getDailyExerciseEntries } from '@/api/Diary/dailyProgressService';
import type { Exercise } from './exerciseSearchService';
import { parseJsonArray } from './exerciseService';
import type { ExerciseProgressData } from '@/services/reportsService';
import type { ExerciseProgressData } from '@/api/Reports/reportsService';
import type { WorkoutPresetSet } from '@/types/workout';
import type { ActivityDetailKeyValuePair } from '@/components/ExerciseActivityDetailsEditor';
import { debug } from '@/utils/logging';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { apiCall } from './api';
import { apiCall } from '../../services/api';

import type { Food, FoodVariant } from '@/types/food';

Expand Down
25 changes: 25 additions & 0 deletions SparkyFitnessFrontend/src/api/Integrations/integrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,28 @@ export const syncHevyData = async (
body: JSON.stringify({ providerId }),
});
};
export interface GarminLoginPayload {
email: string;
password: string;
}
export interface GarminProviderData {
id: string;
provider_type: string;
}

export interface GarminLoginResponse {
status: string;
provider?: GarminProviderData;
client_state?: string;
error?: string;
id: string;
}

export const loginGarmin = async (
payload: GarminLoginPayload
): Promise<GarminLoginResponse> => {
return apiCall('/integrations/garmin/login', {
method: 'POST',
body: JSON.stringify(payload),
});
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { apiCall } from './api';
import type { Exercise } from '../api/Exercises/exerciseSearchService';
import type { SleepAnalyticsData } from '../types';
import { apiCall } from '@/services/api';
import type { Exercise } from '../Exercises/exerciseSearchService';
import type { SleepAnalyticsData } from '../../types';

export interface NutritionData {
date: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { apiCall } from './api';
import { apiCall } from '@/services/api';

export interface AIService {
id: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { apiCall } from './api';
import { info, error } from '@/utils/logging';
import type { UserLoggingLevel } from '@/utils/logging';
import { apiCall } from '@/services/api';

export interface CustomCategory {
id: string;
Expand All @@ -11,25 +9,17 @@ export interface CustomCategory {
data_type: string;
}

export const getCategories = async (
loggingLevel: UserLoggingLevel
): Promise<CustomCategory[]> => {
export const getCategories = async (): Promise<CustomCategory[]> => {
const response = await apiCall(`/measurements/custom-categories`, {
method: 'GET',
suppress404Toast: true,
});
info(loggingLevel, 'Raw API response for getCategories:', response);
return (
response
// eslint-disable-next-line @typescript-eslint/no-explicit-any
.filter((cat: any) => {
const id = cat && cat.id ? String(cat.id) : '';
if (!id) {
error(
loggingLevel,
'Category fetched with missing or invalid ID, filtering out:',
cat
);
return false; // Filter out categories without a valid ID
}
return true;
Expand All @@ -39,33 +29,25 @@ export const getCategories = async (
); // Ensure ID is string for valid categories
};

export const addCategory = async (
categoryData: {
user_id: string;
name: string;
display_name?: string;
measurement_type: string;
frequency: string;
data_type: string;
},
loggingLevel: UserLoggingLevel
): Promise<CustomCategory> => {
export const addCategory = async (categoryData: {
user_id: string;
name: string;
display_name?: string;
measurement_type: string;
frequency: string;
data_type: string;
}): Promise<CustomCategory> => {
const response = await apiCall('/measurements/custom-categories', {
method: 'POST',
body: categoryData,
});
info(loggingLevel, 'Raw API response for addCategory:', response);
const id = response && response.id ? String(response.id) : null;
if (!id) {
error(
loggingLevel,
'New category added with missing or invalid ID:',
response
);
throw new Error(
'Failed to add category: Missing or invalid ID in response.'
);
}

return { ...response, id: id };
};

Expand All @@ -77,8 +59,7 @@ export const updateCategory = async (
measurement_type?: string;
frequency?: string;
data_type?: string;
},
loggingLevel: UserLoggingLevel
}
): Promise<CustomCategory> => {
const response = await apiCall(
`/measurements/custom-categories/${categoryId}`,
Expand All @@ -87,25 +68,16 @@ export const updateCategory = async (
body: categoryData,
}
);
info(loggingLevel, 'Raw API response for updateCategory:', response);
const id = response && response.id ? String(response.id) : null;
if (!id) {
error(
loggingLevel,
'Updated category with missing or invalid ID:',
response
);
throw new Error(
'Failed to update category: Missing or invalid ID in response.'
);
}
return { ...response, id: id };
};

export const deleteCategory = async (
categoryId: string,
loggingLevel: UserLoggingLevel
): Promise<void> => {
export const deleteCategory = async (categoryId: string): Promise<void> => {
return apiCall(`/measurements/custom-categories/${categoryId}`, {
method: 'DELETE',
});
Expand Down
Loading