From eab51e1b9d751df5779c46bb476581acd6a9de99 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 17 Oct 2017 08:22:59 +0200 Subject: [PATCH] Respuesta json en peticiones, auth, escrito impresoras --- services/auth/server/boot/routes.js | 9 +- services/mailer/application/auth.js | 10 +- services/mailer/application/locale.js | 6 +- services/mailer/application/mail.js | 17 ++- .../mailer/application/route/manuscript.js | 25 ++-- .../mailer/application/route/notification.js | 15 +- services/mailer/application/router.js | 2 +- services/mailer/application/template.js | 130 +++++++++++------- .../UNUSED/printer-setup/printer-setup.js | 41 ------ .../notification-alias/notification-alias.js | 4 +- .../template/payment-update/payment-update.js | 4 +- .../template/printer-setup/attachment.json | 1 + .../printer-setup/attachment/model.ezp | Bin 0 -> 9845 bytes .../{UNUSED => }/printer-setup/index.html | 45 +++++- .../{UNUSED => }/printer-setup/locale/es.json | 13 +- .../template/printer-setup/printer-setup.js | 23 ++++ services/mailer/server.js | 8 ++ 17 files changed, 203 insertions(+), 150 deletions(-) delete mode 100644 services/mailer/application/template/UNUSED/printer-setup/printer-setup.js create mode 100644 services/mailer/application/template/printer-setup/attachment.json create mode 100644 services/mailer/application/template/printer-setup/attachment/model.ezp rename services/mailer/application/template/{UNUSED => }/printer-setup/index.html (50%) rename services/mailer/application/template/{UNUSED => }/printer-setup/locale/es.json (60%) create mode 100644 services/mailer/application/template/printer-setup/printer-setup.js diff --git a/services/auth/server/boot/routes.js b/services/auth/server/boot/routes.js index 00165863dc..a0a303c67a 100644 --- a/services/auth/server/boot/routes.js +++ b/services/auth/server/boot/routes.js @@ -51,11 +51,11 @@ module.exports = function(app) { if (!loginUrl) loginUrl = applications.default; - res.send(JSON.stringify({ + res.json({ token: token.id, continue: continueUrl, loginUrl: loginUrl - })); + }); } function findCb(err, instance) { if (!instance || instance.password !== md5(password)) { @@ -76,13 +76,14 @@ module.exports = function(app) { } function badLogin() { res.status(401); - res.send(JSON.stringify({ + res.json({ message: 'Login failed' - })); + }); } }); app.get('/logout', function(req, res) { + console.log(req.accessToken); User.logout(req.accessToken.id, () => res.redirect('/')); }); diff --git a/services/mailer/application/auth.js b/services/mailer/application/auth.js index 11f8f0025a..4b954f8001 100644 --- a/services/mailer/application/auth.js +++ b/services/mailer/application/auth.js @@ -25,17 +25,13 @@ module.exports = { database.pool.query(query, [this.getToken()], (error, result) => { let token = result[0]; - if (error) - return this.response.status(401).send({status: 'REJECT', data: {message: error.code}}); - - if (result.length == 0) - return this.response.status(401).send({status: 'REJECT', data: {message: 'No token found'}}); + if (error || result.length == 0) + return this.response.status(401).send({message: 'Invalid token'}); if (this.isTokenExpired(token.created, token.ttl)) - return this.response.status(401).send({status: 'REJECT', data: {message: 'Token expired'}}); + return this.response.status(401).send({message: 'Token expired'}); this.request.userId = token.userId; - this.next(); }); }, diff --git a/services/mailer/application/locale.js b/services/mailer/application/locale.js index ac2cc8b0cd..496d48bb87 100644 --- a/services/mailer/application/locale.js +++ b/services/mailer/application/locale.js @@ -17,12 +17,12 @@ module.exports = { if (error) { fs.stat(defaultLocaleFile, (error, stats) => { if (error) - return cb({status: 'REJECT', data: {message: 'Translation not found for template ' + template + '.'}}); + return cb(new Error('Translation not found for template ' + template)); - cb({status: 'ACCEPT', data: {locale: require(defaultLocaleFile)}}); + cb(null, {locale: require(defaultLocaleFile)}); }); } else { - cb({status: 'ACCEPT', data: {locale: require(localeFile)}}); + cb(null, {locale: require(localeFile)}); } }); }, diff --git a/services/mailer/application/mail.js b/services/mailer/application/mail.js index 878595a5a5..5e3e6abb0c 100644 --- a/services/mailer/application/mail.js +++ b/services/mailer/application/mail.js @@ -50,12 +50,12 @@ module.exports = { this.log(params.sender, params.recipient, recipient, subject, body, params.message, status); if (error) - return cb({status: 'REJECT', data: {message: 'Email not sent: ' + error}}); + return cb(new Error('Email not sent: ' + error)); if (settings.app().debug) console.log('Mail sent ' + info.messageId + ' [' + info.response + ']'); - cb({status: 'ACCEPT', data: {message: 'Email sent'}}); + cb(); }); }, @@ -66,12 +66,15 @@ module.exports = { * @param {Object} cb - Callback */ sendWithTemplate: function(tplName, params, cb) { - template.get(tplName, params, result => { - if (result.status == 'REJECT') - return cb(result); + template.get(tplName, params, (error, result) => { + if (error) + return cb(error); - this.send(result.data.recipient, result.data.subject, result.data.body, result.data.attachments, params, result => { - cb(result); + this.send(result.recipient, result.subject, result.body, result.attachments, params, error => { + if (error) + return cb(error); + + cb(); }); }); }, diff --git a/services/mailer/application/route/manuscript.js b/services/mailer/application/route/manuscript.js index 1ec5984c17..d2d7392d4d 100644 --- a/services/mailer/application/route/manuscript.js +++ b/services/mailer/application/route/manuscript.js @@ -1,17 +1,24 @@ var express = require('express'); var router = new express.Router(); var mail = require('../mail.js'); -var auth = require('../auth.js'); - -// Auth middleware -var requestToken = function(request, response, next) { - auth.init(request, response, next); -}; // Payment method changes -router.post('/payment-update/:clientId', requestToken, function(request, response, next) { - mail.sendWithTemplate('payment-update', {recipient: request.params.clientId}, result => { - return response.json(result); +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(); }); }); diff --git a/services/mailer/application/route/notification.js b/services/mailer/application/route/notification.js index 508aed3868..e5d5e4bebd 100644 --- a/services/mailer/application/route/notification.js +++ b/services/mailer/application/route/notification.js @@ -3,12 +3,6 @@ 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) { @@ -71,7 +65,7 @@ var requestToken = function(request, response, next) { }); */ // Send notification to alias solunion on client deactivate -router.post('/client-deactivate/:clientId', requestToken, function(request, response) { +router.post('/client-deactivate/:clientId', function(request, response) { var params = { alias: 'solunion', code: 'clientDeactivate', @@ -80,8 +74,11 @@ router.post('/client-deactivate/:clientId', requestToken, function(request, resp } }; - mail.sendWithTemplate('notification-alias', params, result => { - return response.json(result); + mail.sendWithTemplate('notification-alias', params, error => { + if (error) + response.status(400).json({message: error.message}); + + return response.json(); }); }); diff --git a/services/mailer/application/router.js b/services/mailer/application/router.js index 2015486322..b51b8a195e 100644 --- a/services/mailer/application/router.js +++ b/services/mailer/application/router.js @@ -4,7 +4,7 @@ var settings = require('./settings.js'); // Mailer default page router.get('/', function(request, response) { - response.send(settings.app().name + ' v' + settings.app().version); + response.json({}); }); // Manuscripts diff --git a/services/mailer/application/template.js b/services/mailer/application/template.js index 4da1d7a80c..aebfbfd9fa 100644 --- a/services/mailer/application/template.js +++ b/services/mailer/application/template.js @@ -5,13 +5,13 @@ var path = require('path'); var inlineCss = require('inline-css'); module.exports = { - /** - * Obtiene la plantilla. - * @param {String} template - Nombre de la plantilla - * @param {Object} countryCode - Código del idioma - * @param {Object} params - Datos a reemplazar. - * @param {Object} cb - Callback - */ +/** + * Get template. + * @param {String} template - Template name + * @param {Object} countryCode - Language code + * @param {Object} params - Params + * @param {Object} cb - Callback + */ get: function(template, params, cb) { var templatePath = path.join(__dirname, 'template', `${template}`, `index.html`); var classPath = path.join(__dirname, 'template', `${template}`, `${template}.js`); @@ -19,65 +19,68 @@ module.exports = { fs.stat(templatePath, (error, stat) => { if (error) - return cb(null, 'Template ' + template + ' not found'); + return cb(new Error('Template ' + template + ' not found')); let TemplateClass = require(classPath); let instance = new TemplateClass(); let getRenderedStyles = body => { - this.renderStyles(stylePath, body, body => { + this.renderStyles(stylePath, body, (error, body) => { params.subject = params.subject || instance.subject; if (params.subject == undefined) params.subject = body.match(new RegExp('(.*?)', 'i'))[1]; - this.getAttachments(template, body, attachments => { - cb({status: 'ACCEPT', data: {recipient: instance.recipient, subject: params.subject, body: body, attachments: attachments}}); + this.getAttachments(template, body, (error, attachments) => { + if (error) + return cb(error); + + cb(null, {recipient: instance.recipient, subject: params.subject, body: body, attachments: attachments}); }); }); }; let getDataCb = () => { - this.render(templatePath, instance, body => getRenderedStyles(body)); + this.render(templatePath, instance, (error, result) => getRenderedStyles(result)); }; - instance.getData(params, result => { - if (result.status == 'REJECT') - return cb(result); + instance.getData(params, (error, result) => { + if (error) + return cb(error); - locale.load(template, instance.countryCode, result => { - if (result.status == 'REJECT') - return cb(result); + locale.load(template, instance.countryCode, (error, result) => { + if (error) + return cb(error); - instance._ = result.data.locale; - getDataCb(result); + instance._ = result.locale; + getDataCb(null, result); }); }); }); }, - /** - * Renderiza las plantillas - * @param {String} path - Ruta de la plantilla - * @param {Object} data - Listado de parámetros a remplazar - * @param {Object} cb - Callback - */ +/** + * Render template + * @param {String} path - Template path + * @param {Object} data - Params + * @param {Object} cb - Callback + */ render: function(path, data, cb) { fs.readFile(path, 'utf8', function(error, body) { mustache.parse(body); - cb(mustache.render(body, data)); + cb(null, mustache.render(body, data)); }); }, - /** - * Renderiza los estilos de las plantillas. - * @param {String} path - Ruta de la hoja de estilos - * @param {String} body - Html renderizado - * @param {Object} cb - Callback - */ +/** + * Render template style. + * @param {String} path - Stylesheet path + * @param {String} body - Rendered html + * @param {Object} cb - Callback + */ renderStyles: function(path, html, cb) { fs.stat(path, error => { - if (error) return cb(null, 'Template stylesheet not found'); + if (error) return cb(new Error('Template stylesheet not found')); fs.readFile(path, 'utf8', (error, css) => { let style = ''; let body = style + html; @@ -85,42 +88,67 @@ module.exports = { inlineCss(body, options) .then(function(body) { - cb(body); + cb(null, body); }); }); }); }, - /** - * Obtiene todos los ficheros adjuntos de la plantilla - * @param {String} template - Nombre de la plantilla - * @param {String} body - html de la plantilla - * @param {Object} cb - Callback - */ +/** + * Get template attachments + * @param {String} template - Template name + * @param {String} body - template body + * @param {Object} cb - Callback + */ getAttachments: function(template, body, cb) { - var attachments = []; - var tplAttachments = body.match(new RegExp('src="cid:(.*?)"', 'ig')); + let attachments = []; + let tplAttachments = body.match(new RegExp('src="cid:(.*?)"', 'ig')); + // Template default attachments for (var i = 0; i < tplAttachments.length; i++) { - var name = tplAttachments[i].replace('src="cid:', '').replace('"', ''); - var attachmentPath = path.join(__dirname, 'template/default/image', name); + let name = tplAttachments[i].replace('src="cid:', '').replace('"', ''); + let attachmentPath = path.join(__dirname, 'template/default/image', name); attachments.push({filename: name, path: attachmentPath, cid: name}); } - var attachmentsPath = path.join(__dirname, 'template', `${template}`, 'attachment.json'); + // Template attachment files + let attachmentsPath = path.join(__dirname, 'template', `${template}`, 'attachment.json'); fs.stat(attachmentsPath, (error, stats) => { - if (error) return cb(null, 'Could not load attachments from template ' + template); + if (error) + return cb(new Error(`Could not load attachments.js from template ${template}`)); - var attachObj = require(attachmentsPath); + let attachObj = require(attachmentsPath); for (var i = 0; i < attachObj.length; i++) { - var attachmentPath = path.join(__dirname, 'template', `${template}`, 'attachment', attachObj[i]); - attachments.push({filename: attachObj[i], path: attachmentPath, cid: attachObj[i]}); + let filename = attachObj[i]; + let attachmentPath = path.join(__dirname, 'template', `${template}`, 'attachment', filename); + + attachments.push({filename: filename, path: attachmentPath, cid: filename}); } - cb(attachments); + this.checkAttachments(attachments, error => { + if (error) + return cb(error); + cb(null, attachments); + }); }); + }, + +/** + * Check all template attachments + * @param {Object} attachments - Attachments object + * @param {Object} cb - Callback + */ + checkAttachments: function(attachments, cb) { + for (var i = 0; i < attachments.length; i++) { + var attachment = attachments[i]; + fs.stat(attachment.path, error => { + if (error) + return cb(new Error(`Could not load attachment file ${attachment.path}`)); + }); + } + cb(); } }; diff --git a/services/mailer/application/template/UNUSED/printer-setup/printer-setup.js b/services/mailer/application/template/UNUSED/printer-setup/printer-setup.js deleted file mode 100644 index 73fdb89c1b..0000000000 --- a/services/mailer/application/template/UNUSED/printer-setup/printer-setup.js +++ /dev/null @@ -1,41 +0,0 @@ -var path = require('path'); -var database = require(path.join(__dirname, '../../database.js')); -var format = require(path.join(__dirname, '../../util/format.js')); - -module.exports = class PaymentUpdate { - getData(params, cb) { - let query = `SELECT - pm.id payMethodFk, - pm.name payMethodName, - c.dueDay, - c.iban, - LOWER(ct.code) countryCode, - c.email recipient - FROM client c - JOIN payMethod pm ON pm.id = c.paymentMethodFk - JOIN country ct ON ct.id = c.countryFk - WHERE c.id = ?`; - database.pool.query(query, [params.recipient], (error, result) => { - if (error || result.length == 0) - return cb({status: 'REJECT', data: {message: 'No data found', error: error}}); - - Object.assign(this, result[0]); - cb({status: 'ACCEPT', data: {}}); - }); - } - - get paymentDay() { - if (this.payMethodFk != 5) { - return `
${this._.paymentDay}: ${this.dueDay} ${this._.everyMonth}
`; - } - } - - get paymentAdvice() { - switch (this.payMethodFk) { - case 4: - return `${this._.accountPaymentAdviceBefore} ${format.partialAccountAddress(this.iban)} ${this._.accountPaymentAdviceAfter}`; - case 5: - return this._.cardPaymentAdvice; - } - } -}; diff --git a/services/mailer/application/template/notification-alias/notification-alias.js b/services/mailer/application/template/notification-alias/notification-alias.js index 132d037f41..937e1bf8c6 100644 --- a/services/mailer/application/template/notification-alias/notification-alias.js +++ b/services/mailer/application/template/notification-alias/notification-alias.js @@ -12,10 +12,10 @@ module.exports = class NotificationAlias { database.pool.query(query, [params.alias], (error, result) => { if (error || result.length == 0) - return cb({status: 'REJECT', data: {message: 'No data found', error: error}}); + return cb(new Error('No template data found')); Object.assign(this, result[0]); - cb({status: 'ACCEPT', data: {}}); + cb(); }); } diff --git a/services/mailer/application/template/payment-update/payment-update.js b/services/mailer/application/template/payment-update/payment-update.js index 73fdb89c1b..0dbb697980 100644 --- a/services/mailer/application/template/payment-update/payment-update.js +++ b/services/mailer/application/template/payment-update/payment-update.js @@ -17,10 +17,10 @@ module.exports = class PaymentUpdate { WHERE c.id = ?`; database.pool.query(query, [params.recipient], (error, result) => { if (error || result.length == 0) - return cb({status: 'REJECT', data: {message: 'No data found', error: error}}); + return cb(new Error('No template data found')); Object.assign(this, result[0]); - cb({status: 'ACCEPT', data: {}}); + cb(); }); } diff --git a/services/mailer/application/template/printer-setup/attachment.json b/services/mailer/application/template/printer-setup/attachment.json new file mode 100644 index 0000000000..7294783a82 --- /dev/null +++ b/services/mailer/application/template/printer-setup/attachment.json @@ -0,0 +1 @@ +["model.ezp"] \ No newline at end of file diff --git a/services/mailer/application/template/printer-setup/attachment/model.ezp b/services/mailer/application/template/printer-setup/attachment/model.ezp new file mode 100644 index 0000000000000000000000000000000000000000..297df3d214694a64f677aa40d7305ebddb368e28 GIT binary patch literal 9845 zcmeHNe@s=^9sfSKh9||2*4nYk*jse!?10BFM@dJ#3i`0vpitY_kSLZ%eeHwygm-;t z-J%gKNm*tS(`n`!+ib0!u32a6m?If!OGe*lW?J2xVv8HiY(kr?-5+dg_xAbRdkGqLA|nOmjm%q3S;iwKVX~9rJ2ct`=DvXbk6pPdZ8X zCnhhSgbjR{ygPF9yt(<_ydqCtK}q4VlKf@TWXpXUTa~J5TOciFojwVSQ7C(5%OiWG z8@chxnakL`jt^LQ@fkWntLHflI=INIF?af-?ePV#r4-{iUjH~n3!q*MCi$yF;mvg+ zi=J%Ti0mqbi|YcvMHJ?H>ISP!HR$$6j0&`q$d<+yvD&de#U;s->TsPc!zET+##TT& zkx1~z92ac=N=N(GPtg9fXCE*^F$M|!R5b^iqJd^lbs%a)kjE|H6=KX^nB_J5?lOG2 z!6T>~S|KMaK;c*;e+_;(&S|goK$^fh^#}^f?IPcR0L^Ivb=sF2k_mj^ygS+VwoiWW zOs>{Bf1kFYCs(@-^oz*lFfe6vq1Oi74_rl#9#`WD;?FY`sT{`R+q7ZiAT|<5_ zt4cP#7B`0`c{?zX(tq!ho+tc+u#K2s@gGLp=&T;s`EV+KwvpK&=FO=*hrAthZ9q5bQF@KIPJIsw zeGzIQCq2SPuE)X4eMmQQAU^_{`pRa}7Tt`=dKY9L1mV|yKKkGyPb@5e%h1^aU#x47 zY?H@qds7Hr>BE+NH}kp6743{tBr%-f5jYsZKkw<^jxHx#&%uEhKhu^|Az=R{f{1#R@k#`rqe~FnN z@tzy4wS;quG;MA=kge5cB$9so*TvdTQ7CIe{lwRnYQ2!hf!{!hUcmbun0^ROUjxv~ z%E{3<2l>6NAPqME*z7krhnzCnzJBafztUqp6S~DHTuaOxK&$mOh`B|36>}kI=Q^SM zTu(t~aBZZ$fx`9~n-~3&w;wj{%-=*w6I7oKfqw+09K21(_L{QO z&+j$k(eD~NudhRL6ggPXV(PNKuV8EJC6v|g*KA9_gndSG3shRn{ZS$09PixMFi!zK zgZC;UlGA7P&*5qGS1e#bKAO547hZ!oySQ$7dm zd(=&7y^BKu|;!#@w53}Z5DDI22EY&@Xk{?no9jW(0l|{zYTOoHrfz5 z9e~Y)6)pK*>>X?IKCXG;tT`5_d*h2+V`?p-e-FwUX^=MP5!~jl$k2(>kysZ~d^wj- zjJ$5ln7y_>ea25(xts&9 zzt8RsHr0n?o|-^wbkg5^v{yxCyvQba@7owLk4cqiYPjYe&nkUwMP-FPt{=6pWbl}6DrOOK7;vT##@KD_b16O&?L0&P)d+}V2 zH`86eP9*VOjj9>8JxB{aWB#LNb5g$mPi62+*X5y5Fw(+ay%HvB2WOwtf$F#x@hD${^P@h<(oydM&cvC5eiZkL>%&G<{rbQI7z)(o z`5%z*UTyBN+>tX2=5o6%HqS_Svf+~Q%F2qW>he769E0+S`i1F#YrUXN0OhlFWS+z=itNH7ir+hXkVE3nI7=e{Zb+5E60v?FU__Z>5F_Z?e25f zML>^tzr>C-I}?~d-;70^1e+`SVrsFbvoC_kch%>yFAA<>UrZv_boa$6^vCCJUKCz^ zUm*Rd&5KFI;@GW2;appHPx*S@5b=Moc<%jZ74Gr?wKy}RydRk7%=7Gf*bi|JTh`<^ O)c;>mciLg9iT)e;UnVyI literal 0 HcmV?d00001 diff --git a/services/mailer/application/template/UNUSED/printer-setup/index.html b/services/mailer/application/template/printer-setup/index.html similarity index 50% rename from services/mailer/application/template/UNUSED/printer-setup/index.html rename to services/mailer/application/template/printer-setup/index.html index caec77e903..86ae8e31a5 100644 --- a/services/mailer/application/template/UNUSED/printer-setup/index.html +++ b/services/mailer/application/template/printer-setup/index.html @@ -23,12 +23,49 @@

{{_.dear}},

{{_.bodyDescription}}

+

-

{{_.paymentMethod}}: {{payMethodName}}
- {{{paymentDay}}} + Puede utilizar como guía, el video del montaje del ribon y la cinta https://www.youtube.com/watch?v=qhb0kgQF3o8. + También necesitará el QLabel, el programa para imprimir las cintas.

+ +

Puede descargarlo desde este enlace http://www.godexintl.com/en/product/type/Download/2967

+ +

Utilización de QLabel

+ +

Para utilizar el programa de impresión de cintas siga estos pasos:

+ +
    +
  1. Abra el programa QLabel.
  2. +
  3. Haga click en el icono de la carpeta.
  4. +
  5. Seleccione el archivo plantilla llamado "MODEL.ezp".
  6. +
  7. Haga click ENCIMA DEL TEXTO con el boton secundario del ratÓn.
  8. +
  9. Elija la primera opcion "SETUP".
  10. +
  11. Cambie el texto para imprimir.
  12. +
  13. Haga click en el boton OK.
  14. +
  15. Desplácese con el raton para ver la medida máxima.
  16. +
  17. Haga click ENCIMA DEL TEXTO con el boton secundario del raton.
  18. +
  19. Elija la primera opcion "SETUP PRINTER".
  20. +
  21. Haga click en la primera pestalla "Label Setup".
  22. +
  23. Y modifique la propidad "Paper Height".
  24. +
  25. Haga click en el boton OK.
  26. +
  27. Haga click sobre el icono de la impresora.
  28. +
  29. Haga click en "Print".
  30. +
+ +

¿Necesita ayuda?

+ +

Si necesita ayuda, descárguese nuestro programa de soporte para poder conectarnos remotamente a su pc y hacerle la instalación. + Proporciónenos un horario de contacto para atenderle, y contactaremos con usted.

+ +

Puede descargarse el programa desde este enlace http://soporte.verdnatura.es

+ +

+

Soy tu comercial y mi nombre es: {{_.salesPersonName}}
+
Teléfono y whatsapp: {salesMan_phone}
+

-

{{paymentAdvice}}

-

{{_.notifyError}}

+ +
diff --git a/services/mailer/application/template/UNUSED/printer-setup/locale/es.json b/services/mailer/application/template/printer-setup/locale/es.json similarity index 60% rename from services/mailer/application/template/UNUSED/printer-setup/locale/es.json rename to services/mailer/application/template/printer-setup/locale/es.json index 144cdc3464..a856dd8276 100644 --- a/services/mailer/application/template/UNUSED/printer-setup/locale/es.json +++ b/services/mailer/application/template/printer-setup/locale/es.json @@ -1,15 +1,8 @@ { - "subject": "Cambios en las condiciones de pago", - "title": "Cambio en las condiciones", + "subject": "Instalación y configuración de impresora", + "title": "¡GRACIAS POR SU CONFIANZA!", "dear": "Estimado cliente", - "bodyDescription": "Le informamos que han cambiado las condiciones de pago de su cuenta. A continuación le indicamos las nuevas condiciones:", - "paymentMethod": "Método de pago", - "paymentDay": "Día de pago", - "everyMonth": "de cada mes", - "cardPaymentAdvice": "Su modo de pago actual implica que deberá abonar el importe de los pedidos realizados en el mismo día para que se puedan enviar.", - "accountPaymentAdviceBefore": "Su modo de pago actual implica que se le pasará un cargo a la cuenta", - "accountPaymentAdviceAfter": "por el importe pendiente, al vencimiento establecido en las condiciones.", - "notifyError": "En el caso de detectar algún error en los datos indicados o para cualquier aclaración, debe dirigirse a su comercial.", + "bodyDescription": "Siga las intrucciones especificadas en este correo para llevar a cabo la instalación de la impresora.", "actionButton": "Visita nuestra Web", "infoButton": "Ayúdanos a mejorar", "fiscalAddress": "VERDNATURA LEVANTE SL, B97367486 Avda. Espioca, 100, 46460 Silla _ www.verdnatura.es _ clientes@verdnatura.es", diff --git a/services/mailer/application/template/printer-setup/printer-setup.js b/services/mailer/application/template/printer-setup/printer-setup.js new file mode 100644 index 0000000000..c8b25ffed5 --- /dev/null +++ b/services/mailer/application/template/printer-setup/printer-setup.js @@ -0,0 +1,23 @@ +var path = require('path'); +var database = require(path.join(__dirname, '../../database.js')); +var format = require(path.join(__dirname, '../../util/format.js')); + +module.exports = class PaymentUpdate { + getData(params, cb) { + let query = `SELECT + CONCAT(w.name, ' ', w.firstName) salesPersonName, + LOWER(ct.code) countryCode, + c.email recipient + FROM client c + LEFT JOIN worker w ON w.id = c.workerFk + JOIN country ct ON ct.id = c.countryFk + WHERE c.id = ?`; + database.pool.query(query, [params.recipient], (error, result) => { + if (error || result.length == 0) + return cb(new Error('No template data found')); + + Object.assign(this, result[0]); + cb(); + }); + } +}; diff --git a/services/mailer/server.js b/services/mailer/server.js index dc93e525b9..63a7c1596b 100644 --- a/services/mailer/server.js +++ b/services/mailer/server.js @@ -7,11 +7,19 @@ var bodyParser = require('body-parser'); var settings = require('./application/settings.js'); var mail = require('./application/mail.js'); var database = require('./application/database.js'); +var auth = require('./application/auth.js'); // Body parser middleware app.use(bodyParser.json()); app.use(bodyParser.urlencoded({extended: true})); +// Auth middleware +var requestToken = function(request, response, next) { + auth.init(request, response, next); +}; + +app.use(requestToken); + // Load routes app.use('/', require('./application/router.js'));