All files / src/domains/projects/controllers project.controller.ts

0% Statements 0/32
0% Branches 0/54
0% Functions 0/8
0% Lines 0/30

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89                                                                                                                                                                                 
import {
  Controller,
  Get,
  Post,
  Put,
  Param,
  Body,
  UseGuards,
  Req,
} from '@nestjs/common';
import { ProjectService } from '../services/project.service';
import { ProjectMemberService } from '../services/project-member.service';
import { ProjectConfigurationService } from '../services/project-configuration.service';
import { ApiTags, ApiOperation, ApiResponse } from '@nestjs/swagger';
 
@Controller('api/v1/projects')
@ApiTags('Project')
export class ProjectController {
  constructor(
    private readonly projectService: ProjectService,
    private readonly memberService: ProjectMemberService,
    private readonly configService: ProjectConfigurationService,
  ) {}
 
  @Get('config')
  @ApiOperation({ summary: 'Get config operation' })
  @ApiResponse({ status: 200, description: 'Operation successful' })
  async getConfig(@Req() req: any): Promise<any> {
    const tenantId = req.user?.tenantId || 'dummy-tenant-id';
    return this.configService.getConfig(tenantId);
  }
 
  @Post()
  @ApiOperation({ summary: 'Create operation' })
  @ApiResponse({ status: 201, description: 'Operation successful' })
  async create(@Req() req: any, @Body() data: any): Promise<any> {
    const tenantId = req.user?.tenantId || 'dummy-tenant-id';
    return this.projectService.create(tenantId, data);
  }
 
  @Get()
  @ApiOperation({ summary: 'Find all operation' })
  @ApiResponse({ status: 200, description: 'Operation successful' })
  async findAll(@Req() req: any): Promise<any> {
    const tenantId = req.user?.tenantId || 'dummy-tenant-id';
    return this.projectService.findAll(tenantId);
  }
 
  @Get(':id')
  @ApiOperation({ summary: 'Find one operation' })
  @ApiResponse({ status: 200, description: 'Operation successful' })
  async findOne(@Req() req: any, @Param('id') id: string): Promise<any> {
    const tenantId = req.user?.tenantId || 'dummy-tenant-id';
    return this.projectService.findOne(tenantId, id);
  }
 
  @Put(':id/status')
  @ApiOperation({ summary: 'Update status operation' })
  @ApiResponse({ status: 200, description: 'Operation successful' })
  async updateStatus(
    @Req() req: any,
    @Param('id') id: string,
    @Body('status') status: string,
  ): Promise<any> {
    const tenantId = req.user?.tenantId || 'dummy-tenant-id';
    return this.projectService.transitionStatus(tenantId, id, status);
  }
 
  @Post(':id/members')
  @ApiOperation({ summary: 'Add member operation' })
  @ApiResponse({ status: 201, description: 'Operation successful' })
  async addMember(
    @Req() req: any,
    @Param('id') id: string,
    @Body() data: any,
  ): Promise<any> {
    const tenantId = req.user?.tenantId || 'dummy-tenant-id';
    return this.memberService.addMember(tenantId, { ...data, projectId: id });
  }
 
  @Get(':id/members')
  @ApiOperation({ summary: 'Get members operation' })
  @ApiResponse({ status: 200, description: 'Operation successful' })
  async getMembers(@Req() req: any, @Param('id') id: string): Promise<any> {
    const tenantId = req.user?.tenantId || 'dummy-tenant-id';
    return this.memberService.findByProject(tenantId, id);
  }
}