| 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 | Controller, |
||
| 4 | Inject, |
||
| 5 | BadRequestException, |
||
| 6 | UseGuards, |
||
| 7 | Put, |
||
| 8 | Param |
||
| 9 | } from '@nestjs/common'; |
||
| 10 | import {AuthGuard} from '@nestjs/passport'; |
||
| 11 | import {ApiTags, ApiBearerAuth, ApiOperation} from '@nestjs/swagger'; |
||
| 12 | import {ICommandBus} from 'src/Application/ICommandBus'; |
||
| 13 | import {UpdateTaskCommand} from 'src/Application/Task/Command/UpdateTaskCommand'; |
||
| 14 | import {TaskDTO} from '../DTO/TaskDTO'; |
||
| 15 | import {IdDTO} from 'src/Infrastructure/Common/DTO/IdDTO'; |
||
| 16 | import {Roles} from 'src/Infrastructure/HumanResource/User/Decorator/Roles'; |
||
| 17 | import {UserRole} from 'src/Domain/HumanResource/User/User.entity'; |
||
| 18 | import {RolesGuard} from 'src/Infrastructure/HumanResource/User/Security/RolesGuard'; |
||
| 19 | |||
| 20 | @Controller('tasks') |
||
| 21 | @ApiTags('Task') |
||
| 22 | @ApiBearerAuth() |
||
| 23 | @UseGuards(AuthGuard('bearer'), RolesGuard) |
||
| 24 | export class UpdateTaskAction { |
||
| 25 | constructor( |
||
| 26 | @Inject('ICommandBus') |
||
| 27 | private readonly commandBus: ICommandBus |
||
| 28 | ) {} |
||
| 29 | |||
| 30 | @Put(':id') |
||
| 31 | @Roles(UserRole.COOPERATOR, UserRole.EMPLOYEE) |
||
| 32 | @ApiOperation({summary: 'Update task'}) |
||
| 33 | public async index(@Param() dto: IdDTO, @Body() taskDto: TaskDTO) { |
||
| 34 | try { |
||
| 35 | const {id} = dto; |
||
| 36 | await this.commandBus.execute(new UpdateTaskCommand(id, taskDto.name)); |
||
| 37 | |||
| 38 | return {id}; |
||
| 39 | } catch (e) { |
||
| 40 | throw new BadRequestException(e.message); |
||
| 41 | } |
||
| 42 | } |
||
| 43 | } |
||
| 44 |