2017-11-25 14:17:33 +02:00
|
|
|
import deepClone from 'lodash.cloneDeep';
|
2016-10-14 10:57:26 +03:00
|
|
|
|
2017-02-17 15:29:54 +02:00
|
|
|
export default class QueryBase {
|
2016-10-14 10:57:26 +03:00
|
|
|
constructor(collection, body, params = {}) {
|
|
|
|
this.collection = collection;
|
2016-10-19 15:22:50 +03:00
|
|
|
|
|
|
|
this.body = deepClone(body);
|
|
|
|
Object.freeze(this.body);
|
|
|
|
|
2016-10-14 10:57:26 +03:00
|
|
|
this._params = params;
|
|
|
|
}
|
|
|
|
|
|
|
|
clone(newParams) {
|
|
|
|
return new this.constructor(
|
|
|
|
this.collection,
|
|
|
|
deepClone(this.body),
|
|
|
|
_.extend({}, deepClone(this.params), newParams)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
get name() {
|
|
|
|
return `exposure_${this.collection._name}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
get params() {
|
|
|
|
return this._params;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Merges the params with previous params.
|
|
|
|
*
|
|
|
|
* @param data
|
|
|
|
* @returns {Query}
|
|
|
|
*/
|
|
|
|
setParams(data) {
|
|
|
|
_.extend(this._params, data);
|
|
|
|
|
|
|
|
return this;
|
|
|
|
}
|
2017-03-02 10:43:47 +02:00
|
|
|
}
|