From 8aca29e2b33b60497a17319169bd2871fbea5016 Mon Sep 17 00:00:00 2001 From: richarjiang Date: Tue, 26 Aug 2025 22:12:46 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0=E7=9B=AE=E6=A0=87?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=80=BB=E8=BE=91=EF=BC=8C=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E8=AE=B0=E5=BD=95=E5=92=8C=E6=97=A5=E6=9C=9F?= =?UTF-8?q?=E5=A4=84=E7=90=86=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在updateGoal方法中添加日志记录,便于调试和监控目标更新过程。 - 优化目标更新时的日期处理逻辑,确保endDate字段在未提供时设置为undefined,提升数据的灵活性。 --- src/goals/goals.service.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/goals/goals.service.ts b/src/goals/goals.service.ts index 21c4745..a840ce8 100644 --- a/src/goals/goals.service.ts +++ b/src/goals/goals.service.ts @@ -146,6 +146,7 @@ export class GoalsService { */ async updateGoal(userId: string, goalId: string, updateGoalDto: UpdateGoalDto): Promise { try { + this.logger.log(`updateGoal updateGoalDto: ${JSON.stringify(updateGoalDto, null, 2)}`); const goal = await this.goalModel.findOne({ where: { id: goalId, userId, deleted: false }, }); @@ -166,10 +167,11 @@ export class GoalsService { throw new BadRequestException('已完成的目标不能修改状态'); } + + await goal.update({ ...updateGoalDto, - startDate: updateGoalDto.startDate ? new Date(updateGoalDto.startDate) : goal.startDate, - endDate: updateGoalDto.endDate ? new Date(updateGoalDto.endDate) : goal.endDate, + endDate: updateGoalDto.endDate ? new Date(updateGoalDto.endDate) : undefined, }); this.logger.log(`用户 ${userId} 更新了目标: ${goal.title}`);