mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-16 02:36:16 +01:00
feat(writeapi): added group joining and deletion
This commit is contained in:
20
src/middleware/assert.js
Normal file
20
src/middleware/assert.js
Normal file
@@ -0,0 +1,20 @@
|
||||
'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();
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user