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

server/src/Infrastructure/HumanResource/User/Security/CalendarSecretGuard.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
bpm 1
cpm 2
noi 0
c 0
b 0
f 0
rs 10

1 Function

Rating   Name   Duplication   Size   Complexity  
A CalendarSecretGuard.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 CalendarSecretGuard implements CanActivate {
7
  constructor(private configService: ConfigService) {}
8
9
  public canActivate(context: ExecutionContext): boolean {
10
    const configuredCalendarSecret = this.configService.get<string>(
11
      'CALENDAR_SECRET'
12
    );
13
14
    if (!configuredCalendarSecret) {
15
      return false;
16
    }
17
18
    const request: Request = context.switchToHttp().getRequest();
19
    const { calendar_secret } = request.query;
20
21
    return configuredCalendarSecret === calendar_secret;
22
  }
23
}
24