async.waterfall

v1.18.x
barisusakli 10 years ago
parent d3b52136bd
commit ba9a68c59c

@ -8,16 +8,17 @@ var async = require('async'),
module.exports = function(Categories) { module.exports = function(Categories) {
Categories.create = function(data, callback) { Categories.create = function(data, callback) {
db.incrObjectField('global', 'nextCid', function(err, cid) { var category;
if (err) { async.waterfall([
return callback(err); function(next) {
} db.incrObjectField('global', 'nextCid', next);
},
function(cid, next) {
var slug = cid + '/' + utils.slugify(data.name), var slug = cid + '/' + utils.slugify(data.name),
order = data.order || cid, // If no order provided, place it at the end order = data.order || cid, // If no order provided, place it at the end
colours = Categories.assignColours(); colours = Categories.assignColours();
var category = { category = {
cid: cid, cid: cid,
name: data.name, name: data.name,
description: ( data.description ? data.description : '' ), description: ( data.description ? data.description : '' ),
@ -44,14 +45,12 @@ module.exports = function(Categories) {
async.apply(privileges.categories.give, defaultPrivileges, cid, 'administrators'), async.apply(privileges.categories.give, defaultPrivileges, cid, 'administrators'),
async.apply(privileges.categories.give, defaultPrivileges, cid, 'registered-users'), async.apply(privileges.categories.give, defaultPrivileges, cid, 'registered-users'),
async.apply(privileges.categories.give, ['find', 'read'], cid, 'guests') async.apply(privileges.categories.give, ['find', 'read'], cid, 'guests')
], function(err) { ], next);
if (err) { },
return callback(err); function(results, next) {
next(null, category);
} }
], callback);
callback(null, category);
});
});
}; };
Categories.assignColours = function() { Categories.assignColours = function() {

Loading…
Cancel
Save