fitaiProto/apps/mobile/src/api/statistics.ts
2026-03-11 03:43:34 +01:00

27 lines
807 B
TypeScript

import { apiClient } from "./client";
import { API_ENDPOINTS } from "../config/api";
import type { UserStatisticsResponse } from "./types";
/**
* Fetch user statistics including goals, attendance, and weekly trends
*
* @param userId - Clerk user ID
* @param token - Clerk authentication token
* @returns User statistics data
*/
export async function getUserStatistics(
userId: string,
token?: string | null,
): Promise<UserStatisticsResponse> {
const response = await apiClient.get<{
success: boolean;
data: { statistics: UserStatisticsResponse };
}>(API_ENDPOINTS.USERS.STATISTICS, {
params: { userId },
headers: token ? { Authorization: `Bearer ${token}` } : {},
});
// Extract statistics from standardized API response format
return response.data.data.statistics;
}