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:
2020-06-07 23:50:24 +02:00
committed by KevinMidboe
parent fd340449e1
commit 6cfdbd6983
2 changed files with 20 additions and 1 deletions

1
.gitignore vendored
View File

@@ -1,5 +1,6 @@
# Project files to ignore # Project files to ignore
config.js config.js
pdfExports/*
*.swp *.swp
.DS_Store .DS_Store

View File

@@ -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
} }