Passed
Pull Request — master (#436)
by
unknown
02:10
created

src/Infrastructure/Adapter/MattermostNotifier.ts   A

Complexity

Total Complexity 4
Complexity/F 1.33

Size

Lines of Code 70
Function Count 3

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 39
mnd 1
bc 1
fnc 3
dl 0
loc 70
rs 10
bpm 0.3333
cpm 1.3333
noi 0
c 0
b 0
f 0

3 Functions

Rating   Name   Duplication   Size   Complexity  
A MattermostNotifier.createReaction 0 5 1
A MattermostNotifier.createPost 0 21 2
A MattermostNotifier.createComment 0 7 1
1
import { HttpService } from '@nestjs/axios';
2
import { Injectable } from '@nestjs/common';
3
import { ConfigService } from '@nestjs/config';
4
import { IMattermostNotifier } from 'src/Application/IMattermostNotifier';
5
6
@Injectable()
7
export class MattermostNotifier implements IMattermostNotifier {
8
  constructor(
9
    private readonly configService: ConfigService,
10
    private readonly httpService: HttpService
11
  ) {}
12
13
  public async createPost(channelId: string, message: string): Promise<object> {
14
    try {
15
      const response = await this.httpService.axiosRef.post(
16
        `${this.configService.get<string>('MATTERMOST_API_URL')}/posts`,
17
        {
18
          channel_id: channelId,
19
          message
20
        },
21
        {
22
          headers: {
23
            Authorization: `Bearer ${this.configService.get<string>(
24
              'MATTERMOST_ALFRED_TOKEN'
25
            )}`
26
          }
27
        }
28
      );
29
30
      return response.data;
31
    } catch (e) {
32
      console.log('ERROR: ', e);
33
    }
34
  }
35
36
  public async createComment(
37
    channelId: string,
38
    message: string,
39
    rootId: string
40
  ): Promise<object> {
41
    return {};
42
  }
43
44
  public async createReaction(
45
    postId: string,
46
    emojiName: string
47
  ): Promise<object> {
48
  //   try {
49
  //     const response = await this.httpService.axiosRef.post(
50
  //       `${this.configService.get<string>('MATTERMOST_API_URL')}/reactions`,
51
  //       {
52
  //         channel_id: channelId,
53
  //         message
54
  //       },
55
  //       {
56
  //         headers: {
57
  //           Authorization: `Bearer ${this.configService.get<string>(
58
  //             'MATTERMOST_ALFRED_TOKEN'
59
  //           )}`
60
  //         }
61
  //       }
62
  //     );
63
64
  //     return response.data;
65
  //   } catch (e) {
66
  //     console.log('ERROR: ', e);
67
  //   }
68
  // }
69
}
70