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:
barisusakli
2014-04-01 17:12:03 -04:00
parent ac88b5fc25
commit 10f56faf9d
6 changed files with 67 additions and 148 deletions

46
src/categories/update.js Normal file
View 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);
});
};
};