All files / src/model User.ts

43.75% Statements 7/16
0% Branches 0/4
25% Functions 1/4
43.75% Lines 7/16

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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 1258x               8x   173x   173x   173x                                 173x   173x                                                                                                                                                                                      
import { Util } from '../internal/Util';
 
import { Moment } from 'moment';
 
/**
 * Represents a Twit-arr user.
 * @module User
 */
export class User {
  public static fromRest(data: any) {
    Util.assertHasProperties(data, 'username');
 
    const ret = new User();
 
    Util.setProperties(
      ret,
      data,
      'username',
      'email',
      'display_name',
      'empty_password',
      'room_number',
      'real_name',
      'starred',
      'comment',
      'pronouns',
      'home_location',
      'unnoticed_alerts',
      'number_of_tweets',
      'number_of_mentions',
    );
    Util.setDateProperties(ret, data, 'last_login', 'last_photo_updated');
 
    return ret;
  }
 
  /** The unique username. */
  public username: string;
 
  /** The user's role. */
  public role: string;
 
  /** The user's e-mail address. */
  public email: string;
 
  /** The user's display name. */
  public display_name: string;
 
  /** Whether the user has an empty password. */
  public empty_password: boolean;
 
  /** The last time the user logged in. */
  public last_login: Moment;
 
  /** The last time the user's photo was updated. */
  public last_photo_updated: Moment;
 
  /** The user's room number. */
  public room_number: number;
 
  /** The user's real name. */
  public real_name: string;
 
  /** The user's preferred pronouns. */
  public pronouns: string;
 
  /** The user's home location. */
  public home_location: string;
 
  /** Whether the user has un-noticed alerts. */
  public unnoticed_alerts: boolean;
 
  /** The number of tweets the user has posted. */
  public number_of_tweets: number;
 
  /** The number of times the user has been mentioned. */
  public number_of_mentions: number;
 
  /** Whether this user is starred. */
  public starred: boolean;
 
  /** A comment about the user, if any. */
  public comment: string;
 
  public toJSON() {
    const ret = {} as any;
    Util.setProperties(
      ret,
      this,
      'username',
      'email',
      'display_name',
      'empty_password',
      'room_number',
      'real_name',
      'starred',
      'comment',
      'pronouns',
      'home_location',
      'unnoticed_alerts',
      'number_of_tweets',
      'number_of_mentions',
    );
    if (!Util.isEmpty(this.last_login)) {
      ret.last_login = this.last_login.valueOf();
    }
    if (!Util.isEmpty(this.last_photo_updated)) {
      ret.last_photo_updated = this.last_photo_updated.valueOf();
    }
    return ret;
  }
 
  public getDisplayName() {
    return Util.isEmpty(this.display_name) ? '@' + this.username : this.display_name;
  }
 
  public toString() {
    let ret = '@' + this.username;
    if (!Util.isEmpty(this.display_name) && this.display_name !== this.username) {
      ret += ' (' + this.display_name + ')';
    }
    return ret;
  }
}