aboutsummaryrefslogtreecommitdiffstats
path: root/src/models/News.ts
blob: d1ae6fcef5fed3e95c0b6475c20ccb6ebff9e7b2 (plain) (blame)
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
// @flow

import { ifUndefinedString, ifUndefinedBoolean } from '../jsUtils';

interface INews {
  id: string;
  message: string;
  type: string;
  sticky: boolean | undefined;
}

export default class News {
  id: string = '';

  message: string = '';

  type: string = 'primary';

  sticky: boolean = false;

  constructor(data: INews) {
    if (!data.id) {
      throw Error('News requires Id');
    }

    this.id = data.id;
    this.message = ifUndefinedString(data.message, this.message);
    this.type = ifUndefinedString(data.type, this.type);
    this.sticky = ifUndefinedBoolean(data.sticky, this.sticky);
  }
}