salix/services/mailer/application/route/notification.js

89 lines
2.8 KiB
JavaScript
Raw Normal View History

2017-05-30 06:06:14 +00:00
var express = require('express');
var router = new express.Router();
var mail = require('../mail.js');
var database = require('../database.js');
var settings = require('../settings.js');
var auth = require('../auth.js');
// Auth middleware
var requestToken = function(request, response, next) {
auth.init(request, response, next);
};
// Single user notification
/* router.post('/:recipient/noticeUserSend', function(request, response) {
var params = {
recipient: request.params.recipient,
sender: request.body.sender,
category: request.body.category,
message: request.body.message
};
if (params.sender == params.recipient)
return;
let query = `SELECT COUNT(*) isEnabled
FROM noticeSubscription s
JOIN noticeCategory c ON c.id = s.noticeCategoryFk AND c.isEnabled
WHERE c.keyName = ? AND s.userFk = ?`;
database.pool.query(query, [params.category, params.recipient, params.sender], (error, result) => {
mail.sendWithTemplate('notification-notice', params, result => {
return response.json(result);
});
});
}); */
// Send notification to all user subscribed to category
/* router.post('/:category/noticeCategorySend', function(request, response) {
var params = {
sender: request.body.sender,
category: request.params.category,
message: request.body.message
};
let query = `SELECT s.userFk id FROM noticeSubscription s JOIN noticeCategory
c ON c.id = s.noticeCategoryFk AND c.isEnabled WHERE c.keyName = ? AND s.userFk != ?`;
database.pool.query(query, [params.category, params.sender], (error, result) => {
result.forEach(function(user) {
params.recipient = user.id;
mail.sendWithTemplate('notification-notice', params, result => {
return response.json(result);
});
}, this);
});
}); */
// Send system notification
/* router.post('/:recipient/noticeSystemSend', function(request, response) {
var params = {
recipient: request.params.recipient,
sender: settings.smtp().auth.id,
category: request.body.category,
message: request.body.message
};
mail.sendWithTemplate('notification-notice', params, result => {
return response.json(result);
});
}); */
// Send notification to alias solunion on client deactivate
router.post('/client-deactivate/:clientId', requestToken, function(request, response) {
var params = {
alias: 'solunion',
code: 'clientDeactivate',
bodyParams: {
clientId: request.params.clientId
}
};
mail.sendWithTemplate('notification-alias', params, result => {
return response.json(result);
});
2017-05-30 06:06:14 +00:00
});
module.exports = router;