Passed
Push — master ( 1029c0...f58cd4 )
by Mathieu
01:51 queued 22s
created

api/src/Application/School/Query/Discount/GetDiscountsBySchoolQueryHandler.ts   A

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 27
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 GetDiscountsBySchoolQueryHandler.execute 0 19 2
1
import { QueryHandler } from '@nestjs/cqrs';
2
import { Inject } from '@nestjs/common';
3
import { GetDiscountsBySchoolQuery } from './GetDiscountsBySchoolQuery';
4
import { IDiscountRepository } from 'src/Domain/School/Repository/IDiscountRepository';
5
import { DiscountView } from '../../View/DiscountView';
6
7
@QueryHandler(GetDiscountsBySchoolQuery)
8
export class GetDiscountsBySchoolQueryHandler {
9
  constructor(
10
    @Inject('IDiscountRepository')
11
    private readonly discountRepository: IDiscountRepository
12
  ) {}
13
14
  public async execute({ schoolId }: GetDiscountsBySchoolQuery): Promise<DiscountView[]> {
15
    const discountViews: DiscountView[] = [];
16
    const discounts = await this.discountRepository.findBySchool(
17
      schoolId
18
    );
19
20
    for (const discount of discounts) {
21
      discountViews.push(
22
        new DiscountView(
23
          discount.getId(),
24
          discount.getType(),
25
          discount.getAmount() / 100,
26
          discount.getValue() / 100
27
        )
28
      );
29
    }
30
31
    return discountViews;
32
  }
33
}
34