grapher/lib/query/query.server.js

36 lines
868 B
JavaScript
Raw Normal View History

import createGraph from './lib/createGraph.js';
import prepareForProcess from './lib/prepareForProcess.js';
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
* @returns {*}
*/
2017-11-30 22:11:25 +02:00
fetch(context = {}) {
const node = createGraph(
this.collection,
prepareForProcess(this.body, this.params)
);
2017-11-30 22:11:25 +02:00
return hypernova(node, context.userId, {params: this.params});
}
/**
* @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();
}
}