Files
Evergreen-Health-Mobile/src/services/health.ts
T

62 lines
1.5 KiB
TypeScript

import http from './http'
export type HealthUser = {
id: number
phone: string
displayName: string
avatarUrl?: string
}
export type AuthOutput = {
accessToken: string
refreshToken: string
user: HealthUser
}
export type HealthProfile = {
birthday?: string
gender?: string
heightCm?: number
weightKg?: number
averageSleepHours?: number
dailyExerciseMinutes?: number
dietPreference?: string
healthGoal?: string
}
export type PlanItem = {
moduleCode: string
title: string
target: string
advice: string
}
export type HealthPlan = {
id: number
version: number
title: string
summary: string
createTime: string
items: PlanItem[]
}
export type Dashboard = {
user: HealthUser
profile?: HealthProfile
selectedModules: string[]
currentPlan?: HealthPlan
}
export const healthApi = {
register: (payload: { phone: string; password: string; displayName: string }) =>
http.post<never, AuthOutput>('/api/health/auth/register', payload),
login: (payload: { phone: string; password: string }) =>
http.post<never, AuthOutput>('/api/health/auth/login', payload),
dashboard: () => http.get<never, Dashboard>('/api/health/dashboard'),
saveProfile: (payload: HealthProfile) =>
http.put<never, HealthProfile>('/api/health/profile', payload),
saveModules: (moduleCodes: string[]) =>
http.put<never, string[]>('/api/health/modules', { moduleCodes }),
generatePlan: () => http.post<never, HealthPlan>('/api/health/plans/generate')
}