src/models/filter/Filter.js
/**
* Model representing a filter.
*/
class FilterModel {
/**
* @param {Object} response - JSON formatted response of a filter.
* @param {Number} response.id - The filter group id value
* @param {String} response.criteria - @TODO
* @param {String} response.method - @TODO
* @param {String} response.operator - for example: '>', '<', '='
* @param {String} response.value - @TODO
* @param {Boolean} response.created_at - The date when the filter was created
* @param {Boolean} response.updated_at - The date when the filter 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.criteria = attributes.criteria;
/** @type {String} */
this.method = attributes.method;
/** @type {String} */
this.operator = attributes.operator;
/** @type {String} */
this.value = attributes.value;
/** @type {String} */
this.createdAt = attributes.created_at;
/** @type {String} */
this.updatedAt = attributes.updated_at;
}
}
export default FilterModel;