src/models/Notification.js
/**
* Model representing a notification.
*/
class NotificationModel {
/**
* @param {Object} response - JSON formatted response of a Notification
* @param {String} response.id - The id value of the notification
* @param {String} response.type - The type of user (mobile or user) associated with the notification
* @param {String} response.action - The action that occurs when the notification transpires
* @param {Object} response.actionObject - Object with possible actions for notification
* @param {Object} [response.channels] - Array of channels associated with notification
* @param {String} response.message - The notification message
* @param {String} response.status - The notification status ('pending', 'completed', 'read')
* @param {String} response.title - The notification title
* @param {Object} response.opts - Object for interpolating message string
* @param {String} response.createdAt - The creation date of the notification
* @param {String} response.updatedAt - Last time the notification was updated
*/
constructor(response = {}) {
const _response = response.data || response; // if json api is passed in directly
const attributes = _response.attributes || _response; // if json api is passed in directly
if (_response.id) {
/** @type {Number} */
this.id = parseInt(_response.id, 10);
}
/** @type {String} */
this.action = attributes.action;
/** @type {Object} */
this.actionObject = attributes.action_object;
/** @type {String} */
this.channels = attributes.channels;
/** @type {String} */
this.message = attributes.message;
/** @type {String} */
this.status = attributes.status;
/** @type {String} */
this.title = attributes.title;
/** @type {Object} */
this.opts = attributes.opts;
/** @type {String} */
this.createdAt = attributes.created_at;
/** @type {String} */
this.updatedAt = attributes.updated_at;
/** @type {String} */
this.archivedAt = attributes.archived_at;
}
}
export default NotificationModel;