feat: 在用户资料中添加活动水平字段
- 更新用户资料相关逻辑,新增活动水平字段,支持用户在更新资料时提供活动水平信息。 - 修改相关DTO和模型,确保活动水平字段的有效性和数据一致性。 - 更新用户响应数据结构,包含活动水平信息,提升用户体验和数据完整性。
This commit is contained in:
@@ -109,6 +109,7 @@ export class UsersService {
|
||||
pilatesPurposes: profile?.pilatesPurposes,
|
||||
weight: profile?.weight,
|
||||
height: profile?.height,
|
||||
activityLevel: profile?.activityLevel,
|
||||
}
|
||||
|
||||
this.logger.log(`getProfile returnData: ${JSON.stringify(returnData, null, 2)}`);
|
||||
@@ -178,7 +179,7 @@ export class UsersService {
|
||||
|
||||
// 更新用户昵称、头像
|
||||
async updateUser(updateUserDto: UpdateUserDto): Promise<UpdateUserResponseDto> {
|
||||
const { userId, name, avatar, gender, birthDate, dailyStepsGoal, dailyCaloriesGoal, pilatesPurposes, weight, height } = updateUserDto;
|
||||
const { userId, name, avatar, gender, birthDate, dailyStepsGoal, dailyCaloriesGoal, pilatesPurposes, weight, height, activityLevel } = updateUserDto;
|
||||
|
||||
this.logger.log(`updateUser: ${JSON.stringify(updateUserDto, null, 2)}`);
|
||||
|
||||
@@ -214,7 +215,7 @@ export class UsersService {
|
||||
await user.save();
|
||||
|
||||
// 更新或创建扩展信息
|
||||
if (dailyStepsGoal !== undefined || dailyCaloriesGoal !== undefined || pilatesPurposes !== undefined || weight !== undefined || height !== undefined) {
|
||||
if (dailyStepsGoal !== undefined || dailyCaloriesGoal !== undefined || pilatesPurposes !== undefined || weight !== undefined || height !== undefined || activityLevel !== undefined) {
|
||||
const [profile] = await this.userProfileModel.findOrCreate({
|
||||
where: { userId },
|
||||
defaults: { userId },
|
||||
@@ -235,6 +236,10 @@ export class UsersService {
|
||||
profile.height = height;
|
||||
profileChanges.height = height;
|
||||
}
|
||||
if (activityLevel !== undefined) {
|
||||
profile.activityLevel = activityLevel;
|
||||
profileChanges.activityLevel = activityLevel;
|
||||
}
|
||||
await profile.save();
|
||||
}
|
||||
|
||||
@@ -646,6 +651,7 @@ export class UsersService {
|
||||
pilatesPurposes: profileForLogin.pilatesPurposes,
|
||||
weight: profileForLogin.weight,
|
||||
height: profileForLogin.height,
|
||||
activityLevel: profileForLogin.activityLevel,
|
||||
} : undefined,
|
||||
};
|
||||
|
||||
@@ -857,6 +863,7 @@ export class UsersService {
|
||||
pilatesPurposes: profileForGuest.pilatesPurposes,
|
||||
weight: profileForGuest.weight,
|
||||
height: profileForGuest.height,
|
||||
activityLevel: profileForGuest.activityLevel,
|
||||
} : undefined,
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user