Passed
Pull Request — master (#436)
by
unknown
02:07
created

src/Infrastructure/Notification/Repository/NotificationRepository.ts   A

Complexity

Total Complexity 2
Complexity/F 1

Size

Lines of Code 37
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 29
mnd 0
bc 0
fnc 2
dl 0
loc 37
rs 10
bpm 0
cpm 1
noi 0
c 0
b 0
f 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
A NotificationRepository.save 0 3 1
A NotificationRepository.findByLeaveRequestIdAndType 0 15 1
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