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 template = require ( '../template.js' ) ;
// Escrito de cambios en méto de pago del cliente
2017-06-12 11:41:02 +00:00
router . post ( '/:userId/payment-update' , function ( request , response , next ) {
2017-06-07 13:28:42 +00:00
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' } } ) ;
2017-06-12 11:41:02 +00:00
template . getTemplate ( 'payment-update' , qryRs [ 0 ] . countryCode , { userId : request . params . userId } , function ( tplRs , error ) {
2017-06-07 13:28:42 +00:00
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' } } ) ;
} ) ;
2017-05-30 06:06:14 +00:00
} ) ;
} ) ;
} ) ;
module . exports = router ;