diff --git a/src/users/dto/update-user.dto.ts b/src/users/dto/update-user.dto.ts index 4824c22..c3d8cc2 100644 --- a/src/users/dto/update-user.dto.ts +++ b/src/users/dto/update-user.dto.ts @@ -52,6 +52,10 @@ export class UpdateUserDto { @ApiProperty({ description: '身高(厘米)', example: 168 }) height?: number; + @IsOptional() + @ApiProperty({ description: '活动水平(1-5的枚举值)', example: 3, minimum: 1, maximum: 5 }) + activityLevel?: number; + } export class UpdateUserResponseDto { diff --git a/src/users/dto/user-response.dto.ts b/src/users/dto/user-response.dto.ts index ce7a976..00cacad 100644 --- a/src/users/dto/user-response.dto.ts +++ b/src/users/dto/user-response.dto.ts @@ -25,7 +25,7 @@ export interface UserWithPurchaseStatus { maxUsageCount: number; favoriteTopicCount: number; isVip: boolean; - profile?: Pick; + profile?: Pick; } export class UserResponseDto implements BaseResponseDto { diff --git a/src/users/models/user-profile.model.ts b/src/users/models/user-profile.model.ts index 2d82017..71f39ca 100644 --- a/src/users/models/user-profile.model.ts +++ b/src/users/models/user-profile.model.ts @@ -1,6 +1,14 @@ import { BelongsTo, Column, DataType, ForeignKey, Model, Table } from 'sequelize-typescript'; import { User } from './user.model'; +export enum ActivityLevel { + LEVEL_1 = 1, + LEVEL_2 = 2, + LEVEL_3 = 3, + LEVEL_4 = 4, + LEVEL_5 = 5, +} + @Table({ tableName: 't_user_profile', underscored: true, @@ -53,6 +61,17 @@ export class UserProfile extends Model { }) declare height: number | null; + @Column({ + type: DataType.INTEGER, + allowNull: true, + comment: '活动水平(1-5的枚举值)', + validate: { + min: 1, + max: 5, + }, + }) + declare activityLevel: ActivityLevel | null; + @Column({ type: DataType.DATE, defaultValue: DataType.NOW, @@ -64,6 +83,4 @@ export class UserProfile extends Model { defaultValue: DataType.NOW, }) declare updatedAt: Date; -} - - +} \ No newline at end of file diff --git a/src/users/users.service.ts b/src/users/users.service.ts index 19afa6b..71bd708 100644 --- a/src/users/users.service.ts +++ b/src/users/users.service.ts @@ -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 { - 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, };