Code maintainability fixes
This commit is contained in:
27
src/services/exercises.ts
Normal file
27
src/services/exercises.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { ExerciseDef, WorkoutSet } from '../types';
|
||||
import { api } from './api';
|
||||
|
||||
export const getExercises = async (userId: string): Promise<ExerciseDef[]> => {
|
||||
try {
|
||||
return await api.get<ExerciseDef[]>('/exercises');
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
export const saveExercise = async (userId: string, exercise: ExerciseDef): Promise<void> => {
|
||||
await api.post('/exercises', exercise);
|
||||
};
|
||||
|
||||
export const getLastSetForExercise = async (userId: string, exerciseId: string): Promise<WorkoutSet | undefined> => {
|
||||
try {
|
||||
const response = await api.get<{ success: boolean; set?: WorkoutSet }>(`/exercises/${exerciseId}/last-set`);
|
||||
if (response.success && response.set) {
|
||||
return response.set;
|
||||
}
|
||||
return undefined;
|
||||
} catch (error) {
|
||||
console.error("Failed to fetch last set:", error);
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user