Passed
Pull Request — master (#20)
by Muhammad Dyas
01:34
created

src/handlers/BaseHandler.ts   A

Complexity

Total Complexity 12
Complexity/F 3

Size

Lines of Code 32
Function Count 4

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 12
eloc 25
mnd 8
bc 8
fnc 4
dl 0
loc 32
rs 10
bpm 2
cpm 3
noi 0
c 0
b 0
f 0

4 Functions

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