Added the option for default notifications

This commit is contained in:
Ponkhy
2021-09-05 23:23:06 +02:00
parent 778995a4fb
commit 58240aceef
7 changed files with 69 additions and 4 deletions

View File

@@ -617,8 +617,13 @@ class Notification {
bean.name = notification.name;
bean.user_id = userID;
bean.config = JSON.stringify(notification)
bean.config = JSON.stringify(notification);
bean.is_default = notification.isDefault;
await R.store(bean)
if (notification.applyExisting) {
await applyNotificationEveryMonitor(bean.id, userID);
}
}
static async delete(notificationID, userID) {
@@ -702,6 +707,26 @@ function throwGeneralAxiosError(error) {
throw new Error(msg)
}
async function applyNotificationEveryMonitor(notificationID, userID) {
let monitors = await R.getAll("SELECT id FROM monitor WHERE user_id = ?", [
userID
]);
for (let i = 0; i < monitors.length; i++) {
let checkNotification = await R.findOne("monitor_notification", " monitor_id = ? AND notification_id = ? ", [
monitors[i].id,
notificationID,
])
if (! checkNotification) {
let relation = R.dispense("monitor_notification");
relation.monitor_id = monitors[i].id;
relation.notification_id = notificationID;
await R.store(relation)
}
}
}
module.exports = {
Notification,
}