mirror of
				https://github.com/KevinMidboe/ISPDowntimeMonitor.git
				synced 2025-10-29 17:50:12 +00:00 
			
		
		
		
	Db functions as resources for endpoints.
Db functoins for: - getting event by id. - getting events where secuential statues are truncated. - get events, but w/ select on date & isOk status.
This commit is contained in:
		
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| @@ -1,5 +1,6 @@ | |||||||
| # Project files to ignore | # Project files to ignore | ||||||
| config.js | config.js | ||||||
|  | pdfExports/* | ||||||
|  |  | ||||||
| *.swp | *.swp | ||||||
| .DS_Store | .DS_Store | ||||||
|   | |||||||
							
								
								
									
										20
									
								
								src/db.js
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								src/db.js
									
									
									
									
									
								
							| @@ -26,8 +26,26 @@ const commitServiceEventToDatabase = async (serviceMessages, pdfFilename) => { | |||||||
| } | } | ||||||
|  |  | ||||||
| const getAllEvents = () => Event.find().exec() | const getAllEvents = () => Event.find().exec() | ||||||
|  | const getEventById = (id) => Event.findById(id).exec() | ||||||
|  |  | ||||||
|  | const getAlternatingEventStatuses = () => Event.find().exec() | ||||||
|  |   .then(events => { | ||||||
|  |     let lastEventStatus; | ||||||
|  |     return events.filter(event => { | ||||||
|  |       if (event.isOk != lastEventStatus) { | ||||||
|  |         lastEventStatus = event.isOk; | ||||||
|  |         return event | ||||||
|  |       } | ||||||
|  |     }) | ||||||
|  |   }) | ||||||
|  |  | ||||||
|  | const getEventStatus = () => Event.find().select('date isOk').exec() | ||||||
|  |   .then(events => events.reverse()) | ||||||
|  |  | ||||||
| module.exports = { | module.exports = { | ||||||
|   commitServiceEventToDatabase, |   commitServiceEventToDatabase, | ||||||
|   getAllEvents |   getAllEvents, | ||||||
|  |   getEventById, | ||||||
|  |   getAlternatingEventStatuses, | ||||||
|  |   getEventStatus | ||||||
| } | } | ||||||
		Reference in New Issue
	
	Block a user