Passed
Push — master ( 2cdb9e...45e047 )
by Mathieu
01:31
created

api/src/Infrastructure/School/Action/Shooting/GetShootingAction.ts   A

Complexity

Total Complexity 2
Complexity/F 2

Size

Lines of Code 40
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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

1 Function

Rating   Name   Duplication   Size   Complexity  
A GetShootingAction.index 0 9 2
1
import {
2
  Controller,
3
  Inject,
4
  UseGuards,
5
  Param,
6
  Get,
7
  NotFoundException
8
} from '@nestjs/common';
9
import { AuthGuard } from '@nestjs/passport';
10
import { ApiTags, ApiBearerAuth, ApiOperation } from '@nestjs/swagger';
11
import { IQueryBus } from 'src/Application/IQueryBus';
12
import { GetShootingByIdQuery } from 'src/Application/School/Query/Shooting/GetSchootingByIdQuery';
13
import { ShootingView } from 'src/Application/School/View/ShootingView';
14
import { UserRole } from 'src/Domain/User/User.entity';
15
import { IdDTO } from 'src/Infrastructure/Common/DTO/IdDTO';
16
import { Roles } from 'src/Infrastructure/User/Decorator/Roles';
17
import { RolesGuard } from 'src/Infrastructure/User/Security/RolesGuard';
18
19
@Controller('schools/:schoolId/shootings')
20
@ApiTags('School shooting')
21
@ApiBearerAuth()
22
@UseGuards(AuthGuard('bearer'), RolesGuard)
23
export class GetShootingAction {
24
  constructor(
25
    @Inject('IQueryBus')
26
    private readonly queryBus: IQueryBus
27
  ) {}
28
29
  @Get(':id')
30
  @Roles(UserRole.PHOTOGRAPHER)
31
  @ApiOperation({ summary: 'Get shooting' })
32
  public async index(@Param() { id }: IdDTO): Promise<ShootingView> {
33
    try {
34
      return await this.queryBus.execute(new GetShootingByIdQuery(id));
35
    } catch (e) {
36
      throw new NotFoundException(e.message);
37
    }
38
  }
39
}
40