| Total Complexity | 2 |
| Complexity/F | 2 |
| Lines of Code | 57 |
| Function Count | 1 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | import { |
||
| 2 | Controller, |
||
| 3 | Inject, |
||
| 4 | BadRequestException, |
||
| 5 | UseGuards, |
||
| 6 | Param, |
||
| 7 | Put, |
||
| 8 | Body |
||
| 9 | } from '@nestjs/common'; |
||
| 10 | import {AuthGuard} from '@nestjs/passport'; |
||
| 11 | import {ApiUseTags, ApiBearerAuth, ApiOperation} from '@nestjs/swagger'; |
||
| 12 | import {EventIdDTO} from './DTO/EventIdDTO'; |
||
| 13 | import {LoggedUser} from 'src/Infrastructure/User/Decorator/LoggedUser'; |
||
| 14 | import {User} from 'src/Domain/User/User.entity'; |
||
| 15 | import {EventDTO} from './DTO/EventDTO'; |
||
| 16 | import {ICommandBus} from 'src/Application/ICommandBus'; |
||
| 17 | import {UpdateEventCommand} from 'src/Application/FairCalendar/Command/UpdateEventCommand'; |
||
| 18 | |||
| 19 | @Controller('events') |
||
| 20 | @ApiUseTags('Event') |
||
| 21 | @ApiBearerAuth() |
||
| 22 | @UseGuards(AuthGuard('bearer')) |
||
| 23 | export class UpdateEventAction { |
||
| 24 | constructor( |
||
| 25 | @Inject('ICommandBus') |
||
| 26 | private readonly commandBus: ICommandBus |
||
| 27 | ) {} |
||
| 28 | |||
| 29 | @Put(':id') |
||
| 30 | @ApiOperation({title: 'Update event'}) |
||
| 31 | public async index( |
||
| 32 | @Param() idDto: EventIdDTO, |
||
| 33 | @Body() dto: EventDTO, |
||
| 34 | @LoggedUser() user: User |
||
| 35 | ) { |
||
| 36 | const {type, time, summary, projectId, taskId} = dto; |
||
| 37 | |||
| 38 | try { |
||
| 39 | const {id} = await this.commandBus.execute( |
||
| 40 | new UpdateEventCommand( |
||
| 41 | idDto.id, |
||
| 42 | user, |
||
| 43 | type, |
||
| 44 | Number(time), |
||
| 45 | projectId, |
||
| 46 | taskId, |
||
| 47 | summary |
||
| 48 | ) |
||
| 49 | ); |
||
| 50 | |||
| 51 | return {id}; |
||
| 52 | } catch (e) { |
||
| 53 | throw new BadRequestException(e.message); |
||
| 54 | } |
||
| 55 | } |
||
| 56 | } |
||
| 57 |