| Total Complexity | 2 |
| Complexity/F | 1 |
| Lines of Code | 33 |
| Function Count | 2 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | import {InjectRepository} from '@nestjs/typeorm'; |
||
| 2 | import {Repository} from 'typeorm'; |
||
| 3 | import {IPayStubRepository} from 'src/Domain/HumanResource/Repository/IPayStubRepository'; |
||
| 4 | import {PayStub} from 'src/Domain/HumanResource/PayStub.entity'; |
||
| 5 | import {User} from 'src/Domain/User/User.entity'; |
||
| 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(); |
||
| 31 | } |
||
| 32 | } |
||
| 33 |