mirror of
https://github.com/vale981/grapher
synced 2025-03-05 17:41:41 -05:00
added count method + added tests + updated restrictedFields to throw propper error
This commit is contained in:
parent
0dc2dff223
commit
8cff81e0ff
8 changed files with 61 additions and 4 deletions
|
@ -79,6 +79,12 @@ export default class Exposure {
|
|||
this.userId
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
Meteor.methods({
|
||||
[this.name + '.count'](body) {
|
||||
return collection.find(body.$filters || {}, {}, this.userId).count();
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,10 @@
|
|||
* @param restrictedFields
|
||||
*/
|
||||
export default (filters, options, restrictedFields) => {
|
||||
if (!_.isArray(restrictedFields)) {
|
||||
throw new Meteor.Error('Please specify an array of restricted fields.');
|
||||
}
|
||||
|
||||
if (options.fields) {
|
||||
options.fields = _.omit(options.fields, ...restrictedFields);
|
||||
} else {
|
||||
|
|
|
@ -31,5 +31,27 @@ describe('Exposure', function () {
|
|||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Should return the correct count', function (done) {
|
||||
Meteor.call('exposure_exposure_test.count', {}, function (err, res) {
|
||||
assert.isUndefined(err);
|
||||
|
||||
assert.equal(3, res);
|
||||
done();
|
||||
})
|
||||
});
|
||||
|
||||
it('Should return the correct count via query', function (done) {
|
||||
const query = Demo.createQuery({
|
||||
$options: {limit: 1}
|
||||
});
|
||||
|
||||
query.getCount(function (err, res) {
|
||||
assert.isUndefined(err);
|
||||
|
||||
assert.equal(3, res);
|
||||
done();
|
||||
})
|
||||
})
|
||||
});
|
||||
|
|
|
@ -135,6 +135,17 @@ export default class Linker {
|
|||
return _.isFunction(this.linkConfig.resolve);
|
||||
}
|
||||
|
||||
/**
|
||||
* Should return a single result.
|
||||
*/
|
||||
isOneResult()
|
||||
{
|
||||
return (
|
||||
(this.isVirtual() && this.linkConfig.relatedLinker.linkConfig.unique)
|
||||
|| (!this.isVirtual() && this.isSingle())
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param object
|
||||
* @returns {*}
|
||||
|
|
|
@ -9,7 +9,7 @@ export default (childCollectionNode, {limit, skip}) => {
|
|||
const isVirtual = linker.isVirtual();
|
||||
const isSingle = linker.isSingle();
|
||||
const removeStorageField = !childCollectionNode.parentHasMyLinkStorageFieldSpecified();
|
||||
const oneResult = (isVirtual && linker.linkConfig.relatedLinker.linkConfig.unique) || (!isVirtual) && isSingle;
|
||||
const oneResult = linker.isOneResult();
|
||||
|
||||
const fieldStorage = linker.linkStorageField;
|
||||
|
||||
|
|
|
@ -27,12 +27,18 @@ export default function fetch(node, parentObject, userId) {
|
|||
results = node.collection.find(filters, options, userId).fetch();
|
||||
}
|
||||
|
||||
_.each(results, result => {
|
||||
_.each(node.collectionNodes, collectionNode => {
|
||||
_.each(node.collectionNodes, collectionNode => {
|
||||
_.each(results, result => {
|
||||
result[collectionNode.linkName] = fetch(collectionNode, result, userId);
|
||||
//delete result[node.linker.linkStorageField];
|
||||
})
|
||||
});
|
||||
|
||||
if (parentObject) {
|
||||
if (node.linker.isOneResult()) {
|
||||
return _.first(results);
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
|
|
@ -85,6 +85,14 @@ export default class Query {
|
|||
}
|
||||
}
|
||||
|
||||
getCount(callback) {
|
||||
if (Meteor.isClient && !callback) {
|
||||
throw new Meteor.Error('not-allowed', 'You are on client so you must either provide a callback to get the count.');
|
||||
}
|
||||
|
||||
return Meteor.call(this.name + '.count', applyFilterFunction(this.body, this.params), callback);
|
||||
}
|
||||
|
||||
setParams(data) {
|
||||
_.extend(this._params, data);
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
Package.describe({
|
||||
name: 'cultofcoders:grapher',
|
||||
version: '1.1.2',
|
||||
version: '1.1.3',
|
||||
// Brief, one-line summary of the package.
|
||||
summary: 'Grapher makes linking collections easily. And fetching data as a graph.',
|
||||
// URL to the Git repository containing the source code for this package.
|
||||
|
|
Loading…
Add table
Reference in a new issue