Passed
Pull Request — master (#75)
by Mathieu
01:46
created

DeleteEventAction   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 19
dl 0
loc 19
c 0
b 0
f 0
rs 10

1 Function

Rating   Name   Duplication   Size   Complexity  
A index 0 9 2
1
import {
2
  Delete,
3
  Controller,
4
  Inject,
5
  BadRequestException,
6
  UseGuards,
7
  Param,
8
  HttpCode
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 {LoggedUser} from 'src/Infrastructure/User/Decorator/LoggedUser';
14
import {User} from 'src/Domain/User/User.entity';
15
import {DeleteEventCommand} from 'src/Application/FairCalendar/Command/DeleteEventCommand';
16
import {EventIdDTO} from './DTO/EventIdDTO';
17
18
@Controller('events')
19
@ApiUseTags('Event')
20
@ApiBearerAuth()
21
@UseGuards(AuthGuard('bearer'))
22
export class DeleteEventAction {
23
  constructor(
24
    @Inject('ICommandBus')
25
    private readonly commandBus: ICommandBus
26
  ) {}
27
28
  @Delete(':id')
29
  @ApiOperation({title: 'Delete an event'})
30
  @HttpCode(204)
31
  public async index(@Param() dto: EventIdDTO, @LoggedUser() user: User) {
32
    try {
33
      await this.commandBus.execute(new DeleteEventCommand(dto.id, user));
34
    } catch (e) {
35
      throw new BadRequestException(e.message);
36
    }
37
  }
38
}
39