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

server/src/Infrastructure/FairCalendar/Action/GetEventAction.ts   A

Complexity

Total Complexity 2
Complexity/F 2

Size

Lines of Code 36
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 32
mnd 1
bc 1
fnc 1
dl 0
loc 36
bpm 1
cpm 2
noi 0
c 0
b 0
f 0
rs 10

1 Function

Rating   Name   Duplication   Size   Complexity  
A GetEventAction.index 0 8 2
1
import {
2
  Controller,
3
  Inject,
4
  BadRequestException,
5
  UseGuards,
6
  Param,
7
  Get
8
} from '@nestjs/common';
9
import {AuthGuard} from '@nestjs/passport';
10
import {ApiUseTags, ApiBearerAuth, ApiOperation} from '@nestjs/swagger';
11
import {IQueryBus} from 'src/Application/IQueryBus';
12
import {EventIdDTO} from './DTO/EventIdDTO';
13
import {GetEventByIdQuery} from 'src/Application/FairCalendar/Query/GetEventByIdQuery';
14
import {EventView} from 'src/Application/FairCalendar/View/EventView';
15
16
@Controller('events')
17
@ApiUseTags('Event')
18
@ApiBearerAuth()
19
@UseGuards(AuthGuard('bearer'))
20
export class GetEventAction {
21
  constructor(
22
    @Inject('IQueryBus')
23
    private readonly queryBus: IQueryBus
24
  ) {}
25
26
  @Get(':id')
27
  @ApiOperation({title: 'Get event'})
28
  public async index(@Param() dto: EventIdDTO): Promise<EventView> {
29
    try {
30
      return await this.queryBus.execute(new GetEventByIdQuery(dto.id));
31
    } catch (e) {
32
      throw new BadRequestException(e.message);
33
    }
34
  }
35
}
36