All files / src/model Event.ts

58.33% Statements 7/12
100% Branches 0/0
50% Functions 1/2
58.33% Lines 7/12

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 54 55 563x               3x   4x   4x 4x 4x   4x                                                                              
import { Util } from '../internal/Util';
 
import { Moment } from 'moment';
 
/**
 * Represents a calendar event.
 * @module Event
 */
export class Event {
  public static fromRest(data: any) {
    Util.assertHasProperties(data, 'id', 'title', 'start_time');
 
    const ret = new Event();
    Util.setProperties(ret, data, 'id', 'title', 'location', 'official', 'description', 'following');
    Util.setDateProperties(ret, data, 'start_time', 'end_time');
 
    return ret;
  }
 
  /** The unique event ID. */
  public id: string;
 
  /** The event's title. */
  public title: string;
 
  /** The event's location. */
  public location: string;
 
  /** The event's starting time. */
  public start_time: Moment;
 
  /** The event's ending time. */
  public end_time: Moment;
 
  /** Whether the event is official or not. */
  public official: boolean;
 
  /** The event's extended description. */
  public description: string;
 
  /** Whether the user is following this event. */
  public following: boolean;
 
  public toJSON() {
    const ret = {} as any;
    Util.setProperties(ret, this, 'id', 'title', 'location', 'official', 'description', 'following');
    if (this.start_time) {
      ret.start_time = this.start_time.valueOf();
    }
    if (this.end_time) {
      ret.end_time = this.end_time.valueOf();
    }
    return ret;
  }
}