Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/plant/plant.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ export class PlantController {
return this.plantService.getAllPlants(req.user.id);
}

@Get('count')
@ApiOperation({ summary: "Get total number of plants for the user's farm" })
@ApiResponse({ status: 200, description: 'Total plant count returned' })
@ApiResponse({
status: 404,
description: 'Farm not found for the user',
})
getPlantCount(@Req() req: RequestWithUser) {
return this.plantService.getPlantCount(req.user.id);
}

@Get(':id')
@ApiOperation({ summary: 'Get a specific plant by ID' })
@ApiResponse({
Expand Down
7 changes: 7 additions & 0 deletions src/plant/plant.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ export class PlantService {
});
}

async getPlantCount(userId: number): Promise<number> {
const farm = await this.farmService.getFarmByUserId(userId);
return await this.prisma.plant.count({
where: { farm_id: farm.id },
});
}

async getPlantById(id: number) {
const plant = await this.prisma.plant.findUnique({ where: { id } });
if (!plant) {
Expand Down
5 changes: 5 additions & 0 deletions src/posts/posts.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ export class PostsController {
return this.postsService.getFeed(req.user.id);
}

@Get('count')
getTotalPostsCount() {
return this.postsService.getTotalPostsCount();
}

@Get(':id')
findOne(@Param('id', ParseIntPipe) id: number, @Req() req: RequestWithUser) {
return this.postsService.findOne(req.user.id, id, 'view');
Expand Down
4 changes: 4 additions & 0 deletions src/posts/posts.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,4 +375,8 @@ export class PostsService {
}
}
}

async getTotalPostsCount() {
return this.prisma.forumPost.count();
}
}
10 changes: 10 additions & 0 deletions src/tasks/tasks.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,16 @@ export class TasksController {
return this.tasksService.getTasksByStatus(req.user.id, status);
}

@Get('upcoming')
@ApiOperation({ summary: 'Get upcoming tasks (PENDING or IN_PROGRESS)' })
@ApiResponse({
status: 200,
description: 'Upcoming tasks retrieved successfully',
})
getUpcomingTasks(@Req() req: RequestWithUser) {
return this.tasksService.getUpcomingTasks(req.user.id);
}

@Patch(':id')
@ApiOperation({ summary: 'Update task' })
@ApiResponse({
Expand Down
20 changes: 20 additions & 0 deletions src/tasks/tasks.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,26 @@ export class TasksService {
}
}

async getUpcomingTasks(userId: number) {
try {
return this.prisma.task.findMany({
where: {
user_id: userId,
status: {
in: [TaskStatus.PENDING, TaskStatus.IN_PROGRESS],
},
},
orderBy: { due_date: 'asc' },
take: 4,
});
} catch (error) {
throw new InternalServerErrorException(
error,
'Failed to retrieve upcoming tasks',
);
}
}

async updateTask(taskId: number, data: UpdateTaskDto, userId: number) {
const task = await this.getTaskById(taskId);
if (!task) {
Expand Down