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