Total Complexity | 2 |
Complexity/F | 2 |
Lines of Code | 39 |
Function Count | 1 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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 |