src/models/gamification/Badge.js
/**
* Model representing a badge.
*/
class BadgeModel {
/**
* @param {Object} response - JSON formatted response of a single badge
* @param {!Number} response.id - The id of the badge on the server
* @param {!String} response.type - The type of this object ('badges')
* @param {!String} response.title - Title
* @param {String} response.based_on - Must be either `count` or `time`
* @param {Any} response.cache_token - Not sure what this does
* @param {String} response.created_at - Created at
* @param {String} response.description - Description
* @param {Any} response.disabled_image - Image wrapper
* @param {Any} response.disabled_image.disabled_image - Image Object when the item is not active
* @param {Boolean} response.enabled - Is this enabled
* @param {Any} response.featured - Not sure what this means
* @param {Any} response.image - Image wrapper
* @param {Any} response.image.image - Image Object
* @param {Number} response.position - Position in which to sort
* @param {String} response.redemption_points - Description
* @param {String} response.start_at - Must be DateTime
* @param {String} response.start_point - Must be either `fixed` or `event`.
* @param {Number} response.threshold - Must be numeric
* @param {String} response.time_unit - Must be one of `day`, `month`, `year`.
* @param {String} response.updated_at - Updated at
*/
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.title = attributes.title;
/** @type {String} -- either `count` or `time` */
this.basedOn = attributes.based_on;
/** @type {String} */
this.cacheToken = attributes.cache_token;
/** @type {String} */
this.createdAt = attributes.created_at;
/** @type {String} */
this.description = attributes.description;
if (attributes.disabled_image) {
/** @type {ImageModel} */
this.disabledImage = attributes.disabled_image;
}
/** @type {Boolean} */
this.enabled = attributes.enabled;
/** @type {Any} */
this.featured = attributes.featured;
if (attributes.image) {
/** @type {ImageModel} */
this.image = attributes.image;
}
/** @type {Number} */
this.position = attributes.position;
/** @type {Number} */
this.redemptionPoints = attributes.redemption_points;
/** @type {String} */
this.startAt = attributes.start_at;
/** @type {String} */
this.startPoint = attributes.start_point;
/** @type {Number} */
this.threshold = attributes.threshold;
/** @type {String} */
this.timeUnit = attributes.time_unit;
/** @type {String} */
this.updatedAt = attributes.updated_at;
}
}
export default BadgeModel;