All files / src/dao TextDAO.ts

26.32% Statements 5/19
100% Branches 0/0
0% Functions 0/9
27.78% Lines 5/18

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 541x   1x   1x   1x   1x                                                                                          
import { TwitarrHTTPOptions } from '../api/TwitarrHTTPOptions';
 
import { Announcement } from '../model/Announcement';
 
import { Util } from '../internal/Util';
 
import { AbstractDAO } from './AbstractDAO';
 
export class TextDAO extends AbstractDAO {
  public async getFile(filename: string) {
    const options = new TwitarrHTTPOptions().withParameter('app', 'plain');
 
    return this.http
      .get('/api/v2/text/' + filename, options)
      .then(result => this.handleErrors(result))
      .then(data => {
        return data[filename];
      });
  }
 
  public async serverTime() {
    return this.http
      .get('/api/v2/time')
      .then(result => this.handleErrors(result))
      .then(data => {
        return {
          time: Util.toMoment(data.epoch),
          display: data.time,
          offset: data.offset as number,
        };
      });
  }
 
  public async reactions() {
    return this.http
      .get('/api/v2/reactions')
      .then(result => this.handleErrors(result))
      .then(data => {
        return data.reactions as string[];
      });
  }
 
  public async announcements() {
    return this.http
      .get('/api/v2/announcements', new TwitarrHTTPOptions().withParameter('app', 'plain'))
      .then(result => this.handleErrors(result))
      .then(data => {
        if (data.announcements) {
          return data.announcements.map(announcement => Announcement.fromRest(announcement));
        }
      });
  }
}