Passed
Pull Request — master (#75)
by Mathieu
01:18
created

server/src/Domain/FairCalendar/Specification/IsMaximumTimeSpentReached.ts   A

Complexity

Total Complexity 1
Complexity/F 1

Size

Lines of Code 22
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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

1 Function

Rating   Name   Duplication   Size   Complexity  
A IsMaximumTimeSpentReached.isSatisfiedBy 0 8 1
1
import {Injectable, Inject} from '@nestjs/common';
2
import {ISpecification} from 'src/Domain/ISpecification';
3
import {IEventRepository} from '../Repository/IEventRepository';
4
import {Event} from '../Event.entity';
5
6
@Injectable()
7
export class IsMaximumTimeSpentReached implements ISpecification {
8
  constructor(
9
    @Inject('IEventRepository')
10
    private readonly eventRepository: IEventRepository
11
  ) {}
12
13
  public async isSatisfiedBy(event: Event): Promise<boolean> {
14
    const timeSpent = await this.eventRepository.getDayTimeSpentByUser(
15
      event.getUser(),
16
      event.getDate()
17
    );
18
19
    return timeSpent + event.getTime() > Event.MAXIMUM_TIMESPENT_PER_DAY;
20
  }
21
}
22