All files / models Events.js

0% Statements 0/20
0% Branches 0/4
0% Functions 0/3
0% Lines 0/20
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                                                                           
import { isArrayLike, mapObj } from 'ramda';
 
export class Event {
  constructor(obj) {
    this.id = obj.sccNtfevtReqId;
    this.data = obj.data;
    this.status = obj.sccNtfevtStatus;
    this.startDate = obj.sccNtfevtStartdt;
    this.message = obj.sccNtfevtMessage;
  }
}
 
export default class Events {
  constructor(obj) {
    const evtObj = obj.sccNtfGetEventsResp;
 
    this.totalEventsCount = evtObj.totalEventsCount;
    this.readEventsCount = evtObj.readEventsCount;
    this.unreadEventsCount = evtObj.unreadEventsCount;
 
    this.events = {};
    let length = 0;
 
    const items = evtObj.sccNtfEvent;
    if (isArrayLike(items)) {
      this.events = mapObj((evt) => {
        ++length;
        return new Event(evt);
      }, items);
    } else if (typeof items === 'object') {
      ++length;
      this.events['0'] = new Event(items);
    }
 
    this.events.length = length;
  }
}