28 lines
894 B
TypeScript
28 lines
894 B
TypeScript
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;
|
|
}
|
|
};
|