refactor: made project service to use pagination
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
import { Controller, Get, Post, Patch, Delete, Param, Body, Query } from '@nestjs/common';
|
||||
import { Controller, Get, Post, Patch, Delete, Param, Body, Query, Req } from '@nestjs/common';
|
||||
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiQuery } from '@nestjs/swagger';
|
||||
import { Request } from 'express';
|
||||
import { ProjectService } from '../providers/project.service';
|
||||
import { CreateProjectDto } from '../dto/project/create-project.dto';
|
||||
import { UpdateProjectDto } from '../dto/project/update-project.dto';
|
||||
import { PaginationDto } from '../../../common/DTO/pagination.dto';
|
||||
import { TMProject } from '../entities/project.entity';
|
||||
|
||||
@ApiTags('Task Manager - Projects')
|
||||
@@ -13,10 +15,15 @@ export class ProjectController {
|
||||
@Get()
|
||||
@ApiOperation({ summary: 'Get all projects, optionally filtered by workspace' })
|
||||
@ApiQuery({ name: 'workspaceId', required: false, description: 'Filter projects by workspace ID' })
|
||||
@ApiResponse({ status: 200, description: 'List of projects', type: [TMProject] })
|
||||
findAll(@Query('workspaceId') workspaceId?: string): Promise<TMProject[]> {
|
||||
if (workspaceId) return this.projectService.findByWorkspace(workspaceId);
|
||||
return this.projectService.findAll();
|
||||
@ApiResponse({ status: 200, description: 'Paginated list of projects' })
|
||||
findAll(
|
||||
@Query() pagination: PaginationDto,
|
||||
@Query('workspaceId') workspaceId: string,
|
||||
@Req() req: Request,
|
||||
) {
|
||||
const baseUrl = `${req.protocol}://${req.get('host')}${req.path}`;
|
||||
if (workspaceId) return this.projectService.findByWorkspace(workspaceId, pagination, baseUrl);
|
||||
return this.projectService.findAll(pagination, baseUrl);
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
@@ -50,7 +57,7 @@ export class ProjectController {
|
||||
@Delete(':id')
|
||||
@ApiOperation({ summary: 'Delete a project' })
|
||||
@ApiParam({ name: 'id', description: 'Project ID' })
|
||||
@ApiResponse({ status: 200, description: 'Project deleted' })
|
||||
@ApiResponse({ status: 200, description: 'Project deleted', type: TMProject })
|
||||
@ApiResponse({ status: 404, description: 'Project not found' })
|
||||
remove(@Param('id') id: string): Promise<TMProject> {
|
||||
return this.projectService.remove(id);
|
||||
|
||||
Reference in New Issue
Block a user