From 2c04325152c91b742b5d47588114731060da9306 Mon Sep 17 00:00:00 2001 From: richarjiang Date: Thu, 14 Aug 2025 22:23:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=89=93=E5=8D=A1=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E7=9A=84=E5=88=9B=E5=BB=BA=E9=80=BB=E8=BE=91=EF=BC=8C?= =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=8F=82=E6=95=B0=E4=BC=A0=E9=80=92=E6=96=B9?= =?UTF-8?q?=E5=BC=8F=EF=BC=8C=E7=AE=80=E5=8C=96=E7=94=A8=E6=88=B7ID?= =?UTF-8?q?=E7=9A=84=E5=A4=84=E7=90=86=E3=80=82=E5=90=8C=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=AE=AD=E7=BB=83=E8=AE=A1=E5=88=92=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E7=9A=84=E8=BF=94=E5=9B=9E=E7=BB=93=E6=9E=84=EF=BC=8C?= =?UTF-8?q?=E7=9B=B4=E6=8E=A5=E8=BF=94=E5=9B=9E=E8=A1=8C=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E4=BB=A5=E6=8F=90=E5=8D=87=E6=80=A7=E8=83=BD=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/checkins/checkins.controller.ts | 2 +- src/checkins/checkins.service.ts | 10 ++++++---- src/training-plans/training-plans.service.ts | 7 +------ 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/checkins/checkins.controller.ts b/src/checkins/checkins.controller.ts index 6db201e..83a1b83 100644 --- a/src/checkins/checkins.controller.ts +++ b/src/checkins/checkins.controller.ts @@ -18,7 +18,7 @@ export class CheckinsController { @ApiBody({ type: CreateCheckinDto }) @ApiResponse({ type: CheckinResponseDto }) async create(@Body() dto: CreateCheckinDto, @CurrentUser() user: AccessTokenPayload): Promise { - return this.checkinsService.create({ ...dto, userId: user.sub }); + return this.checkinsService.create(dto, user.sub); } @Put('update') diff --git a/src/checkins/checkins.service.ts b/src/checkins/checkins.service.ts index 8a018c4..07e04a2 100644 --- a/src/checkins/checkins.service.ts +++ b/src/checkins/checkins.service.ts @@ -18,11 +18,11 @@ export class CheckinsService { private readonly activityLogsService: ActivityLogsService, ) { } - async create(dto: CreateCheckinDto): Promise { + async create(dto: CreateCheckinDto, userId: string): Promise { // 检查是否已存在未删除的记录 const existingRecord = await this.checkinModel.findOne({ where: { - userId: dto.userId, + userId, workoutId: dto.workoutId || null, planId: dto.planId || null, checkinDate: dto.checkinDate || null, @@ -30,12 +30,14 @@ export class CheckinsService { }, }); + // 存在则更新 if (existingRecord) { + await this.update({ ...dto, id: existingRecord.id! }, userId); return { code: ResponseCode.SUCCESS, message: 'success', data: existingRecord.toJSON() }; } const record = await this.checkinModel.create({ - userId: dto.userId, + userId, workoutId: dto.workoutId || null, planId: dto.planId || null, title: dto.title || null, @@ -47,7 +49,7 @@ export class CheckinsService { }); await this.activityLogsService.record({ - userId: record.userId, + userId, entityType: ActivityEntityType.CHECKIN, action: ActivityActionType.CREATE, entityId: record.id, diff --git a/src/training-plans/training-plans.service.ts b/src/training-plans/training-plans.service.ts index 090fe31..93b0045 100644 --- a/src/training-plans/training-plans.service.ts +++ b/src/training-plans/training-plans.service.ts @@ -95,12 +95,7 @@ export class TrainingPlansService { return { data: { - list: rows.map(r => ({ - id: r.id, - createdAt: r.createdAt, - startDate: r.startDate, - goal: r.goal, - })), + list: rows, total: count, page, limit,