Skip to content

Commit

Permalink
Prevent invalid date parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
abuturla committed Feb 28, 2018
1 parent 02dfdd4 commit ef2b4c6
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions scripts/buildfire/services/notifications/localNotifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ if (typeof (buildfire) == "undefined") throw ("please add buildfire.js first to

//https://github.com/BuildFire/sdk/wiki/Buildfire-Local-Notifications-API
buildfire.notifications.localNotification = {
_isDate: function(date){
var isDate = (Object.prototype.toString.call(date) === "[object Date]") ? true: false;

return isDate;
},

//--- options properties ---
//title: string
//text: string
Expand All @@ -10,7 +16,10 @@ buildfire.notifications.localNotification = {
send: function (options, callback) {
var packetId = null;
var command = 'localNotifications.schedule';

if(options.at && !window.buildfire.notifications.localNotification._isDate(options.at)){
callback('Option "at" must be a Date type.', null);
return;
}
var packet = new Packet(packetId, command, options);
buildfire._sendPacket(packet, callback);
},
Expand All @@ -23,7 +32,10 @@ buildfire.notifications.localNotification = {
schedule: function (options, callback) {
var packetId = null;
var command = 'localNotifications.schedule';

if(options.at && !window.buildfire.notifications.localNotification._isDate(options.at)){
callback('Option "at" must be a Date type.', null);
return;
}
var packet = new Packet(packetId, command, options);
buildfire._sendPacket(packet, callback);
}
Expand Down

0 comments on commit ef2b4c6

Please sign in to comment.