Completed
Push — master ( e65836...fa4d5c )
by Mathieu
12s queued 10s
created

server/src/Infrastructure/Project/Action/UpdateProjectAction.ts   A

Complexity

Total Complexity 2
Complexity/F 2

Size

Lines of Code 47
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 42
dl 0
loc 47
rs 10
c 0
b 0
f 0
wmc 2
mnd 1
bc 1
fnc 1
bpm 1
cpm 2
noi 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A UpdateProjectAction.index 0 15 2
1
import {
2
  Body,
3
  Controller,
4
  Inject,
5
  BadRequestException,
6
  UseGuards,
7
  Put,
8
  Param
9
} from '@nestjs/common';
10
import { AuthGuard } from '@nestjs/passport';
11
import { ApiTags, ApiBearerAuth, ApiOperation } from '@nestjs/swagger';
12
import { ICommandBus } from 'src/Application/ICommandBus';
13
import { UpdateProjectCommand } from 'src/Application/Project/Command/UpdateProjectCommand';
14
import { ProjectDTO } from '../DTO/ProjectDTO';
15
import { IdDTO } from 'src/Infrastructure/Common/DTO/IdDTO';
16
import { UserRole } from 'src/Domain/HumanResource/User/User.entity';
17
import { Roles } from 'src/Infrastructure/HumanResource/User/Decorator/Roles';
18
import { RolesGuard } from 'src/Infrastructure/HumanResource/User/Security/RolesGuard';
19
20
@Controller('projects')
21
@ApiTags('Project')
22
@ApiBearerAuth()
23
@UseGuards(AuthGuard('bearer'), RolesGuard)
24
export class UpdateProjectAction {
25
  constructor(
26
    @Inject('ICommandBus')
27
    private readonly commandBus: ICommandBus
28
  ) {}
29
30
  @Put(':id')
31
  @Roles(UserRole.COOPERATOR, UserRole.EMPLOYEE)
32
  @ApiOperation({summary: 'Update project'})
33
  public async index(@Param() { id }: IdDTO, @Body() projectDto: ProjectDTO) {
34
    try {
35
      const {name, dayDuration, customerId, invoiceUnit} = projectDto;
36
37
      await this.commandBus.execute(
38
        new UpdateProjectCommand(id, name, dayDuration, invoiceUnit, customerId)
39
      );
40
41
      return {id};
42
    } catch (e) {
43
      throw new BadRequestException(e.message);
44
    }
45
  }
46
}
47