mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-07 22:45:46 +01:00
admin cleanup
removed unnecessary admin checks in src/admin/user then realized they are just one liners so moved them to src/socket.io.admin.js moved categories update to categories folder
This commit is contained in:
46
src/categories/update.js
Normal file
46
src/categories/update.js
Normal file
@@ -0,0 +1,46 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
var async = require('async'),
|
||||
db = require('./../database'),
|
||||
utils = require('./../../public/src/utils');
|
||||
|
||||
|
||||
module.exports = function(Categories) {
|
||||
|
||||
Categories.update = function(modified, callback) {
|
||||
|
||||
function updateCategory(cid, next) {
|
||||
var category = modified[cid];
|
||||
var fields = Object.keys(category);
|
||||
|
||||
async.each(fields, function(key, next) {
|
||||
updateCategoryField(cid, key, category[key], next);
|
||||
}, next);
|
||||
}
|
||||
|
||||
function updateCategoryField(cid, key, value, next) {
|
||||
db.setObjectField('category:' + cid, key, value, function(err) {
|
||||
if(err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
if (key === 'name') {
|
||||
var slug = cid + '/' + utils.slugify(value);
|
||||
db.setObjectField('category:' + cid, 'slug', slug, next);
|
||||
} else if (key === 'order') {
|
||||
db.sortedSetAdd('categories:cid', value, cid, next);
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
var cids = Object.keys(modified);
|
||||
|
||||
async.each(cids, updateCategory, function(err) {
|
||||
callback(err, cids);
|
||||
});
|
||||
};
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user