feat: added DELETE /api/v1/categories/:cid route

v1.18.x
Julian Lam 5 years ago
parent e942ad8101
commit 3072de4812

@ -107,17 +107,18 @@ define('admin/manage/category', [
});
}, 1000);
socket.emit('admin.categories.purge', ajaxify.data.category.cid, function (err) {
if (err) {
return app.alertError(err.message);
}
$.ajax({
url: config.relative_path + '/api/v1/categories/' + ajaxify.data.category.cid,
method: 'delete',
}).done(function () {
if (intervalId) {
clearInterval(intervalId);
}
modal.modal('hide');
app.alertSuccess('[[admin/manage/categories:alert.purge-success]]');
ajaxify.go('admin/manage/categories');
}).fail(function (ev) {
app.alertError(ev.responseJSON.status.message);
});
return false;

@ -1,6 +1,7 @@
'use strict';
const categories = require('../../categories');
const events = require('../../events');
const helpers = require('../helpers');
@ -20,3 +21,17 @@ Categories.update = async (req, res) => {
const categoryObjs = await categories.getCategories([req.params.cid]);
helpers.formatApiResponse(200, res, categoryObjs[0]);
};
Categories.delete = async (req, res) => {
const name = await categories.getCategoryField(req.params.cid, 'name');
await Categories.purge(req.params.cid, req.user.uid);
await events.log({
type: 'category-purge',
uid: req.user.uid,
ip: req.ip,
cid: req.params.cid,
name: name,
});
helpers.formatApiResponse(200, res);
};

@ -10,16 +10,11 @@ const setupApiRoute = routeHelpers.setupApiRoute;
module.exports = function () {
const middlewares = [middleware.authenticate];
setupApiRoute(router, '/', middleware, [...middlewares, middleware.checkRequired.bind(null, ['name'])], 'post', controllers.write.categories.create);
setupApiRoute(router, '/:cid', middleware, [...middlewares], 'put', controllers.write.categories.update);
// app.route('/:cid')
// .delete(apiMiddleware.requireUser, apiMiddleware.requireAdmin, apiMiddleware.validateCid, function(req, res) {
// Categories.purge(req.params.cid, req.user.uid, function(err) {
// return errorHandler.handle(err, res);
// });
// });
setupApiRoute(router, '/', middleware, [...middlewares, middleware.checkRequired.bind(null, ['name']), middleware.isAdmin], 'post', controllers.write.categories.create);
setupApiRoute(router, '/:cid', middleware, [...middlewares, middleware.isAdmin], 'put', controllers.write.categories.update);
setupApiRoute(router, '/:cid', middleware, [...middlewares, middleware.isAdmin], 'delete', controllers.write.categories.delete);
// Category disabled state is deprecated, so this route won't be ported over
// app.route('/:cid/state')
// .put(apiMiddleware.requireUser, apiMiddleware.requireAdmin, apiMiddleware.validateCid, function(req, res) {
// var payload = {};

@ -40,6 +40,8 @@ Categories.getNames = async function () {
};
Categories.purge = async function (socket, cid) {
sockets.warnDeprecated(socket, 'DELETE /api/v1/categories/:cid');
const name = await categories.getCategoryField(cid, 'name');
await categories.purge(cid, socket.uid);
await events.log({

Loading…
Cancel
Save