refactor(socket.io): deprecate categories.setWatchState in favour of api.categories.setWatchState

This commit is contained in:
Julian Lam
2023-10-23 12:11:34 -04:00
parent f1dbfaa283
commit d7c6b3d60e
7 changed files with 81 additions and 24 deletions

View File

@@ -1,6 +1,7 @@
'use strict';
const categories = require('../../categories');
const meta = require('../../meta');
const api = require('../../api');
const helpers = require('../helpers');
@@ -44,6 +45,24 @@ Categories.getPosts = async (req, res) => {
helpers.formatApiResponse(200, res, posts);
};
Categories.setWatchState = async (req, res) => {
const { cid } = req.params;
let { uid, state } = req.body;
if (req.method === 'DELETE') {
// DELETE is always setting state to system default in acp
state = categories.watchStates[meta.config.categoryWatchState];
} else if (Object.keys(categories.watchStates).includes(state)) {
state = categories.watchStates[state]; // convert to integer for backend processing
} else {
throw new Error('[[error:invalid-data]]');
}
const { cids: modified } = await api.categories.setWatchState(req, { cid, state, uid });
helpers.formatApiResponse(200, res, { modified });
};
Categories.getPrivileges = async (req, res) => {
const privilegeSet = await api.categories.getPrivileges(req, { cid: req.params.cid });
helpers.formatApiResponse(200, res, privilegeSet);