mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-08-08 11:31:27 +08:00
Added the option for default notifications
This commit is contained in:
@@ -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,
|
||||
}
|
||||
|
Reference in New Issue
Block a user