Add new limit operator

This commit is contained in:
John Supplee 2021-02-26 17:31:44 +02:00
parent 2930e9cadb
commit 62b0d371ee
3 changed files with 16 additions and 2 deletions

View file

@ -227,6 +227,7 @@ BlazeComponent.extendComponent({
'operator-comment': 'comments', 'operator-comment': 'comments',
'operator-has': 'has', 'operator-has': 'has',
'operator-sort': 'sort', 'operator-sort': 'sort',
'operator-limit': 'limit',
}; };
const predicates = { const predicates = {
@ -430,6 +431,16 @@ BlazeComponent.extendComponent({
} else { } else {
value = predicateTranslations.has[value]; value = predicateTranslations.has[value];
} }
} else if (operator === 'limit') {
const limit = parseInt(value, 10);
if (isNaN(limit) || limit < 1) {
this.parsingErrors.push({
tag: 'operator-limit-invalid',
value,
});
} else {
value = limit;
}
} }
if (Array.isArray(params[operator])) { if (Array.isArray(params[operator])) {
params[operator].push(value); params[operator].push(value);

View file

@ -907,6 +907,7 @@
"operator-sort": "sort", "operator-sort": "sort",
"operator-comment": "comment", "operator-comment": "comment",
"operator-has": "has", "operator-has": "has",
"operator-limit": "limit",
"predicate-archived": "archived", "predicate-archived": "archived",
"predicate-ended": "ended", "predicate-ended": "ended",
"predicate-all": "all", "predicate-all": "all",
@ -928,6 +929,7 @@
"operator-sort-invalid": "sort of '%s' is invalid", "operator-sort-invalid": "sort of '%s' is invalid",
"operator-status-invalid": "'%s' is not a valid status", "operator-status-invalid": "'%s' is not a valid status",
"operator-has-invalid": "%s is not a valid existence check", "operator-has-invalid": "%s is not a valid existence check",
"operator-limit-invalid": "%s is not a valid limit. Limit should be a positive integer.",
"next-page": "Next Page", "next-page": "Next Page",
"previous-page": "Previous Page", "previous-page": "Previous Page",
"heading-notes": "Notes", "heading-notes": "Notes",

View file

@ -755,13 +755,14 @@ function findCards(sessionId, selector, projection, errors = null) {
// check(projection, Object); // check(projection, Object);
const userId = Meteor.userId(); const userId = Meteor.userId();
console.log('selector:', selector);
console.log('projection:', projection);
let cards; let cards;
if (!errors || !errors.hasErrors()) { if (!errors || !errors.hasErrors()) {
cards = Cards.find(selector, projection); cards = Cards.find(selector, projection);
} }
console.log('selector:', selector);
console.log('projection:', projection);
console.log('count:', cards.count()); console.log('count:', cards.count());
const update = { const update = {
$set: { $set: {