src/handlers/BaseHandler.ts   A
last analyzed

Complexity

Total Complexity 14
Complexity/F 3.5

Size

Lines of Code 33
Function Count 4

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 14
eloc 26
mnd 10
bc 10
fnc 4
dl 0
loc 33
rs 10
bpm 2.5
cpm 3.5
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
A BaseHandler.getAnnotationByType 0 3 1
B BaseHandler.getUserTimezone 0 10 8
1
import {chat_v1 as chatV1} from '@googleapis/chat';
2
import {LocaleTimezone} from '../helpers/interfaces';
3
import {DEFAULT_LOCALE_TIMEZONE} from '../helpers/time';
4
5
export default abstract class BaseHandler {
6
  protected event: chatV1.Schema$DeprecatedEvent;
7
8
  constructor(event: chatV1.Schema$DeprecatedEvent) {
9
    this.event = event;
10
  }
11
12
  protected getAnnotations(): chatV1.Schema$Annotation[] {
13
    return this.event.message?.annotations ?? [];
14
  }
15
16
  protected getAnnotationByType(type: string): chatV1.Schema$Annotation | undefined {
17
    return this.getAnnotations().find((annotation) => annotation.type === type);
18
  }
19
20
  protected getUserTimezone(): LocaleTimezone {
21
    if (this.event.common?.timeZone?.id) {
22
      const locale = this.event.common.userLocale ?? 'en';
23
      const id = this.event.common.timeZone.id;
24
      const offset = this.event.common.timeZone.offset ?? 0;
25
      return {locale, id, offset};
26
    }
27
28
    return DEFAULT_LOCALE_TIMEZONE;
29
  }
30
31
  public abstract process(): chatV1.Schema$Message | Promise<chatV1.Schema$Message>;
32
}
33