api/src/Infrastructure/School/Action/Discount/CountSchoolDiscountsAction.ts   A
last analyzed

Complexity

Total Complexity 2
Complexity/F 2

Size

Lines of Code 34
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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

1 Function

Rating   Name   Duplication   Size   Complexity  
A CountSchoolDiscountsAction.index 0 11 2
1
import { Controller, Inject, UseGuards, Get, Param, NotFoundException } from '@nestjs/common';
2
import { AuthGuard } from '@nestjs/passport';
3
import { ApiTags, ApiBearerAuth, ApiOperation } from '@nestjs/swagger';
4
import { IQueryBus } from 'src/Application/IQueryBus';
5
import { CountDiscountsBySchoolQuery } from 'src/Application/School/Query/Discount/CountDiscountsBySchoolQuery';
6
import { UserRole } from 'src/Domain/User/User.entity';
7
import { IdDTO } from 'src/Infrastructure/Common/DTO/IdDTO';
8
import { Roles } from 'src/Infrastructure/User/Decorator/Roles';
9
import { RolesGuard } from 'src/Infrastructure/User/Security/RolesGuard';
10
11
@Controller('schools')
12
@ApiTags('School discount')
13
@ApiBearerAuth()
14
@UseGuards(AuthGuard('bearer'), RolesGuard)
15
export class CountSchoolDiscountsAction {
16
  constructor(
17
    @Inject('IQueryBus')
18
    private readonly queryBus: IQueryBus
19
  ) {}
20
21
  @Get(':id/count-discounts')
22
  @Roles(UserRole.PHOTOGRAPHER)
23
  @ApiOperation({ summary: 'Count school discounts' })
24
  public async index(@Param() { id }: IdDTO) {
25
    try {
26
      const total = await this.queryBus.execute(new CountDiscountsBySchoolQuery(id));
27
28
      return { total };
29
    } catch (e) {
30
      throw new NotFoundException(e.message);
31
    }
32
  }
33
}
34