refactor: changed functions to use pagination logic correctly

This commit is contained in:
2026-07-05 19:20:08 +03:30
parent a14bd490be
commit 9f61152d94
5 changed files with 63 additions and 69 deletions
@@ -1,5 +1,5 @@
import { Controller, Get, Post, Patch, Delete, Param, Body, Query, Headers } from "@nestjs/common";
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiQuery } from "@nestjs/swagger";
import { Controller, Get, Post, Patch, Delete, Param, Body, Query } from "@nestjs/common";
import { ApiTags, ApiOperation, ApiResponse, ApiParam } from "@nestjs/swagger";
import { ProjectService } from "../providers/project.service";
import { CreateProjectDto } from "../dto/project/create-project.dto";
import { UpdateProjectDto } from "../dto/project/update-project.dto";
@@ -18,18 +18,9 @@ export class ProjectController {
@Get()
@PermissionsDec(PermissionEnum.PROJECT)
@ApiOperation({ summary: "Get all projects, optionally filtered by workspace" })
@ApiQuery({ name: "workspaceId", required: false, description: "Filter projects by workspace ID" })
@ApiResponse({ status: 200, description: "Paginated list of projects" })
findAll(
@Query() pagination: PaginationDto,
@Query("workspaceId") workspaceId: string,
@Headers("host") host: string,
@Headers("x-forwarded-proto") proto?: string,
) {
const protocol = proto ?? "http";
const baseUrl = `${protocol}://${host}/task-manager/projects`;
if (workspaceId) return this.projectService.findByWorkspace(workspaceId, pagination, baseUrl);
return this.projectService.findAll(pagination, baseUrl);
findAll(@Query() pagination: PaginationDto): Promise<{ projects: TMProject[]; count: number; paginate: true }> {
return this.projectService.findAll(pagination);
}
@Get(":id")
@@ -74,11 +65,15 @@ export class ProjectController {
}
@Get("/workspace/:wsId")
@ApiOperation({summary: "Get projects of a specific workspace"})
@PermissionsDec(PermissionEnum.PROJECT)
@ApiOperation({ summary: "Get projects of a specific workspace" })
@ApiParam({ name: "wsId", description: "Workspace ID" })
@ApiResponse({ status: 200, description: "received projects successfully!"})
@ApiResponse({ status: 200, description: "received projects successfully!" })
@ApiResponse({ status: 404, description: "WorkSpace not found" })
findByWorkspace(@Param("wsId") wsId: string): Promise<TMProject[]> {
return this.findByWorkspace(wsId);
findByWorkspace(
@Param("wsId") wsId: string,
@Query() pagination: PaginationDto,
): Promise<{ projects: TMProject[]; count: number; paginate: true }> {
return this.projectService.findByWorkspace(wsId, pagination);
}
}