| Total Complexity | 2 |
| Complexity/F | 2 |
| Lines of Code | 44 |
| Function Count | 1 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | import { |
||
| 2 | Body, |
||
| 3 | Post, |
||
| 4 | Controller, |
||
| 5 | Inject, |
||
| 6 | BadRequestException, |
||
| 7 | UseGuards |
||
| 8 | } from '@nestjs/common'; |
||
| 9 | import {AuthGuard} from '@nestjs/passport'; |
||
| 10 | import {ApiUseTags, ApiBearerAuth, ApiOperation} from '@nestjs/swagger'; |
||
| 11 | import {ICommandBus} from 'src/Application/ICommandBus'; |
||
| 12 | import {CreateDailyRateCommand} from 'src/Application/Accounting/Command/DailyRate/CreateDailyRateCommand'; |
||
| 13 | import {DailyRateDTO} from '../../DTO/DailyRateDTO'; |
||
| 14 | import {Roles} from 'src/Infrastructure/User/Decorator/Roles'; |
||
| 15 | import {RolesGuard} from 'src/Infrastructure/User/Security/RolesGuard'; |
||
| 16 | import {UserRole} from 'src/Domain/User/User.entity'; |
||
| 17 | |||
| 18 | @Controller('daily_rates') |
||
| 19 | @ApiUseTags('Accounting') |
||
| 20 | @ApiBearerAuth() |
||
| 21 | @UseGuards(AuthGuard('bearer'), RolesGuard) |
||
| 22 | export class CreateDailyRateAction { |
||
| 23 | constructor( |
||
| 24 | @Inject('ICommandBus') |
||
| 25 | private readonly commandBus: ICommandBus |
||
| 26 | ) {} |
||
| 27 | |||
| 28 | @Post() |
||
| 29 | @Roles(UserRole.COOPERATOR, UserRole.EMPLOYEE) |
||
| 30 | @ApiOperation({title: 'Create new daily rate'}) |
||
| 31 | public async index(@Body() dto: DailyRateDTO) { |
||
| 32 | try { |
||
| 33 | const {userId, customerId, taskId, amount} = dto; |
||
| 34 | const id = await this.commandBus.execute( |
||
| 35 | new CreateDailyRateCommand(amount, userId, customerId, taskId) |
||
| 36 | ); |
||
| 37 | |||
| 38 | return {id}; |
||
| 39 | } catch (e) { |
||
| 40 | throw new BadRequestException(e.message); |
||
| 41 | } |
||
| 42 | } |
||
| 43 | } |
||
| 44 |