fitaiProto/apps/mobile/src/api/fitnessProfile.ts
echo 39021dca35 manual check in/check out
implemented, to be implemented: qrcode or/and geofence
2025-11-19 02:23:39 +01:00

97 lines
2.2 KiB
TypeScript

import axios from "axios";
import { API_BASE_URL } from "../config/api";
export interface FitnessProfile {
id?: string;
clientId: string;
height?: number;
weight?: number;
goals?: string;
fitnessLevel: "beginner" | "intermediate" | "advanced";
medicalConditions?: string;
dietaryRestrictions?: string;
preferredWorkoutTime?: "morning" | "afternoon" | "evening";
workoutFrequency?: number;
}
export const fitnessProfileApi = {
getFitnessProfile: async (
userId: string,
token: string,
): Promise<FitnessProfile> => {
try {
console.log(
"Getting fitness profile with URL:",
`${API_BASE_URL}/api/users/${userId}/fitness-profile`,
);
const response = await axios.get(
`${API_BASE_URL}/api/users/${userId}/fitness-profile`,
{
headers: {
Authorization: `Bearer ${token}`,
},
},
);
return response.data;
} catch (error: any) {
console.error(
"Error fetching fitness profile:",
error.message,
error.response?.data,
);
throw error;
}
},
updateFitnessProfile: async (
userId: string,
data: Partial<FitnessProfile>,
token: string,
): Promise<FitnessProfile> => {
try {
const response = await axios.put(
`${API_BASE_URL}/api/users/${userId}/fitness-profile`,
data,
{
headers: {
Authorization: `Bearer ${token}`,
},
},
);
return response.data;
} catch (error: any) {
console.error(
"Error updating fitness profile:",
error.message,
error.response?.data,
);
throw error;
}
},
createFitnessProfile: async (
data: Omit<FitnessProfile, "id">,
token: string,
): Promise<FitnessProfile> => {
try {
const response = await axios.post(
`${API_BASE_URL}/api/users/${data.clientId}/fitness-profile`,
data,
{
headers: {
Authorization: `Bearer ${token}`,
},
},
);
return response.data;
} catch (error: any) {
console.error(
"Error creating fitness profile:",
error.message,
error.response?.data,
);
throw error;
}
},
};