| Total Complexity | 2 |
| Complexity/F | 1 |
| Lines of Code | 37 |
| Function Count | 2 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | import { Injectable } from '@nestjs/common'; |
||
| 2 | import { InjectRepository } from '@nestjs/typeorm'; |
||
| 3 | import { Repository } from 'typeorm'; |
||
| 4 | import { INotificationRepository } from 'src/Domain/Notification/Repository/INotificationRepository'; |
||
| 5 | import { |
||
| 6 | Notification, |
||
| 7 | NotificationType |
||
| 8 | } from 'src/Domain/Notification/Notification.entity'; |
||
| 9 | |||
| 10 | @Injectable() |
||
| 11 | export class NotificationRepository implements INotificationRepository { |
||
| 12 | constructor( |
||
| 13 | @InjectRepository(Notification) |
||
| 14 | private readonly repository: Repository<Notification> |
||
| 15 | ) {} |
||
| 16 | |||
| 17 | public save(notification: Notification): Promise<Notification> { |
||
| 18 | return this.repository.save(notification); |
||
| 19 | } |
||
| 20 | |||
| 21 | public findByLeaveRequestIdAndType( |
||
| 22 | leaveRequestId: string, |
||
| 23 | type: NotificationType |
||
| 24 | ): Promise<Notification> { |
||
| 25 | const query = this.repository |
||
| 26 | .createQueryBuilder('notification') |
||
| 27 | .select(['notification.resourceId']) |
||
| 28 | .where( |
||
| 29 | 'notification.leaveRequestId = :leaveRequestId AND notification.type = :type', |
||
| 30 | { leaveRequestId, type } |
||
| 31 | ) |
||
| 32 | .getOne(); |
||
| 33 | |||
| 34 | return query; |
||
| 35 | } |
||
| 36 | } |
||
| 37 |