Skip to content

Commit

Permalink
Prepare and modify sending of (all) notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
GPlay97 committed Aug 11, 2020
1 parent 47de722 commit 9509f3d
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 5 deletions.
50 changes: 50 additions & 0 deletions controllers/notifications.js
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
};
10 changes: 5 additions & 5 deletions routes/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ const notificationsController = require('../controllers/notifications');

router.get('/', authorizationMiddleware, authenticationMiddleware, notificationsController.getNotificationsQuota);

router.post('/', authorizationMiddleware, authenticationMiddleware, notificationsController.sendNotifications);
router.post('/mail', authorizationMiddleware, authenticationMiddleware, notificationsController.sendMailNotification);
router.post('/push', authorizationMiddleware, authenticationMiddleware, notificationsController.sendPushNotification);
router.post('/telegram', authorizationMiddleware, authenticationMiddleware, notificationsController.sendTelegramNotification);
router.post('/sms', authorizationMiddleware, authenticationMiddleware, notificationsController.sendSMSNotification);
router.post('/', authorizationMiddleware, authenticationMiddleware, notificationsController.sendNotification);
router.post('/mail', authorizationMiddleware, authenticationMiddleware, notificationsController.sendNotification);
router.post('/push', authorizationMiddleware, authenticationMiddleware, notificationsController.sendNotification);
router.post('/telegram', authorizationMiddleware, authenticationMiddleware, notificationsController.sendNotification);
router.post('/sms', authorizationMiddleware, authenticationMiddleware, notificationsController.sendNotification);

module.exports = router;

0 comments on commit 9509f3d

Please sign in to comment.