mirror of
https://github.com/vale981/Vulcan
synced 2025-03-09 12:16:37 -04:00
28 lines
No EOL
1 KiB
JavaScript
28 lines
No EOL
1 KiB
JavaScript
// TODO: get rid of this?
|
|
|
|
import Mingo from 'mingo';
|
|
|
|
Mongo.Collection.prototype.findInStore = function (store, selector = {}, options = {}) {
|
|
const typeName = this.options && this.options.typeName;
|
|
const docs = _.where(store.getState().apollo.data, {__typename: typeName})
|
|
|
|
const mingoQuery = new Mingo.Query(selector);
|
|
|
|
const cursor = mingoQuery.find(docs);
|
|
const sortedDocs = cursor.sort(options.sort).all();
|
|
|
|
// console.log('// findRedux')
|
|
// console.log("typeName: ", typeName)
|
|
// console.log("selector: ", selector)
|
|
// console.log("options: ", options)
|
|
// console.log("all docs: ", docs)
|
|
// console.log("selected docs: ", cursor.all())
|
|
// console.log("sorted docs: ", cursor.sort(options.sort).all())
|
|
|
|
return {fetch: () => sortedDocs};
|
|
}
|
|
|
|
Mongo.Collection.prototype.findOneInStore = function (store, _idOrObject) {
|
|
const docs = typeof _idOrObject === 'string' ? this.findInStore(store, {_id: _idOrObject}).fetch() : this.findInStore(store, _idOrObject).fetch();
|
|
return docs.length === 0 ? undefined: docs[0];
|
|
} |