Vulcan/packages/nova-comments/lib/parameters.js

26 lines
907 B
JavaScript

import { addCallback } from 'meteor/nova:core';
// limit the number of items that can be requested at once
const CommentsMaxLimit = (parameters, terms) => {
var maxLimit = 1000;
// if a limit was provided with the terms, add it too (note: limit=0 means "no limit")
if (typeof terms.limit !== 'undefined') {
_.extend(parameters.options, {limit: parseInt(terms.limit)});
}
// limit to "maxLimit" items at most when limit is undefined, equal to 0, or superior to maxLimit
if(!parameters.options.limit || parameters.options.limit === 0 || parameters.options.limit > maxLimit) {
parameters.options.limit = maxLimit;
}
return parameters;
}
addCallback("comments.parameters", CommentsMaxLimit);
const CommentsBelongingToPost = (parameters, terms) => {
parameters.selector.postId = terms.postId;
return parameters;
};
addCallback("comments.parameters", CommentsBelongingToPost);