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