75 lines
3.6 KiB
TypeScript
75 lines
3.6 KiB
TypeScript
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";
|
|
import { PaginationDto } from "../../../common/DTO/pagination.dto";
|
|
import { TMProject } from "../entities/project.entity";
|
|
import { AdminRoute } from "../../../common/decorators/admin.decorator";
|
|
import { PermissionsDec } from "../../../common/decorators/permission.decorator";
|
|
import { PermissionEnum } from "../../users/enums/permission.enum";
|
|
import { UserDec } from "../../../common/decorators/user.decorator";
|
|
import { AuthGuards } from "../../../common/decorators/auth-guard.decorator";
|
|
import { ParamDto } from "../../../common/DTO/param.dto";
|
|
import { ITokenPayload } from "../../auth/interfaces/IToken-payload";
|
|
|
|
@AuthGuards()
|
|
@AdminRoute()
|
|
@ApiTags("Task Manager - Projects")
|
|
@Controller("task-manager/projects")
|
|
export class ProjectController {
|
|
constructor(private readonly projectService: ProjectService) {}
|
|
|
|
@Post()
|
|
@PermissionsDec(PermissionEnum.PROJECT)
|
|
@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")
|
|
@PermissionsDec(PermissionEnum.PROJECT)
|
|
@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")
|
|
@PermissionsDec(PermissionEnum.PROJECT)
|
|
@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);
|
|
}
|
|
|
|
@Get("user/workspace/:id")
|
|
@ApiOperation({ summary: "Get user projects in a specific workspace!" })
|
|
@ApiResponse({ status: 200, description: "Got user projects successfully!" })
|
|
@ApiResponse({ status: 400, description: "Bad Request!" })
|
|
findUserProjectsByWorkspace(
|
|
@UserDec() user: ITokenPayload,
|
|
@Param() paramDto: ParamDto,
|
|
@Query() pagination: PaginationDto,
|
|
): Promise<{ projects: TMProject[]; count: number; paginate: true }> {
|
|
return this.projectService.findUserProjectsByWorkspace(user.id, user.permissions, paramDto.id, pagination);
|
|
}
|
|
|
|
@Get("project/:id")
|
|
@ApiOperation({ summary: "Get project detail" })
|
|
@ApiResponse({ status: 200, description: "Got Project Detail Successfully!" })
|
|
@ApiResponse({ status: 400, description: "Bad request!" })
|
|
@ApiResponse({ status: 404, description: "The project was not found!" })
|
|
getProjectDetail(@Param() paramDto: ParamDto, @UserDec() user: ITokenPayload): Promise<TMProject | null> {
|
|
return this.projectService.getProjectDetail(paramDto.id, user.id, user.permissions);
|
|
}
|
|
}
|