2017-05-30 06:06:14 +00:00
|
|
|
var express = require('express');
|
|
|
|
var router = new express.Router();
|
2017-06-12 11:41:02 +00:00
|
|
|
var mail = require('../mail.js');
|
2017-08-31 14:11:37 +00:00
|
|
|
var database = require('../database.js');
|
2017-09-27 15:44:51 +00:00
|
|
|
var settings = require('../settings.js');
|
2017-08-31 14:11:37 +00:00
|
|
|
// Single user notification
|
2017-09-27 15:44:51 +00:00
|
|
|
/* router.post('/:recipient/noticeUserSend', function(request, response) {
|
2017-08-31 14:11:37 +00:00
|
|
|
var params = {
|
|
|
|
recipient: request.params.recipient,
|
|
|
|
sender: request.body.sender,
|
|
|
|
category: request.body.category,
|
|
|
|
message: request.body.message
|
|
|
|
};
|
2017-06-12 11:41:02 +00:00
|
|
|
|
2017-08-31 14:11:37 +00:00
|
|
|
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) => {
|
2017-09-27 15:44:51 +00:00
|
|
|
mail.sendWithTemplate('notification-notice', params, result => {
|
2017-08-31 14:11:37 +00:00
|
|
|
return response.json(result);
|
|
|
|
});
|
|
|
|
});
|
2017-09-27 15:44:51 +00:00
|
|
|
}); */
|
2017-08-31 14:11:37 +00:00
|
|
|
|
|
|
|
// Send notification to all user subscribed to category
|
2017-09-27 15:44:51 +00:00
|
|
|
/* router.post('/:category/noticeCategorySend', function(request, response) {
|
2017-08-31 14:11:37 +00:00
|
|
|
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;
|
|
|
|
|
2017-09-27 15:44:51 +00:00
|
|
|
mail.sendWithTemplate('notification-notice', params, result => {
|
2017-08-31 14:11:37 +00:00
|
|
|
return response.json(result);
|
|
|
|
});
|
|
|
|
}, this);
|
|
|
|
});
|
2017-09-27 15:44:51 +00:00
|
|
|
}); */
|
2017-06-12 11:41:02 +00:00
|
|
|
|
2017-08-31 14:11:37 +00:00
|
|
|
// Send system notification
|
2017-09-27 15:44:51 +00:00
|
|
|
/* router.post('/:recipient/noticeSystemSend', function(request, response) {
|
2017-08-31 14:11:37 +00:00
|
|
|
var params = {
|
|
|
|
recipient: request.params.recipient,
|
2017-09-27 15:44:51 +00:00
|
|
|
sender: settings.smtp().auth.id,
|
2017-08-31 14:11:37 +00:00
|
|
|
category: request.body.category,
|
|
|
|
message: request.body.message
|
|
|
|
};
|
|
|
|
|
2017-09-27 15:44:51 +00:00
|
|
|
mail.sendWithTemplate('notification-notice', params, result => {
|
|
|
|
return response.json(result);
|
|
|
|
});
|
|
|
|
}); */
|
|
|
|
|
|
|
|
// Send notification to alias solunion on client deactivate
|
|
|
|
router.post('/client-deactivate/:clientId', function(request, response) {
|
|
|
|
var params = {
|
|
|
|
alias: 'solunion',
|
|
|
|
code: 'clientDeactivate',
|
|
|
|
bodyParams: {
|
|
|
|
clientId: request.params.clientId
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
mail.sendWithTemplate('notification-alias', params, result => {
|
2017-08-31 14:11:37 +00:00
|
|
|
return response.json(result);
|
|
|
|
});
|
2017-05-30 06:06:14 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = router;
|