You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
777 B
JavaScript

'use strict';
/**
* The middlewares here strictly act to "assert" validity of the incoming
* payload and throw an error otherwise.
*/
const groups = require('../groups');
const topics = require('../topics');
const helpers = require('../controllers/helpers');
module.exports = function (middleware) {
middleware.assertGroup = async (req, res, next) => {
const name = await groups.getGroupNameByGroupSlug(req.params.slug);
if (!name || await groups.exists(name)) {
return helpers.formatApiResponse(404, res, new Error('[[error:no-group]]'));
}
next();
};
middleware.assertTopic = async (req, res, next) => {
if (!await topics.exists(req.params.tid)) {
return helpers.formatApiResponse(404, res, new Error('[[error:no-topic]]'));
}
next();
};
};