fixed complications with deleted id's

v1.18.x
psychobunny 10 years ago
parent def57d2926
commit f5eaa08340

@ -134,7 +134,9 @@ define('admin/extend/rewards', function() {
active: [{ active: [{
disabled: true, disabled: true,
value: '', value: '',
claimable: 1 claimable: 1,
rid: null,
id: null
}], }],
conditions: conditions, conditions: conditions,
conditionals: conditionals, conditionals: conditionals,

@ -8,14 +8,11 @@ var rewards = {},
rewards.save = function(data, callback) { rewards.save = function(data, callback) {
function save(data, next) { function save(data, next) {
if (!Object.keys(data.rewards).length) { function commit(err, id) {
return next(); if (err) {
} return callback(err);
}
var rewardsData = data.rewards;
delete data.rewards;
db.incrObjectField('global', 'nextRid', function(err, id) {
data.id = id; data.id = id;
async.parallel([ async.parallel([
@ -32,7 +29,20 @@ rewards.save = function(data, callback) {
db.setObject('rewards:id:' + data.id + ':rewards', rewardsData, next); db.setObject('rewards:id:' + data.id + ':rewards', rewardsData, next);
} }
], next); ], next);
}); }
if (!Object.keys(data.rewards).length) {
return next();
}
var rewardsData = data.rewards;
delete data.rewards;
if (!parseInt(data.id, 10)) {
db.incrObjectField('global', 'rewards:id', commit);
} else {
commit(false, data.id);
}
} }
async.each(data, save, function(err) { async.each(data, save, function(err) {

Loading…
Cancel
Save