var express = require('express'); var router = new express.Router(); var mail = require('../mail.js'); var database = require('../database.js'); var template = require('../template.js'); // Escrito de cambios en méto de pago del cliente router.post('/:userId/payment-update', function(request, response, next) { database.pool.query('SELECT `e-mail` AS email, LOWER(p.Codigo) AS countryCode FROM Clientes AS c JOIN Paises AS p ON p.id = c.Id_Pais WHERE Id_Cliente = ?', [request.params.userId], function(error, qryRs) { if (qryRs.length == 0) return response.json({data: {message: 'Client not found'}}); template.getTemplate('payment-update', qryRs[0].countryCode, {userId: request.params.userId}, function(tplRs, error) { if (error) return response.json({data: {message: error}}); mail.send(qryRs[0].email, tplRs.subject, tplRs.body, tplRs.attachments, (mailrs, error) => { if (error) return response.json({data: {message: error}}); return response.json({data: {message: 'Mail sent'}}); }); }); }); }); module.exports = router;