Passed
Pull Request — master (#19)
by Muhammad Dyas
01:43
created

src/handlers/BaseHandler.ts   A

Complexity

Total Complexity 8
Complexity/F 2

Size

Lines of Code 24
Function Count 4

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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

4 Functions

Rating   Name   Duplication   Size   Complexity  
A BaseHandler.getAnnotations 0 3 4
A BaseHandler.getAnnotationByType 0 3 1
A BaseHandler.process 0 2 1
A BaseHandler.getUserTimezone 0 3 2
1
import {chat_v1 as chatV1} from 'googleapis/build/src/apis/chat/v1';
2
3
export default abstract class BaseHandler {
4
  protected event: chatV1.Schema$DeprecatedEvent;
5
6
  constructor(event: chatV1.Schema$DeprecatedEvent) {
7
    this.event = event;
8
  }
9
10
  protected getAnnotations(): chatV1.Schema$Annotation[] {
11
    return this.event.message?.annotations ?? [];
12
  }
13
14
  protected getAnnotationByType(type: string): chatV1.Schema$Annotation | undefined {
15
    return this.getAnnotations().find((annotation) => annotation.type === type);
16
  }
17
18
  protected getUserTimezone(): chatV1.Schema$TimeZone | undefined {
19
    return this.event.common?.timeZone;
20
  }
21
22
  public abstract process(): chatV1.Schema$Message | Promise<chatV1.Schema$Message>;
23
}
24