src/models/content/Content.js
import { stringToCamel } from '../../utilities/FormatUtility';
/**
* Model representing Dynamic Content.
*/
class ContentModel {
/**
* @param {Object} response - JSON formatted default response of a dynamic content
* @param {Number} response.id - The ID of the content
* @param {String} response.title - Title of the content
* @param {String} response.description - A description related to the content
* @param {String} response.created_at - The time at which the content was created
* @param {String} response.updated_at - The time at which the content was updated
* @param {Number} response.position - The position where the content is put on the platform
* @param {Array} response.tags - The tags to describe the content
* @param {Object} response.brand - The brand to describe the content
*/
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);
}
// Object.assign(this, attributes);
Object.keys(attributes).forEach((key) => {
if (['type', 'relationships', 'id'].indexOf(key) === -1) {
/** @type {Any} */
this[stringToCamel(key)] = attributes[key];
}
});
}
}
export default ContentModel;