feat(writeapi): topic posting and replying

This commit is contained in:
Julian Lam
2020-10-01 14:26:34 -04:00
parent 40dc1c38d3
commit 4c833d0bf0
8 changed files with 129 additions and 7 deletions

View File

@@ -6,13 +6,23 @@
*/
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);
const exists = await groups.exists(name);
if (!exists) {
throw new Error('[[error:no-group]]');
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();