api/src/Infrastructure/School/Action/GetSchoolAction.ts   A
last analyzed

Complexity

Total Complexity 2
Complexity/F 2

Size

Lines of Code 45
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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

1 Function

Rating   Name   Duplication   Size   Complexity  
A GetSchoolAction.index 0 12 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 { GetSchoolByIdQuery } from 'src/Application/School/Query/GetSchoolByIdQuery';
13
import { SchoolView } from 'src/Application/School/View/SchoolView';
14
import { UserRole } from 'src/Domain/User/User.entity';
15
import { IdDTO } from 'src/Infrastructure/Common/DTO/IdDTO';
16
import { LoggedUser } from 'src/Infrastructure/User/Decorator/LoggedUser';
17
import { Roles } from 'src/Infrastructure/User/Decorator/Roles';
18
import { RolesGuard } from 'src/Infrastructure/User/Security/RolesGuard';
19
import { UserAuthView } from 'src/Infrastructure/User/Security/UserAuthView';
20
21
@Controller('schools')
22
@ApiTags('School')
23
@ApiBearerAuth()
24
@UseGuards(AuthGuard('bearer'), RolesGuard)
25
export class GetSchoolAction {
26
  constructor(
27
    @Inject('IQueryBus')
28
    private readonly queryBus: IQueryBus
29
  ) {}
30
31
  @Get(':id')
32
  @Roles(UserRole.PHOTOGRAPHER, UserRole.DIRECTOR)
33
  @ApiOperation({ summary: 'Get school' })
34
  public async index(
35
    @Param() dto: IdDTO,
36
    @LoggedUser() { id }: UserAuthView
37
  ): Promise<SchoolView> {
38
    try {
39
      return await this.queryBus.execute(new GetSchoolByIdQuery(dto.id, id));
40
    } catch (e) {
41
      throw new NotFoundException(e.message);
42
    }
43
  }
44
}
45