feat(users): 添加用户语言偏好字段

- 在 User 模型中添加 language 字段,默认值为 'zh-CN'
- 更新 UpdateUserDto 以支持语言偏好参数
- 在用户更新服务中实现语言偏好的保存逻辑
This commit is contained in:
richarjiang
2025-11-27 11:17:27 +08:00
parent ac231a7742
commit 43f378d44d
3 changed files with 18 additions and 1 deletions

View File

@@ -59,6 +59,11 @@ export class UpdateUserDto {
@ApiProperty({ description: '活动水平1-5的枚举值', example: 3, minimum: 1, maximum: 5 }) @ApiProperty({ description: '活动水平1-5的枚举值', example: 3, minimum: 1, maximum: 5 })
activityLevel?: number; activityLevel?: number;
@IsString({ message: '语言偏好必须是字符串' })
@IsOptional()
@ApiProperty({ description: '用户语言偏好', example: 'zh-CN', required: false })
language?: string;
} }
export class UpdateUserResponseDto { export class UpdateUserResponseDto {

View File

@@ -118,6 +118,14 @@ export class User extends Model {
}) })
declare deviceName: string; declare deviceName: string;
@Column({
type: DataType.STRING,
allowNull: true,
defaultValue: 'zh-CN',
comment: '用户语言偏好zh-CN、en-US',
})
declare language: string;
get isVip(): boolean { get isVip(): boolean {
return this.membershipExpiration ? dayjs(this.membershipExpiration).isAfter(dayjs()) : false; return this.membershipExpiration ? dayjs(this.membershipExpiration).isAfter(dayjs()) : false;
} }

View File

@@ -222,7 +222,7 @@ export class UsersService {
// 更新用户昵称、头像 // 更新用户昵称、头像
async updateUser(updateUserDto: UpdateUserDto, userId: string): Promise<UpdateUserResponseDto> { async updateUser(updateUserDto: UpdateUserDto, userId: string): Promise<UpdateUserResponseDto> {
const { name, avatar, gender, birthDate, dailyStepsGoal, dailyCaloriesGoal, pilatesPurposes, weight, initialWeight, targetWeight, height, activityLevel } = updateUserDto; const { name, avatar, gender, birthDate, language, dailyStepsGoal, dailyCaloriesGoal, pilatesPurposes, weight, initialWeight, targetWeight, height, activityLevel } = updateUserDto;
this.logger.log(`updateUser: ${JSON.stringify(updateUserDto, null, 2)}`); this.logger.log(`updateUser: ${JSON.stringify(updateUserDto, null, 2)}`);
@@ -252,6 +252,10 @@ export class UsersService {
user.birthDate = dayjs(birthDate * 1000).startOf('day').toDate(); user.birthDate = dayjs(birthDate * 1000).startOf('day').toDate();
userChanges.birthDate = birthDate; userChanges.birthDate = birthDate;
} }
if (language) {
user.language = language;
userChanges.language = language;
}
this.logger.log(`updateUser user: ${JSON.stringify(user, null, 2)}`); this.logger.log(`updateUser user: ${JSON.stringify(user, null, 2)}`);