2016-10-14 10:57:26 +03:00
|
|
|
import createGraph from './lib/createGraph.js';
|
2016-11-07 18:44:09 +02:00
|
|
|
import prepareForProcess from './lib/prepareForProcess.js';
|
2016-10-14 10:57:26 +03:00
|
|
|
import hypernova from './hypernova/hypernova.js';
|
|
|
|
import Base from './query.base';
|
|
|
|
|
|
|
|
export default class Query extends Base {
|
|
|
|
/**
|
|
|
|
* Retrieves the data.
|
2017-11-30 22:11:25 +02:00
|
|
|
* @param context
|
2016-10-14 10:57:26 +03:00
|
|
|
* @returns {*}
|
|
|
|
*/
|
2017-11-30 22:11:25 +02:00
|
|
|
fetch(context = {}) {
|
2016-10-14 10:57:26 +03:00
|
|
|
const node = createGraph(
|
|
|
|
this.collection,
|
2016-11-07 18:44:09 +02:00
|
|
|
prepareForProcess(this.body, this.params)
|
2016-10-14 10:57:26 +03:00
|
|
|
);
|
|
|
|
|
2017-11-30 22:11:25 +02:00
|
|
|
return hypernova(node, context.userId, {params: this.params});
|
2016-10-14 10:57:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param args
|
|
|
|
* @returns {*}
|
|
|
|
*/
|
|
|
|
fetchOne(...args) {
|
|
|
|
return _.first(this.fetch(...args));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the count of matching elements.
|
|
|
|
* @returns {integer}
|
|
|
|
*/
|
|
|
|
getCount() {
|
|
|
|
return this.collection.find(this.body.$filters || {}, {}).count();
|
|
|
|
}
|
|
|
|
}
|