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 { Controller, Get, Post, Patch, Delete, Param, Body, Query, Headers } from "@nestjs/common";
|
||||||
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiQuery } from '@nestjs/swagger';
|
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiQuery } from "@nestjs/swagger";
|
||||||
import { Request } from 'express';
|
import { ProjectService } from "../providers/project.service";
|
||||||
import { ProjectService } from '../providers/project.service';
|
import { CreateProjectDto } from "../dto/project/create-project.dto";
|
||||||
import { CreateProjectDto } from '../dto/project/create-project.dto';
|
import { UpdateProjectDto } from "../dto/project/update-project.dto";
|
||||||
import { UpdateProjectDto } from '../dto/project/update-project.dto';
|
import { PaginationDto } from "../../../common/DTO/pagination.dto";
|
||||||
import { PaginationDto } from '../../../common/DTO/pagination.dto';
|
import { TMProject } from "../entities/project.entity";
|
||||||
import { TMProject } from '../entities/project.entity';
|
|
||||||
|
|
||||||
@ApiTags('Task Manager - Projects')
|
@ApiTags("Task Manager - Projects")
|
||||||
@Controller('task-manager/projects')
|
@Controller("task-manager/projects")
|
||||||
export class ProjectController {
|
export class ProjectController {
|
||||||
constructor(private readonly projectService: ProjectService) {}
|
constructor(private readonly projectService: ProjectService) {}
|
||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
@ApiOperation({ summary: 'Get all projects, optionally filtered by workspace' })
|
@ApiOperation({ summary: "Get all projects, optionally filtered by workspace" })
|
||||||
@ApiQuery({ name: 'workspaceId', required: false, description: 'Filter projects by workspace ID' })
|
@ApiQuery({ name: "workspaceId", required: false, description: "Filter projects by workspace ID" })
|
||||||
@ApiResponse({ status: 200, description: 'Paginated list of projects' })
|
@ApiResponse({ status: 200, description: "Paginated list of projects" })
|
||||||
findAll(
|
findAll(
|
||||||
@Query() pagination: PaginationDto,
|
@Query() pagination: PaginationDto,
|
||||||
@Query('workspaceId') workspaceId: string,
|
@Query("workspaceId") workspaceId: string,
|
||||||
@Req() req: Request,
|
@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);
|
if (workspaceId) return this.projectService.findByWorkspace(workspaceId, pagination, baseUrl);
|
||||||
return this.projectService.findAll(pagination, baseUrl);
|
return this.projectService.findAll(pagination, baseUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get(':id')
|
@Get(":id")
|
||||||
@ApiOperation({ summary: 'Get a project by ID' })
|
@ApiOperation({ summary: "Get a project by ID" })
|
||||||
@ApiParam({ name: 'id', description: 'Project ID' })
|
@ApiParam({ name: "id", description: "Project ID" })
|
||||||
@ApiResponse({ status: 200, description: 'Project found', type: TMProject })
|
@ApiResponse({ status: 200, description: "Project found", type: TMProject })
|
||||||
@ApiResponse({ status: 404, description: 'Project not found' })
|
@ApiResponse({ status: 404, description: "Project not found" })
|
||||||
findOne(@Param('id') id: string): Promise<TMProject> {
|
findOne(@Param("id") id: string): Promise<TMProject> {
|
||||||
return this.projectService.findOne(id);
|
return this.projectService.findOne(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
@ApiOperation({ summary: 'Create a new project' })
|
@ApiOperation({ summary: "Create a new project" })
|
||||||
@ApiResponse({ status: 201, description: 'Project created', type: TMProject })
|
@ApiResponse({ status: 201, description: "Project created", type: TMProject })
|
||||||
@ApiResponse({ status: 400, description: 'One or more users are not members of the workspace' })
|
@ApiResponse({ status: 400, description: "One or more users are not members of the workspace" })
|
||||||
@ApiResponse({ status: 404, description: 'Workspace not found' })
|
@ApiResponse({ status: 404, description: "Workspace not found" })
|
||||||
create(@Body() body: CreateProjectDto): Promise<TMProject> {
|
create(@Body() body: CreateProjectDto): Promise<TMProject> {
|
||||||
return this.projectService.create(body);
|
return this.projectService.create(body);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Patch(':id')
|
@Patch(":id")
|
||||||
@ApiOperation({ summary: 'Update a project' })
|
@ApiOperation({ summary: "Update a project" })
|
||||||
@ApiParam({ name: 'id', description: 'Project ID' })
|
@ApiParam({ name: "id", description: "Project ID" })
|
||||||
@ApiResponse({ status: 200, description: 'Project updated', type: TMProject })
|
@ApiResponse({ status: 200, description: "Project updated", type: TMProject })
|
||||||
@ApiResponse({ status: 400, description: 'One or more users are not members of the workspace' })
|
@ApiResponse({ status: 400, description: "One or more users are not members of the workspace" })
|
||||||
@ApiResponse({ status: 404, description: 'Project not found' })
|
@ApiResponse({ status: 404, description: "Project not found" })
|
||||||
update(@Param('id') id: string, @Body() body: UpdateProjectDto): Promise<TMProject> {
|
update(@Param("id") id: string, @Body() body: UpdateProjectDto): Promise<TMProject> {
|
||||||
return this.projectService.update(id, body);
|
return this.projectService.update(id, body);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Delete(':id')
|
@Delete(":id")
|
||||||
@ApiOperation({ summary: 'Delete a project' })
|
@ApiOperation({ summary: "Delete a project" })
|
||||||
@ApiParam({ name: 'id', description: 'Project ID' })
|
@ApiParam({ name: "id", description: "Project ID" })
|
||||||
@ApiResponse({ status: 200, description: 'Project deleted', type: TMProject })
|
@ApiResponse({ status: 200, description: "Project deleted", type: TMProject })
|
||||||
@ApiResponse({ status: 404, description: 'Project not found' })
|
@ApiResponse({ status: 404, description: "Project not found" })
|
||||||
remove(@Param('id') id: string): Promise<TMProject> {
|
remove(@Param("id") id: string): Promise<TMProject> {
|
||||||
return this.projectService.remove(id);
|
return this.projectService.remove(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ export class WorkspaceRepository {
|
|||||||
findOneById(id: string) {
|
findOneById(id: string) {
|
||||||
return this.repository.findOne({
|
return this.repository.findOne({
|
||||||
where: { id },
|
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 { RemarkController } from "./controllers/remark.controller";
|
||||||
import { RemarkRepository } from "./repositories/remark.repository";
|
import { RemarkRepository } from "./repositories/remark.repository";
|
||||||
import { RemarkService } from "./providers/remark.service";
|
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({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
@@ -43,7 +46,8 @@ import { RemarkService } from "./providers/remark.service";
|
|||||||
TaskPhaseController,
|
TaskPhaseController,
|
||||||
TaskController,
|
TaskController,
|
||||||
CheckListItemController,
|
CheckListItemController,
|
||||||
RemarkController
|
RemarkController,
|
||||||
|
AttachmentController
|
||||||
],
|
],
|
||||||
providers: [
|
providers: [
|
||||||
WorkspaceRepository,
|
WorkspaceRepository,
|
||||||
@@ -59,7 +63,9 @@ import { RemarkService } from "./providers/remark.service";
|
|||||||
CheckListItemRepository,
|
CheckListItemRepository,
|
||||||
CheckListItemService,
|
CheckListItemService,
|
||||||
RemarkRepository,
|
RemarkRepository,
|
||||||
RemarkService
|
RemarkService,
|
||||||
|
AttachmentRepository,
|
||||||
|
AttachmentService
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
export class TaskManagerModule {}
|
export class TaskManagerModule {}
|
||||||
|
|||||||
Reference in New Issue
Block a user