api: add pagination for guilds

start adding apiMessages

add apiMessages lib with tests

use apiMessage and fix tests

fix content tests

guilds pagination: add api docs

guilds pagination: improve api docs
This commit is contained in:
Matteo Pagliazzi
2017-03-10 14:14:42 +01:00
parent 767763fbf6
commit 939712ad1f
9 changed files with 140 additions and 7 deletions

View File

@@ -0,0 +1,21 @@
// A map of messages used by the API that don't need to be translated and
// so are not placed into /common/locales
import _ from 'lodash';
// When this file grows, it can be split into multiple ones.
const messages = {
guildsOnlyPaginate: 'Only public guilds support pagination.',
guildsPaginateBooleanString: 'req.query.paginate must be a boolean string.',
guildsPageInteger: 'req.query.page must be an integer greater than or equal to 0.',
};
export default function (msgKey, vars = {}) {
let message = messages[msgKey];
if (!message) throw new Error(`Error processing the API message "${msgKey}".`);
let clonedVars = vars ? _.clone(vars) : {};
// TODO cache the result of template() ? More memory usage, faster output
return _.template(message)(clonedVars);
}