优化打卡服务的创建逻辑,调整参数传递方式,简化用户ID的处理。同时,更新训练计划服务的返回结构,直接返回行数据以提升性能。

This commit is contained in:
2025-08-14 22:23:50 +08:00
parent bef2c2d910
commit 2c04325152
3 changed files with 8 additions and 11 deletions

View File

@@ -18,11 +18,11 @@ export class CheckinsService {
private readonly activityLogsService: ActivityLogsService,
) { }
async create(dto: CreateCheckinDto): Promise<CheckinResponseDto> {
async create(dto: CreateCheckinDto, userId: string): Promise<CheckinResponseDto> {
// 检查是否已存在未删除的记录
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,