Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Digest email WIP #600

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions imports/api/rest/digest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import CaseNotifications from '../case-notifications'

// https://github.com/unee-t/frontend/issues/282
export default (req, res) => {
if (req.query.accessToken !== process.env.API_ACCESS_TOKEN) {
res.send(401)
}

var oneWeekAgo = new Date()
oneWeekAgo.setDate(oneWeekAgo.getDate() - 7)

const query = { createdAt: {} }
query.createdAt['$gte'] = oneWeekAgo

if (!req.query.userid) {
res.send(400, 'userid missing')
}

query.userId = req.query.userid

if (req.query.from) { query.createdAt['$gte'] = new Date(req.query.from) }
if (req.query.to) { query.createdAt['$lte'] = new Date(req.query.to) }

console.log('digest', query)

res.send(CaseNotifications.find(query).fetch())
}
2 changes: 2 additions & 0 deletions imports/api/rest/rest-routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { json } from 'body-parser'
import getPendingInvitations from './get-pending-invitations'
import putPendingInvitations from './put-pending-invitations'
import getInvitations from './get-invitations'
import digest from './digest'
import getConvertedInvitations from './get-converted-invitations'
import postProcessDbChangeMessage from './post-process-db-change-message'
import postSesNotification from './post-ses-notification'
Expand All @@ -28,6 +29,7 @@ const createRoute = (method, url, handler) => {

createRoute('get', '/pending-invitations', getPendingInvitations)
createRoute('get', '/invitations', getInvitations)
createRoute('get', '/digest', digest)
createRoute('get', '/converted-invitations', getConvertedInvitations)
createRoute('put', '/pending-invitations/done', putPendingInvitations)
createRoute('post', '/db-change-message/process', postProcessDbChangeMessage)
Expand Down