优化打卡服务的创建逻辑,调整参数传递方式,简化用户ID的处理。同时,更新训练计划服务的返回结构,直接返回行数据以提升性能。
This commit is contained in:
@@ -18,7 +18,7 @@ export class CheckinsController {
|
|||||||
@ApiBody({ type: CreateCheckinDto })
|
@ApiBody({ type: CreateCheckinDto })
|
||||||
@ApiResponse({ type: CheckinResponseDto })
|
@ApiResponse({ type: CheckinResponseDto })
|
||||||
async create(@Body() dto: CreateCheckinDto, @CurrentUser() user: AccessTokenPayload): Promise<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')
|
@Put('update')
|
||||||
|
|||||||
@@ -18,11 +18,11 @@ export class CheckinsService {
|
|||||||
private readonly activityLogsService: ActivityLogsService,
|
private readonly activityLogsService: ActivityLogsService,
|
||||||
) { }
|
) { }
|
||||||
|
|
||||||
async create(dto: CreateCheckinDto): Promise<CheckinResponseDto> {
|
async create(dto: CreateCheckinDto, userId: string): Promise<CheckinResponseDto> {
|
||||||
// 检查是否已存在未删除的记录
|
// 检查是否已存在未删除的记录
|
||||||
const existingRecord = await this.checkinModel.findOne({
|
const existingRecord = await this.checkinModel.findOne({
|
||||||
where: {
|
where: {
|
||||||
userId: dto.userId,
|
userId,
|
||||||
workoutId: dto.workoutId || null,
|
workoutId: dto.workoutId || null,
|
||||||
planId: dto.planId || null,
|
planId: dto.planId || null,
|
||||||
checkinDate: dto.checkinDate || null,
|
checkinDate: dto.checkinDate || null,
|
||||||
@@ -30,12 +30,14 @@ export class CheckinsService {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 存在则更新
|
||||||
if (existingRecord) {
|
if (existingRecord) {
|
||||||
|
await this.update({ ...dto, id: existingRecord.id! }, userId);
|
||||||
return { code: ResponseCode.SUCCESS, message: 'success', data: existingRecord.toJSON() };
|
return { code: ResponseCode.SUCCESS, message: 'success', data: existingRecord.toJSON() };
|
||||||
}
|
}
|
||||||
|
|
||||||
const record = await this.checkinModel.create({
|
const record = await this.checkinModel.create({
|
||||||
userId: dto.userId,
|
userId,
|
||||||
workoutId: dto.workoutId || null,
|
workoutId: dto.workoutId || null,
|
||||||
planId: dto.planId || null,
|
planId: dto.planId || null,
|
||||||
title: dto.title || null,
|
title: dto.title || null,
|
||||||
@@ -47,7 +49,7 @@ export class CheckinsService {
|
|||||||
});
|
});
|
||||||
|
|
||||||
await this.activityLogsService.record({
|
await this.activityLogsService.record({
|
||||||
userId: record.userId,
|
userId,
|
||||||
entityType: ActivityEntityType.CHECKIN,
|
entityType: ActivityEntityType.CHECKIN,
|
||||||
action: ActivityActionType.CREATE,
|
action: ActivityActionType.CREATE,
|
||||||
entityId: record.id,
|
entityId: record.id,
|
||||||
|
|||||||
@@ -95,12 +95,7 @@ export class TrainingPlansService {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
data: {
|
data: {
|
||||||
list: rows.map(r => ({
|
list: rows,
|
||||||
id: r.id,
|
|
||||||
createdAt: r.createdAt,
|
|
||||||
startDate: r.startDate,
|
|
||||||
goal: r.goal,
|
|
||||||
})),
|
|
||||||
total: count,
|
total: count,
|
||||||
page,
|
page,
|
||||||
limit,
|
limit,
|
||||||
|
|||||||
Reference in New Issue
Block a user