feat: 移除获取目标和任务详情的API及相关逻辑
- 删除GoalsController和GoalsService中获取单个目标和任务详情的API实现,简化代码结构。 - 更新GoalTaskService中的分页参数,将每页数量调整为200,提升数据处理能力。 - 优化GoalTaskQueryDto,移除页码和每页数量的验证装饰器,简化DTO结构。
This commit is contained in:
@@ -83,14 +83,12 @@ export class GoalTaskQueryDto {
|
||||
|
||||
@IsOptional()
|
||||
@IsInt()
|
||||
@Min(1, { message: '页码必须大于0' })
|
||||
|
||||
page?: number = 1;
|
||||
|
||||
@IsOptional()
|
||||
@IsInt()
|
||||
@Min(1, { message: '每页数量必须大于0' })
|
||||
@Max(100, { message: '每页数量不能超过100' })
|
||||
pageSize?: number = 20;
|
||||
pageSize?: number = 200;
|
||||
}
|
||||
|
||||
export class CompleteGoalTaskDto {
|
||||
|
||||
@@ -64,21 +64,6 @@ export class GoalsController {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取单个目标详情
|
||||
*/
|
||||
@Get(':id')
|
||||
async getGoal(
|
||||
@Param('id') id: string,
|
||||
@CurrentUser() user: AccessTokenPayload,
|
||||
): Promise<BaseResponseDto<any>> {
|
||||
const goal = await this.goalsService.getGoal(user.sub, id);
|
||||
return {
|
||||
code: ResponseCode.SUCCESS,
|
||||
message: '获取目标详情成功',
|
||||
data: goal,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新目标
|
||||
@@ -227,22 +212,6 @@ export class GoalsController {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取单个任务详情
|
||||
*/
|
||||
@Get('tasks/:taskId')
|
||||
async getTask(
|
||||
@Param('taskId') taskId: string,
|
||||
@CurrentUser() user: AccessTokenPayload,
|
||||
): Promise<BaseResponseDto<any>> {
|
||||
const task = await this.goalTaskService.getTask(user.sub, taskId);
|
||||
return {
|
||||
code: ResponseCode.SUCCESS,
|
||||
message: '获取任务详情成功',
|
||||
data: task,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 完成任务
|
||||
*/
|
||||
|
||||
@@ -136,46 +136,6 @@ export class GoalsService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取单个目标详情
|
||||
*/
|
||||
async getGoal(userId: string, goalId: string): Promise<Goal> {
|
||||
try {
|
||||
// 惰性生成任务
|
||||
await this.goalTaskService.generateTasksLazily(userId, goalId);
|
||||
|
||||
const goal = await this.goalModel.findOne({
|
||||
where: { id: goalId, userId, deleted: false },
|
||||
include: [
|
||||
{
|
||||
model: GoalCompletion,
|
||||
as: 'completions',
|
||||
where: { deleted: false },
|
||||
required: false,
|
||||
order: [['completedAt', 'DESC']],
|
||||
limit: 10, // 只显示最近10次完成记录
|
||||
},
|
||||
{
|
||||
model: GoalTask,
|
||||
as: 'tasks',
|
||||
where: { deleted: false },
|
||||
required: false,
|
||||
order: [['startDate', 'ASC']],
|
||||
limit: 20, // 显示最近20个任务
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
if (!goal) {
|
||||
throw new NotFoundException('目标不存在');
|
||||
}
|
||||
|
||||
return this.formatGoalResponse(goal);
|
||||
} catch (error) {
|
||||
this.logger.error(`获取目标详情失败: ${error.message}`);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新目标
|
||||
|
||||
@@ -314,7 +314,7 @@ export class GoalTaskService {
|
||||
// 先进行惰性生成
|
||||
await this.generateTasksLazily(userId, query.goalId);
|
||||
|
||||
const { page = 1, pageSize = 20, goalId, status, startDate, endDate } = query;
|
||||
const { page = 1, pageSize = 200, goalId, status, startDate, endDate } = query;
|
||||
const offset = (page - 1) * pageSize;
|
||||
|
||||
const where: WhereOptions = {
|
||||
@@ -345,13 +345,6 @@ export class GoalTaskService {
|
||||
order: [['startDate', 'ASC'], ['createdAt', 'DESC']],
|
||||
offset,
|
||||
limit: pageSize,
|
||||
include: [
|
||||
{
|
||||
model: Goal,
|
||||
as: 'goal',
|
||||
attributes: ['id', 'title', 'repeatType', 'frequency', 'category'],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
return {
|
||||
@@ -366,33 +359,6 @@ export class GoalTaskService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取单个任务详情
|
||||
*/
|
||||
async getTask(userId: string, taskId: string): Promise<GoalTask> {
|
||||
try {
|
||||
const task = await this.goalTaskModel.findOne({
|
||||
where: { id: taskId, userId, deleted: false },
|
||||
include: [
|
||||
{
|
||||
model: Goal,
|
||||
as: 'goal',
|
||||
attributes: ['id', 'title', 'repeatType', 'frequency', 'category'],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
if (!task) {
|
||||
throw new NotFoundException('任务不存在');
|
||||
}
|
||||
|
||||
return this.formatTaskResponse(task);
|
||||
} catch (error) {
|
||||
this.logger.error(`获取任务详情失败: ${error.message}`);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 完成任务
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user