feat(writeapi): added group joining and deletion

This commit is contained in:
Julian Lam
2020-10-01 14:11:59 -04:00
parent d044c3223e
commit 952dc211dd
11 changed files with 135 additions and 44 deletions

20
src/middleware/assert.js Normal file
View 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();
};
};