feat(users): 添加用户语言偏好字段
- 在 User 模型中添加 language 字段,默认值为 'zh-CN' - 更新 UpdateUserDto 以支持语言偏好参数 - 在用户更新服务中实现语言偏好的保存逻辑
This commit is contained in:
@@ -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 {
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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)}`);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user