-
-
Save Sampath-Lokuge/dcb2979ca02c38a7bfedbc2acc07203d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async scheduleNotification(data: Transaction) { | |
let notifications: any[] = []; | |
notifications = await this.storage.get(LocalStorage.NOTIFICATIONS); | |
let firstNotificationTime = new Date(data.dueOn); | |
firstNotificationTime.setDate(firstNotificationTime.getDate()); | |
firstNotificationTime.setHours(20); | |
firstNotificationTime.setMinutes(23); | |
firstNotificationTime.setSeconds(0); | |
const id = random(1, 1000); | |
let notification = { | |
id: id, | |
title: 'Due Today', | |
text: `Payment for ${data.category.name}: ${data.description} of ${Number(data.totalPrice).toLocaleString()} is due today.`, | |
data: { transaction: data }, | |
at: firstNotificationTime, | |
} | |
if (notifications == null) notifications = []; | |
notifications.push(notification); | |
this.storage.set(LocalStorage.NOTIFICATIONS, notifications); | |
this.scheduleNotifications(notifications); | |
} | |
scheduleNotifications(notifications: any[]) { | |
cordova.plugins.notification.local.clearAll((res) => { | |
let notificationsDesc = notifications.map((notification) => { | |
return { | |
id: notification.id, | |
title: notification.title, | |
text: notification.text, | |
data: notification.data, | |
trigger: { at: notification.at } | |
} | |
}); | |
cordova.plugins.notification.local.schedule(notificationsDesc); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment