feat: 基本資料修改
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user