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

19 lines
717 B
JavaScript
Raw Normal View History

2017-03-23 16:27:59 +09:00
import { addCallback } from 'meteor/vulcan:core';
// limit the number of items that can be requested at once
const CommentsMaxLimit = (parameters, terms) => {
var maxLimit = 1000;
2015-05-08 09:20:58 +09:00
// if a limit was provided with the terms, add it too (note: limit=0 means "no limit")
if (typeof terms.limit !== 'undefined') {
2015-05-08 09:20:58 +09:00
_.extend(parameters.options, {limit: parseInt(terms.limit)});
}
2015-05-08 09:20:58 +09:00
// 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) {
2015-05-08 09:20:58 +09:00
parameters.options.limit = maxLimit;
}
return parameters;
}
addCallback("comments.parameters", CommentsMaxLimit);