-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prepare and modify sending of (all) notifications
- Loading branch information
Showing
2 changed files
with
55 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
const axios = require('axios'); | ||
const asyncHandler = require('@evnotify/utils').asyncHandler; | ||
const mailController = require('./mail'); | ||
|
||
const retrieveData = async(req) => { | ||
return Promise.all([ | ||
axios.get(`${process.env.SETTINGS_SERVICE}/${req.params.akey}`, { | ||
headers: { | ||
'Authorization': req.headers.authorization, | ||
'Authentication': req.headers.authentication, | ||
'AKey': req.params.akey | ||
} | ||
}).then((response) => { | ||
return response.data; | ||
}), | ||
axios.get(`${process.env.SYNC_SERVICE}/${akey}`, { | ||
headers: { | ||
'Authorization': req.headers.authorization, | ||
'Authentication': req.headers.authentication, | ||
'AKey': req.params.akey | ||
} | ||
}).then((response) => { | ||
return response.data; | ||
}) | ||
]); | ||
}; | ||
|
||
|
||
const getNotificationsQuota = asyncHandler(async (req, res, next) => { | ||
|
||
}); | ||
|
||
const sendNotification = asyncHandler(async (req, res, next) => { | ||
const [settings, sync] = await retrieveData(req); | ||
const notificationChannel = req.baseUrl.replace('/') || 'broadcast'; | ||
const notificationType = req.body.type; | ||
|
||
// TODO: implement the notifications | ||
if (notificationChannel === 'mail' || notificationChannel === 'broadcast') mailController.sendMessage(); | ||
if (notificationChannel === 'telegram' || notificationChannel === 'broadcast') telegramController.sendMessage(); | ||
if (notificationChannel === 'push' || notificationChannel === 'broadcast') pushController.sendMessage(); | ||
if (notificationChannel === 'sms' || notificationChannel === 'broadcast') smsController.sendMessage(); | ||
|
||
res.sendStatus(200); | ||
}); | ||
|
||
module.exports = { | ||
getNotificationsQuota, | ||
sendNotification | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters