| Total Complexity | 2 |
| Complexity/F | 2 |
| Lines of Code | 50 |
| 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 {LoggedUser} from 'src/Infrastructure/User/Decorator/LoggedUser'; |
||
| 13 | import {User} from 'src/Domain/User/User.entity'; |
||
| 14 | import {AddEventCommand} from 'src/Application/FairCalendar/Command/AddEventCommand'; |
||
| 15 | import {EventDTO} from './DTO/EventDTO'; |
||
| 16 | |||
| 17 | @Controller('events') |
||
| 18 | @ApiUseTags('Event') |
||
| 19 | @ApiBearerAuth() |
||
| 20 | @UseGuards(AuthGuard('bearer')) |
||
| 21 | export class AddEventAction { |
||
| 22 | constructor( |
||
| 23 | @Inject('ICommandBus') |
||
| 24 | private readonly commandBus: ICommandBus |
||
| 25 | ) {} |
||
| 26 | |||
| 27 | @Post() |
||
| 28 | @ApiOperation({title: 'Add new event'}) |
||
| 29 | public async index(@Body() dto: EventDTO, @LoggedUser() user: User) { |
||
| 30 | try { |
||
| 31 | const {type, date, projectId, taskId, summary, time} = dto; |
||
| 32 | const id = await this.commandBus.execute( |
||
| 33 | new AddEventCommand( |
||
| 34 | type, |
||
| 35 | user, |
||
| 36 | Number(time), |
||
| 37 | new Date(date), |
||
| 38 | projectId, |
||
| 39 | taskId, |
||
| 40 | summary |
||
| 41 | ) |
||
| 42 | ); |
||
| 43 | |||
| 44 | return {id}; |
||
| 45 | } catch (e) { |
||
| 46 | throw new BadRequestException(e.message); |
||
| 47 | } |
||
| 48 | } |
||
| 49 | } |
||
| 50 |