Passed
Pull Request — master (#78)
by Mathieu
01:25
created

server/src/Infrastructure/Billing/Action/UpdateDailyRateAction.ts   A

Complexity

Total Complexity 2
Complexity/F 2

Size

Lines of Code 43
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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

1 Function

Rating   Name   Duplication   Size   Complexity  
A UpdateDailyRateAction.index 0 14 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 {ApiUseTags, ApiBearerAuth, ApiOperation} from '@nestjs/swagger';
12
import {ICommandBus} from 'src/Application/ICommandBus';
13
import {DailyRateDTO} from './DTO/DailyRateDTO';
14
import {IdDTO} from 'src/Infrastructure/Common/DTO/IdDTO';
15
import {UpdateDailyRateCommand} from 'src/Application/Billing/Command/DailyRate/UpdateDailyRateCommand';
16
17
@Controller('daily_rates')
18
@ApiUseTags('Billing')
19
@ApiBearerAuth()
20
@UseGuards(AuthGuard('bearer'))
21
export class UpdateDailyRateAction {
22
  constructor(
23
    @Inject('ICommandBus')
24
    private readonly commandBus: ICommandBus
25
  ) {}
26
27
  @Put(':id')
28
  @ApiOperation({title: 'Update daily rate'})
29
  public async index(@Param() idDto: IdDTO, @Body() dto: DailyRateDTO) {
30
    try {
31
      const {userId, customerId, taskId, amount} = dto;
32
33
      const id = await this.commandBus.execute(
34
        new UpdateDailyRateCommand(idDto.id, amount, userId, customerId, taskId)
35
      );
36
37
      return {id};
38
    } catch (e) {
39
      throw new BadRequestException(e.message);
40
    }
41
  }
42
}
43