Total Complexity | 2 |
Total Lines | 24 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | import {InjectRepository} from '@nestjs/typeorm'; |
||
6 | |||
7 | export class PayStubRepository implements IPayStubRepository { |
||
8 | constructor( |
||
9 | @InjectRepository(PayStub) |
||
10 | private readonly repository: Repository<PayStub> |
||
11 | ) {} |
||
12 | |||
13 | public save(payStub: PayStub): Promise<PayStub> { |
||
14 | return this.repository.save(payStub); |
||
15 | } |
||
16 | |||
17 | public findOneByUserAndDate( |
||
18 | user: User, |
||
19 | date: Date |
||
20 | ): Promise<PayStub | undefined> { |
||
21 | const month = new Date(date).getMonth() + 1; |
||
22 | const year = new Date(date).getFullYear(); |
||
23 | |||
24 | return this.repository |
||
25 | .createQueryBuilder('payStub') |
||
26 | .select(['payStub.id']) |
||
27 | .where('payStub.user = :userId', {userId: user.getId()}) |
||
28 | .andWhere('extract(month FROM payStub.date) = :month', {month}) |
||
29 | .andWhere('extract(year FROM payStub.date) = :year', {year}) |
||
30 | .getOne(); |
||
33 |