fix: fixing some errors in project service and controller
This commit is contained in:
@@ -1,65 +1,66 @@
|
||||
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';
|
||||
import { Controller, Get, Post, Patch, Delete, Param, Body, Query, Headers } from "@nestjs/common";
|
||||
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiQuery } 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";
|
||||
import { PaginationDto } from "../../../common/DTO/pagination.dto";
|
||||
import { TMProject } from "../entities/project.entity";
|
||||
|
||||
@ApiTags('Task Manager - Projects')
|
||||
@Controller('task-manager/projects')
|
||||
@ApiTags("Task Manager - Projects")
|
||||
@Controller("task-manager/projects")
|
||||
export class ProjectController {
|
||||
constructor(private readonly projectService: ProjectService) {}
|
||||
|
||||
@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: 'Paginated list of projects' })
|
||||
@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,
|
||||
@Req() req: Request,
|
||||
@Query("workspaceId") workspaceId: string,
|
||||
@Headers("host") host: string,
|
||||
@Headers("x-forwarded-proto") proto?: string,
|
||||
) {
|
||||
const baseUrl = `${req.protocol}://${req.get('host')}${req.path}`;
|
||||
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);
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
@ApiOperation({ summary: 'Get a project by ID' })
|
||||
@ApiParam({ name: 'id', description: 'Project ID' })
|
||||
@ApiResponse({ status: 200, description: 'Project found', type: TMProject })
|
||||
@ApiResponse({ status: 404, description: 'Project not found' })
|
||||
findOne(@Param('id') id: string): Promise<TMProject> {
|
||||
@Get(":id")
|
||||
@ApiOperation({ summary: "Get a project by ID" })
|
||||
@ApiParam({ name: "id", description: "Project ID" })
|
||||
@ApiResponse({ status: 200, description: "Project found", type: TMProject })
|
||||
@ApiResponse({ status: 404, description: "Project not found" })
|
||||
findOne(@Param("id") id: string): Promise<TMProject> {
|
||||
return this.projectService.findOne(id);
|
||||
}
|
||||
|
||||
@Post()
|
||||
@ApiOperation({ summary: 'Create a new project' })
|
||||
@ApiResponse({ status: 201, description: 'Project created', type: TMProject })
|
||||
@ApiResponse({ status: 400, description: 'One or more users are not members of the workspace' })
|
||||
@ApiResponse({ status: 404, description: 'Workspace not found' })
|
||||
@ApiOperation({ summary: "Create a new project" })
|
||||
@ApiResponse({ status: 201, description: "Project created", type: TMProject })
|
||||
@ApiResponse({ status: 400, description: "One or more users are not members of the workspace" })
|
||||
@ApiResponse({ status: 404, description: "Workspace not found" })
|
||||
create(@Body() body: CreateProjectDto): Promise<TMProject> {
|
||||
return this.projectService.create(body);
|
||||
}
|
||||
|
||||
@Patch(':id')
|
||||
@ApiOperation({ summary: 'Update a project' })
|
||||
@ApiParam({ name: 'id', description: 'Project ID' })
|
||||
@ApiResponse({ status: 200, description: 'Project updated', type: TMProject })
|
||||
@ApiResponse({ status: 400, description: 'One or more users are not members of the workspace' })
|
||||
@ApiResponse({ status: 404, description: 'Project not found' })
|
||||
update(@Param('id') id: string, @Body() body: UpdateProjectDto): Promise<TMProject> {
|
||||
@Patch(":id")
|
||||
@ApiOperation({ summary: "Update a project" })
|
||||
@ApiParam({ name: "id", description: "Project ID" })
|
||||
@ApiResponse({ status: 200, description: "Project updated", type: TMProject })
|
||||
@ApiResponse({ status: 400, description: "One or more users are not members of the workspace" })
|
||||
@ApiResponse({ status: 404, description: "Project not found" })
|
||||
update(@Param("id") id: string, @Body() body: UpdateProjectDto): Promise<TMProject> {
|
||||
return this.projectService.update(id, body);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
@ApiOperation({ summary: 'Delete a project' })
|
||||
@ApiParam({ name: 'id', description: 'Project ID' })
|
||||
@ApiResponse({ status: 200, description: 'Project deleted', type: TMProject })
|
||||
@ApiResponse({ status: 404, description: 'Project not found' })
|
||||
remove(@Param('id') id: string): Promise<TMProject> {
|
||||
@Delete(":id")
|
||||
@ApiOperation({ summary: "Delete a project" })
|
||||
@ApiParam({ name: "id", description: "Project ID" })
|
||||
@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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ export class WorkspaceRepository {
|
||||
findOneById(id: string) {
|
||||
return this.repository.findOne({
|
||||
where: { id },
|
||||
relations: ["workspaceType", "projects", "users"],
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,9 @@ import { CheckListItemController } from "./controllers/check-list-item.controlle
|
||||
import { RemarkController } from "./controllers/remark.controller";
|
||||
import { RemarkRepository } from "./repositories/remark.repository";
|
||||
import { RemarkService } from "./providers/remark.service";
|
||||
import { AttachmentController } from "./controllers/attachment.controller";
|
||||
import { AttachmentRepository } from "./repositories/attachment.repository";
|
||||
import { AttachmentService } from "./providers/attachment.service";
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
@@ -43,7 +46,8 @@ import { RemarkService } from "./providers/remark.service";
|
||||
TaskPhaseController,
|
||||
TaskController,
|
||||
CheckListItemController,
|
||||
RemarkController
|
||||
RemarkController,
|
||||
AttachmentController
|
||||
],
|
||||
providers: [
|
||||
WorkspaceRepository,
|
||||
@@ -59,7 +63,9 @@ import { RemarkService } from "./providers/remark.service";
|
||||
CheckListItemRepository,
|
||||
CheckListItemService,
|
||||
RemarkRepository,
|
||||
RemarkService
|
||||
RemarkService,
|
||||
AttachmentRepository,
|
||||
AttachmentService
|
||||
]
|
||||
})
|
||||
export class TaskManagerModule {}
|
||||
|
||||
Reference in New Issue
Block a user