|  | @ -86,27 +86,28 @@ class Notification { | 
			
		
	
		
		
			
				
					|  |  |     } |  |  |     } | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |     static async save(notification, notificationID, userID) { |  |  |     static async save(notification, notificationID, userID) { | 
			
		
	
		
		
			
				
					
					|  |  |         let bean |  |  |         let bean; | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |         if (notificationID) { |  |  |         if (notificationID) { | 
			
		
	
		
		
			
				
					|  |  |             bean = await R.findOne("notification", " id = ? AND user_id = ? ", [ |  |  |             bean = await R.findOne("notification", " id = ? AND user_id = ? ", [ | 
			
		
	
		
		
			
				
					|  |  |                 notificationID, |  |  |                 notificationID, | 
			
		
	
		
		
			
				
					|  |  |                 userID, |  |  |                 userID, | 
			
		
	
		
		
			
				
					
					|  |  |             ]) |  |  |             ]); | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |             if (! bean) { |  |  |             if (! bean) { | 
			
		
	
		
		
			
				
					
					|  |  |                 throw new Error("notification not found") |  |  |                 throw new Error("notification not found"); | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  |             } |  |  |             } | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |         } else { |  |  |         } else { | 
			
		
	
		
		
			
				
					
					|  |  |             bean = R.dispense("notification") |  |  |             bean = R.dispense("notification"); | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  |         } |  |  |         } | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |         bean.name = notification.name; |  |  |         bean.name = notification.name; | 
			
		
	
		
		
			
				
					|  |  |         bean.user_id = userID; |  |  |         bean.user_id = userID; | 
			
		
	
		
		
			
				
					|  |  |         bean.config = JSON.stringify(notification); |  |  |         bean.config = JSON.stringify(notification); | 
			
		
	
		
		
			
				
					|  |  |         bean.is_default = notification.isDefault || false; |  |  |         bean.is_default = notification.isDefault || false; | 
			
		
	
		
		
			
				
					
					|  |  |         await R.store(bean) |  |  |         bean.incidents = notification.incidents || true; | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  |  |  |  |         await R.store(bean); | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |         if (notification.applyExisting) { |  |  |         if (notification.applyExisting) { | 
			
		
	
		
		
			
				
					|  |  |             await applyNotificationEveryMonitor(bean.id, userID); |  |  |             await applyNotificationEveryMonitor(bean.id, userID); | 
			
		
	
	
		
		
			
				
					|  | @ -119,13 +120,13 @@ class Notification { | 
			
		
	
		
		
			
				
					|  |  |         let bean = await R.findOne("notification", " id = ? AND user_id = ? ", [ |  |  |         let bean = await R.findOne("notification", " id = ? AND user_id = ? ", [ | 
			
		
	
		
		
			
				
					|  |  |             notificationID, |  |  |             notificationID, | 
			
		
	
		
		
			
				
					|  |  |             userID, |  |  |             userID, | 
			
		
	
		
		
			
				
					
					|  |  |         ]) |  |  |         ]); | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |         if (! bean) { |  |  |         if (! bean) { | 
			
		
	
		
		
			
				
					
					|  |  |             throw new Error("notification not found") |  |  |             throw new Error("notification not found"); | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  |         } |  |  |         } | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |         await R.trash(bean) |  |  |         await R.trash(bean); | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  |     } |  |  |     } | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |     static checkApprise() { |  |  |     static checkApprise() { | 
			
		
	
	
		
		
			
				
					|  | @ -145,17 +146,17 @@ async function applyNotificationEveryMonitor(notificationID, userID) { | 
			
		
	
		
		
			
				
					|  |  |         let checkNotification = await R.findOne("monitor_notification", " monitor_id = ? AND notification_id = ? ", [ |  |  |         let checkNotification = await R.findOne("monitor_notification", " monitor_id = ? AND notification_id = ? ", [ | 
			
		
	
		
		
			
				
					|  |  |             monitors[i].id, |  |  |             monitors[i].id, | 
			
		
	
		
		
			
				
					|  |  |             notificationID, |  |  |             notificationID, | 
			
		
	
		
		
			
				
					
					|  |  |         ]) |  |  |         ]); | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |         if (! checkNotification) { |  |  |         if (! checkNotification) { | 
			
		
	
		
		
			
				
					|  |  |             let relation = R.dispense("monitor_notification"); |  |  |             let relation = R.dispense("monitor_notification"); | 
			
		
	
		
		
			
				
					|  |  |             relation.monitor_id = monitors[i].id; |  |  |             relation.monitor_id = monitors[i].id; | 
			
		
	
		
		
			
				
					|  |  |             relation.notification_id = notificationID; |  |  |             relation.notification_id = notificationID; | 
			
		
	
		
		
			
				
					
					|  |  |             await R.store(relation) |  |  |             await R.store(relation); | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  |         } |  |  |         } | 
			
		
	
		
		
			
				
					|  |  |     } |  |  |     } | 
			
		
	
		
		
			
				
					|  |  | } |  |  | } | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  | module.exports = { |  |  | module.exports = { | 
			
		
	
		
		
			
				
					|  |  |     Notification, |  |  |     Notification, | 
			
		
	
		
		
			
				
					
					|  |  | } |  |  | }; | 
			
				
				
			
		
	
		
		
	
	
		
		
			
				
					|  | 
 |