Passed
Pull Request — master (#325)
by
unknown
02:11
created

server/src/Infrastructure/HumanResource/User/Security/CalendarTokenGuard.ts   A

Complexity

Total Complexity 2
Complexity/F 2

Size

Lines of Code 24
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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

1 Function

Rating   Name   Duplication   Size   Complexity  
A CalendarTokenGuard.canActivate 0 14 2
1
import { Request } from 'express';
2
import { Injectable, CanActivate, ExecutionContext } from '@nestjs/common';
3
import { ConfigService } from '@nestjs/config';
4
5
@Injectable()
6
export class CalendarTokenGuard implements CanActivate {
7
  constructor(private configService: ConfigService) {}
8
9
  public canActivate(context: ExecutionContext): boolean {
10
    const configuredCalendarToken = this.configService.get<string>(
11
      'CALENDAR_TOKEN'
12
    );
13
14
    if (!configuredCalendarToken) {
15
      return false;
16
    }
17
18
    const request: Request = context.switchToHttp().getRequest();
19
    const { token } = request.query;
20
21
    return configuredCalendarToken === token;
22
  }
23
}
24