diff --git a/src/users/dto/update-user.dto.ts b/src/users/dto/update-user.dto.ts index 8243a52..74ce283 100644 --- a/src/users/dto/update-user.dto.ts +++ b/src/users/dto/update-user.dto.ts @@ -59,6 +59,11 @@ export class UpdateUserDto { @ApiProperty({ description: '活动水平(1-5的枚举值)', example: 3, minimum: 1, maximum: 5 }) activityLevel?: number; + @IsString({ message: '语言偏好必须是字符串' }) + @IsOptional() + @ApiProperty({ description: '用户语言偏好', example: 'zh-CN', required: false }) + language?: string; + } export class UpdateUserResponseDto { diff --git a/src/users/models/user.model.ts b/src/users/models/user.model.ts index 1804924..8453b41 100644 --- a/src/users/models/user.model.ts +++ b/src/users/models/user.model.ts @@ -118,6 +118,14 @@ export class User extends Model { }) declare deviceName: string; + @Column({ + type: DataType.STRING, + allowNull: true, + defaultValue: 'zh-CN', + comment: '用户语言偏好(如:zh-CN、en-US)', + }) + declare language: string; + get isVip(): boolean { return this.membershipExpiration ? dayjs(this.membershipExpiration).isAfter(dayjs()) : false; } diff --git a/src/users/users.service.ts b/src/users/users.service.ts index 323ec47..a4b90e1 100644 --- a/src/users/users.service.ts +++ b/src/users/users.service.ts @@ -222,7 +222,7 @@ export class UsersService { // 更新用户昵称、头像 async updateUser(updateUserDto: UpdateUserDto, userId: string): Promise { - 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)}`); @@ -252,6 +252,10 @@ export class UsersService { user.birthDate = dayjs(birthDate * 1000).startOf('day').toDate(); userChanges.birthDate = birthDate; } + if (language) { + user.language = language; + userChanges.language = language; + } this.logger.log(`updateUser user: ${JSON.stringify(user, null, 2)}`);