Skip to content

Node.js based forum software built for the modern web

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

Julian Lam52b78e83a89d
diff --git a/src/api/categories.js b/src/api/categories.js
index c37e287221..394db8f95d 100644
--- a/src/api/categories.js
+++ b/src/api/categories.js
@@ -61,6 +61,8 @@ categoriesAPI.delete = async function (caller, { cid }) {
});
};
+categoriesAPI.getPosts = async (caller, { cid }) => await categories.getRecentReplies(cid, caller.uid, 0, 4);
+
categoriesAPI.getPrivileges = async (caller, { cid }) => {
await hasAdminPrivilege(caller.uid, 'privileges');
diff --git a/src/controllers/write/categories.js b/src/controllers/write/categories.js
index d84f2bddfb..714816ef9f 100644
--- a/src/controllers/write/categories.js
+++ b/src/controllers/write/categories.js
@@ -31,6 +31,11 @@ Categories.delete = async (req, res) => {
helpers.formatApiResponse(200, res);
};
+Categories.getPosts = async (req, res) => {
+ const posts = await api.categories.getPosts(req, { ...req.params });
+ helpers.formatApiResponse(200, res, posts);
+};
+
Categories.getPrivileges = async (req, res) => {
const privilegeSet = await api.categories.getPrivileges(req, { cid: req.params.cid });
helpers.formatApiResponse(200, res, privilegeSet);
diff --git a/src/routes/write/categories.js b/src/routes/write/categories.js
index ed3ffd2dce..3b96556d20 100644
--- a/src/routes/write/categories.js
+++ b/src/routes/write/categories.js
@@ -15,6 +15,8 @@ module.exports = function () {
setupApiRoute(router, 'put', '/:cid', [...middlewares], controllers.write.categories.update);
setupApiRoute(router, 'delete', '/:cid', [...middlewares], controllers.write.categories.delete);
+ setupApiRoute(router, 'get', '/:cid/posts', [...middlewares], controllers.write.categories.getPosts);
+
setupApiRoute(router, 'get', '/:cid/privileges', [...middlewares], controllers.write.categories.getPrivileges);
setupApiRoute(router, 'put', '/:cid/privileges/:privilege', [...middlewares, middleware.checkRequired.bind(null, ['member'])], controllers.write.categories.setPrivilege);
setupApiRoute(router, 'delete', '/:cid/privileges/:privilege', [...middlewares, middleware.checkRequired.bind(null, ['member'])], controllers.write.categories.setPrivilege);
diff --git a/src/socket.io/categories.js b/src/socket.io/categories.js
index 169e207b0d..1db5358354 100644
--- a/src/socket.io/categories.js
+++ b/src/socket.io/categories.js
@@ -4,13 +4,17 @@ const categories = require('../categories');
const privileges = require('../privileges');
const user = require('../user');
const topics = require('../topics');
+const api = require('../api');
+
+const sockets = require('.');
const SocketCategories = module.exports;
require('./categories/search')(SocketCategories);
SocketCategories.getRecentReplies = async function (socket, cid) {
- return await categories.getRecentReplies(cid, socket.uid, 0, 4);
+ sockets.warnDeprecated(socket, 'GET /api/v3/categories/:cid/posts');
+ return await api.categories.getPosts(socket, { cid });
};
SocketCategories.get = async function (socket) {