Completed
Push — master ( 605e3d...3de0bb )
by Muhammad Dyas
14s queued 13s
created

BaseHandler.getUserTimezone   B

Complexity

Conditions 8

Size

Total Lines 10
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 10
rs 7.3333
c 0
b 0
f 0
cc 8
1
import {chat_v1 as chatV1} from 'googleapis/build/src/apis/chat/v1';
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