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,