优化打卡服务的创建逻辑,调整参数传递方式,简化用户ID的处理。同时,更新训练计划服务的返回结构,直接返回行数据以提升性能。
This commit is contained in:
@@ -18,7 +18,7 @@ export class CheckinsController {
|
||||
@ApiBody({ type: CreateCheckinDto })
|
||||
@ApiResponse({ type: CheckinResponseDto })
|
||||
async create(@Body() dto: CreateCheckinDto, @CurrentUser() user: AccessTokenPayload): Promise<CheckinResponseDto> {
|
||||
return this.checkinsService.create({ ...dto, userId: user.sub });
|
||||
return this.checkinsService.create(dto, user.sub);
|
||||
}
|
||||
|
||||
@Put('update')
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user