From e719c959aa3ae96cb6b50da8d297ea7acd47df4b Mon Sep 17 00:00:00 2001 From: richarjiang Date: Sat, 16 Aug 2025 14:19:50 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=BC=BA=E8=87=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E8=AE=AD=E7=BB=83=E4=BC=9A=E8=AF=9D=E5=88=9B=E5=BB=BA=E9=80=BB?= =?UTF-8?q?=E8=BE=91=EF=BC=8C=E6=B7=BB=E5=8A=A0=E8=AF=A6=E7=BB=86=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E8=AE=B0=E5=BD=95=E4=BB=A5=E4=BE=BF=E4=BA=8E=E8=B0=83?= =?UTF-8?q?=E8=AF=95=E5=92=8C=E9=94=99=E8=AF=AF=E8=BF=BD=E8=B8=AA=EF=BC=9B?= =?UTF-8?q?=E8=B0=83=E6=95=B4=E8=AE=AD=E7=BB=83=E4=BC=9A=E8=AF=9D=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E6=8E=92=E5=BA=8F=E6=96=B9=E5=BC=8F=EF=BC=8C=E6=94=B9?= =?UTF-8?q?=E4=B8=BA=E6=8C=89=E5=88=9B=E5=BB=BA=E6=97=B6=E9=97=B4=E6=8E=92?= =?UTF-8?q?=E5=BA=8F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/workouts/workouts.service.ts | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/workouts/workouts.service.ts b/src/workouts/workouts.service.ts index b60e932..e99be24 100644 --- a/src/workouts/workouts.service.ts +++ b/src/workouts/workouts.service.ts @@ -125,11 +125,17 @@ export class WorkoutsService { const transaction = await this.workoutSessionModel.sequelize?.transaction(); if (!transaction) throw new Error('Failed to start transaction'); + this.winstonLogger.info(`创建自定义训练会话`, { + context: 'WorkoutsService', + userId, + dto, + }); + try { // 1. 创建训练会话 const workoutSession = await this.workoutSessionModel.create({ userId, - trainingPlanId: null, // 自定义训练不关联训练计划 + name: dto.name, scheduledDate: dto.scheduledDate ? new Date(dto.scheduledDate) : new Date(), status: 'planned', @@ -163,17 +169,23 @@ export class WorkoutsService { } } - await transaction.commit(); - this.winstonLogger.info(`创建自定义训练会话 ${workoutSession.id}`, { context: 'WorkoutsService', userId, workoutSessionId: workoutSession.id, - exerciseCount: dto.customExercises!.length, + exerciseCount: dto.customExercises?.length, }); + + await transaction.commit(); return workoutSession.toJSON(); } catch (error) { + this.winstonLogger.error(`创建自定义训练会话失败`, { + context: 'WorkoutsService', + userId, + dto, + error, + }); await transaction.rollback(); throw error; } @@ -309,7 +321,7 @@ export class WorkoutsService { attributes: ['id', 'name', 'goal'] } ], - order: [['scheduledDate', 'DESC']], + order: [['createdAt', 'DESC']], limit, offset, });