Passed
Push — master ( fa5b81...8559eb )
by Mathieu
01:32
created

api/src/Infrastructure/Order/Action/ShippingCost/RemoveShippingCostAction.ts   A

Complexity

Total Complexity 2
Complexity/F 2

Size

Lines of Code 39
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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

1 Function

Rating   Name   Duplication   Size   Complexity  
A RemoveShippingCostAction.index 0 9 2
1
import {
2
  Controller,
3
  Inject,
4
  BadRequestException,
5
  UseGuards,
6
  Param,
7
  Delete
8
} from '@nestjs/common';
9
import { AuthGuard } from '@nestjs/passport';
10
import { ApiTags, ApiOperation, ApiBearerAuth } from '@nestjs/swagger';
11
import { ICommandBus } from 'src/Application/ICommandBus';
12
import { RemoveShippingCostCommand } from 'src/Application/Order/Command/ShippingCost/RemoveShippingCostCommand';
13
import { UserRole } from 'src/Domain/User/User.entity';
14
import { IdDTO } from 'src/Infrastructure/Common/DTO/IdDTO';
15
import { Roles } from 'src/Infrastructure/User/Decorator/Roles';
16
import { RolesGuard } from 'src/Infrastructure/User/Security/RolesGuard';
17
18
@Controller('shipping-costs')
19
@ApiTags('Order')
20
@ApiBearerAuth()
21
@UseGuards(AuthGuard('bearer'), RolesGuard)
22
export class RemoveShippingCostAction {
23
  constructor(
24
    @Inject('ICommandBus')
25
    private readonly commandBus: ICommandBus
26
  ) {}
27
28
  @Delete(':id')
29
  @Roles(UserRole.PHOTOGRAPHER)
30
  @ApiOperation({ summary: 'Remove shipping cost' })
31
  public async index(@Param() { id }: IdDTO) {
32
    try {
33
      await this.commandBus.execute(new RemoveShippingCostCommand(id));
34
    } catch (e) {
35
      throw new BadRequestException(e.message);
36
    }
37
  }
38
}
39