86 lines
2.8 KiB
JavaScript
86 lines
2.8 KiB
JavaScript
var express = require('express');
|
|
var router = new express.Router();
|
|
var mail = require('../mail.js');
|
|
var template = require('../template.js');
|
|
var httpRequest = require('request');
|
|
|
|
// Payment method changes
|
|
router.post('/payment-update/:clientId', function(request, response, next) {
|
|
mail.sendWithTemplate('payment-update', {recipient: request.params.clientId}, error => {
|
|
if (error)
|
|
return response.status(400).json({message: error.message});
|
|
|
|
return response.json();
|
|
});
|
|
});
|
|
|
|
// Printer setup
|
|
router.post('/printer-setup/:clientId', function(request, response, next) {
|
|
mail.sendWithTemplate('printer-setup', {recipient: request.params.clientId}, error => {
|
|
if (error)
|
|
return response.status(400).json({message: error.message});
|
|
|
|
return response.json();
|
|
});
|
|
});
|
|
|
|
// Printer setup preview
|
|
router.get('/printer-setup/:clientId', function(request, response, next) {
|
|
template.get('printer-setup', {recipient: request.params.clientId}, true, (error, result) => {
|
|
if (error)
|
|
return response.status(400).json({message: error.message});
|
|
|
|
response.send(result.body);
|
|
});
|
|
});
|
|
|
|
// Client welcome
|
|
router.post('/client-welcome/:clientId', function(request, response, next) {
|
|
mail.sendWithTemplate('client-welcome', {recipient: request.params.clientId}, error => {
|
|
if (error)
|
|
return response.status(400).json({message: error.message});
|
|
|
|
return response.json();
|
|
});
|
|
});
|
|
|
|
// Client welcome preview
|
|
router.get('/client-welcome/:clientId', function(request, response, next) {
|
|
template.get('client-welcome', {recipient: request.params.clientId}, true, (error, result) => {
|
|
if (error)
|
|
return response.status(400).json({message: error.message});
|
|
|
|
response.send(result.body);
|
|
});
|
|
});
|
|
|
|
// Sepa core
|
|
router.post('/sepa-core/:clientId', function(request, response, next) {
|
|
var options = {
|
|
url: 'http://localhost:3008/manuscript/sepa-core/7422',
|
|
method: 'POST',
|
|
headers: {
|
|
'authorization': request.headers.authorization
|
|
}
|
|
}
|
|
|
|
let httpStream = httpRequest(options, function(error, httpResponse, body) {
|
|
if (error)
|
|
return response.status(400).json({message: httpResponse.message});
|
|
});
|
|
|
|
if (httpStream)
|
|
mail.send('joan@verdnatura.es', 'Correu de prova', 'test message', [{filename: 'test.pdf', content: httpStream}], function(error, result) {
|
|
if (error)
|
|
return response.status(400).json({message: error.message});
|
|
});
|
|
/* mail.sendWithTemplate('sepa-core', {recipient: request.params.clientId}, error => {
|
|
if (error)
|
|
return response.status(400).json({message: error.message});
|
|
|
|
return response.json();
|
|
}); */
|
|
});
|
|
|
|
module.exports = router;
|