Skip to content

Commit

Permalink
fix git issue #422
Browse files Browse the repository at this point in the history
  • Loading branch information
Niels Roche committed Aug 22, 2017
1 parent bda7a3e commit 51ac1e4
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 14 deletions.
12 changes: 12 additions & 0 deletions Utils.js
Expand Up @@ -303,3 +303,15 @@ function checkInternetConnection(host_url) {

return cn;
};

/*
* check for true / false
* also if the variable is from type string e.g. 'true' / 'false'
*/
function retBoolean(boolean) {
if (boolean === true || boolean === 'true') {
return true;
} else {
return false;
}
};
8 changes: 6 additions & 2 deletions ZAutomationAPIProvider.js
Expand Up @@ -528,15 +528,19 @@ _.extend(ZAutomationAPIWebRequest.prototype, {
error: "Something went wrong."
};

redeemed = this.req.query.hasOwnProperty("set_redeemed") ? Boolean(this.req.query.set_redeemed) : true;
all = this.req.query.hasOwnProperty("all") ? Boolean(this.req.query.all) : false;
redeemed = this.req.body.hasOwnProperty("set_redeemed")? retBoolean(this.req.body.set_redeemed) : false;
all = this.req.body.hasOwnProperty("all")? retBoolean(this.req.body.all) : false;

if (!all) {
this.controller.redeemNotification(id, redeemed, function (notice) {
if (notice) {
reply.code = 204;
reply.data = null;
reply.error = null;
} else {
reply.code = 404;
reply.data = null;
reply.error = 'Notification not found.';
}
});
} else {
Expand Down
31 changes: 19 additions & 12 deletions classes/AutomationController.js
Expand Up @@ -1484,31 +1484,38 @@ AutomationController.prototype.deleteAllRedeemedNotifications = function (callba
};

AutomationController.prototype.redeemNotification = function (id, redeemed, callback) {
var r = redeemed || true,
var r = redeemed !== undefined? redeemed : true;
id = id || 0;

if (id > 0) {
this.notifications.set(this.notifications.get().forEach(function(notification) {
if (notification.id === id) {
notification.redeemed = r;
}
}));
var notifications = this.notifications.get(),
index= _.findIndex(notifications, { id: id });

notifications[index].redeemed = r;

this.notifications.set(notifications);

if (typeof callback === 'function') {
callback(true);
}
} else {
if (typeof callback === 'function') {
callback(false);
}
}
};

AutomationController.prototype.redeemAllNotifications = function (redeemed, callback) {
var r = redeemed || true;
var r = redeemed !== undefined? redeemed : true;

try {
this.notifications.set(this.notifications.get().forEach(function(notification) {
if (!notification.redeemed) {
notification.redeemed = r;
}
}));
var notifications = this.notifications.get();

_.forEach(notifications, function (notification) {
notification.redeemed = r;
});

this.notifications.set(notifications);

if (typeof callback === 'function') {
callback(true);
Expand Down

0 comments on commit 51ac1e4

Please sign in to comment.