Passed
Pull Request — master (#70)
by Mathieu
01:22
created

QuoteRepository.countByYear   A

Complexity

Conditions 1

Size

Total Lines 6
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
1
import {InjectRepository} from '@nestjs/typeorm';
2
import {Repository} from 'typeorm';
3
import {IQuoteRepository} from 'src/Domain/Billing/Repository/IQuoteRepository';
4
import {Quote} from 'src/Domain/Billing/Quote.entity';
5
6
export class QuoteRepository implements IQuoteRepository {
7
  constructor(
8
    @InjectRepository(Quote)
9
    private readonly repository: Repository<Quote>
10
  ) {}
11
12
  public save(quote: Quote): Promise<Quote> {
13
    return this.repository.save(quote);
14
  }
15
16
  public countByYear(year: number): Promise<number> {
17
    return this.repository
18
      .createQueryBuilder('quote')
19
      .select('quote.id')
20
      .where('extract(year FROM quote.date) = :year', {year})
21
      .getCount();
22
  }
23
24
  public find(id: string): Promise<Quote> {
25
    return this.repository
26
      .createQueryBuilder('quote')
27
      .select('quote.id')
28
      .where('quote.id = :id', {id})
29
      .getOne();
30
  }
31
}
32