feat: 基本資料修改

This commit is contained in:
skytek_xinliang
2026-08-28 15:18:11 +08:00
parent 6d9f8df725
commit db089ce267
5 changed files with 416 additions and 52 deletions
+36 -2
View File
@@ -54,6 +54,8 @@ export interface UserProfile {
consentVersion: ConsentVersion;
}
type EditableProfile = Omit<UserProfile, "phone" | "consentVersion">;
export interface SelfAssessment {
exerciseFrequency: ExerciseFrequency | "";
painLevel: PainLevel | "";
@@ -168,6 +170,25 @@ function toProfileRequest(
};
}
function toProfileRequestFromStore(profile: UserProfile): ProfileRequest {
if (profile.gender !== "男" && profile.gender !== "女") {
throw new Error("請先完成性別資料");
}
return {
name: profile.name,
birthday: profile.birthday,
gender: profile.gender === "男" ? "male" : "female",
heightCm: profile.height,
weightKg: profile.weight,
email: profile.email || null,
emergencyContact: profile.emergencyContact || null,
emergencyPhone: profile.emergencyPhone || null,
consent: profile.consent,
consentVersion: profile.consentVersion,
};
}
function createDefaultAppointments(): Appointment[] {
const measurementItems = [
"血壓",
@@ -417,8 +438,21 @@ export const useAppStore = defineStore("app", () => {
}
}
function updateProfile(profile: Partial<UserProfile>) {
userProfile.value = { ...userProfile.value, ...profile };
async function updateProfile(
profile: Partial<EditableProfile>,
): Promise<UserProfile> {
const updatedProfile = { ...userProfile.value, ...profile };
if (USE_MOCK) {
userProfile.value = updatedProfile;
return userProfile.value;
}
const response = await apiUpdateProfile(
toProfileRequestFromStore(updatedProfile),
);
userProfile.value = applyProfileToStore(response);
return userProfile.value;
}
function setSelfAssessment(response: SelfAssessmentResponse) {