mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-15 18:26:15 +01:00
21 lines
467 B
JavaScript
21 lines
467 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');
|
||
|
|
|
||
|
|
module.exports = function (middleware) {
|
||
|
|
middleware.assertGroup = async (req, res, next) => {
|
||
|
|
const name = await groups.getGroupNameByGroupSlug(req.params.slug);
|
||
|
|
const exists = await groups.exists(name);
|
||
|
|
if (!exists) {
|
||
|
|
throw new Error('[[error:no-group]]');
|
||
|
|
}
|
||
|
|
|
||
|
|
next();
|
||
|
|
};
|
||
|
|
};
|