From 43f378d44dccd75fddd7d67b2d32cffc490e2d8b Mon Sep 17 00:00:00 2001 From: richarjiang Date: Thu, 27 Nov 2025 11:17:27 +0800 Subject: [PATCH] =?UTF-8?q?feat(users):=20=E6=B7=BB=E5=8A=A0=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E8=AF=AD=E8=A8=80=E5=81=8F=E5=A5=BD=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 User 模型中添加 language 字段,默认值为 'zh-CN' - 更新 UpdateUserDto 以支持语言偏好参数 - 在用户更新服务中实现语言偏好的保存逻辑 --- src/users/dto/update-user.dto.ts | 5 +++++ src/users/models/user.model.ts | 8 ++++++++ src/users/users.service.ts | 6 +++++- 3 files changed, 18 insertions(+), 1 deletion(-) 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)}`);