mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
refactor(socket.io): deprecate categories.get in favour of api.categories.list
This commit is contained in:
@@ -15,6 +15,22 @@ const hasAdminPrivilege = async (uid, privilege = 'categories') => {
|
||||
}
|
||||
};
|
||||
|
||||
categoriesAPI.list = async (caller) => {
|
||||
async function getCategories() {
|
||||
const cids = await categories.getCidsByPrivilege('categories:cid', caller.uid, 'find');
|
||||
return await categories.getCategoriesData(cids);
|
||||
}
|
||||
|
||||
const [isAdmin, categoriesData] = await Promise.all([
|
||||
user.isAdministrator(caller.uid),
|
||||
getCategories(),
|
||||
]);
|
||||
|
||||
return {
|
||||
categories: categoriesData.filter(category => category && (!category.disabled || isAdmin)),
|
||||
};
|
||||
};
|
||||
|
||||
categoriesAPI.get = async function (caller, data) {
|
||||
const [userPrivileges, category] = await Promise.all([
|
||||
privileges.categories.get(data.cid, caller.uid),
|
||||
|
||||
@@ -7,6 +7,10 @@ const helpers = require('../helpers');
|
||||
|
||||
const Categories = module.exports;
|
||||
|
||||
Categories.list = async (req, res) => {
|
||||
helpers.formatApiResponse(200, res, await api.categories.list(req));
|
||||
};
|
||||
|
||||
Categories.get = async (req, res) => {
|
||||
helpers.formatApiResponse(200, res, await api.categories.get(req, req.params));
|
||||
};
|
||||
|
||||
@@ -10,6 +10,7 @@ const { setupApiRoute } = routeHelpers;
|
||||
module.exports = function () {
|
||||
const middlewares = [middleware.ensureLoggedIn];
|
||||
|
||||
setupApiRoute(router, 'get', '/', [...middlewares], controllers.write.categories.list);
|
||||
setupApiRoute(router, 'post', '/', [...middlewares, middleware.checkRequired.bind(null, ['name'])], controllers.write.categories.create);
|
||||
setupApiRoute(router, 'get', '/:cid', [], controllers.write.categories.get);
|
||||
setupApiRoute(router, 'put', '/:cid', [...middlewares], controllers.write.categories.update);
|
||||
|
||||
@@ -18,15 +18,9 @@ SocketCategories.getRecentReplies = async function (socket, cid) {
|
||||
};
|
||||
|
||||
SocketCategories.get = async function (socket) {
|
||||
async function getCategories() {
|
||||
const cids = await categories.getCidsByPrivilege('categories:cid', socket.uid, 'find');
|
||||
return await categories.getCategoriesData(cids);
|
||||
}
|
||||
const [isAdmin, categoriesData] = await Promise.all([
|
||||
user.isAdministrator(socket.uid),
|
||||
getCategories(),
|
||||
]);
|
||||
return categoriesData.filter(category => category && (!category.disabled || isAdmin));
|
||||
sockets.warnDeprecated(socket, 'GET /api/v3/categories');
|
||||
const { categories } = await api.categories.list(socket);
|
||||
return categories;
|
||||
};
|
||||
|
||||
SocketCategories.getWatchedCategories = async function (socket) {
|
||||
|
||||
Reference in New Issue
Block a user