src/models/cohort/Cohort.js
/**
* Model representing a cohort.
*/
class CohortModel {
/**
* @param {Object} response - JSON formatted response of a cohort.
* @param {Number} response.id - The user role ID value
* @param {String} response.name - Name of the cohort
* @param {String} response.cohort_type - Cohort type - must be either 'dynamic' or 'static'
* @param {Boolean} response.created_at - The date when the cohort was created
* @param {Boolean} response.updated_at - The date when the cohort was last 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.name = attributes.name;
/** @type {String} */
this.cohortType = attributes.cohort_type;
/** @type {String} */
this.createdAt = attributes.created_at;
/** @type {String} */
this.updatedAt = attributes.updated_at;
}
}
export default CohortModel;