diff --git a/client/client/src/address-edit/address-edit.html b/client/client/src/address-edit/address-edit.html index c4fbf229a..72c6b4136 100644 --- a/client/client/src/address-edit/address-edit.html +++ b/client/client/src/address-edit/address-edit.html @@ -1,6 +1,6 @@ + - - {{$parent.$parent.item.name}} {{$parent.$parent.item.surname}} - { - this.canChangePassword = (res.data && res.data.length) ? res.data[0].isCustomer : false; + this.canChangePassword = (res.data) ? res.data.isCustomer : false; }); } else { this.canChangePassword = false; diff --git a/client/core/src/watcher/watcher.js b/client/core/src/watcher/watcher.js index cf50c205a..3ee1b5d4e 100644 --- a/client/core/src/watcher/watcher.js +++ b/client/core/src/watcher/watcher.js @@ -25,8 +25,10 @@ export default class Watcher extends Component { this.copyData(); } $onInit() { - if (this.get) { + if (this.get && this.url) { this.fetchData(); + } else if (this.get && !this.url) { + throw new Error('Error: Parameter url ommitted'); } } $onChanges(changes) { @@ -39,12 +41,15 @@ export default class Watcher extends Component { } fetchData() { let id = this.data[this.idField]; - return new Promise((resolve, reject) => { - this.$http.get(`${this.url}/${id}`).then( - json => this.writeData(json, resolve), - json => reject(json) - ); - }); + // return new Promise((resolve, reject) => { + this.$http.get(`${this.url}/${id}`).then( + json => { + this.data = this.copyObject(json.data); + this.copyData(); + } + // json => reject(json) + ); + // }); } /** * Submits the data and goes back in the history. diff --git a/services/client/common/methods/client/activate.js b/services/client/common/methods/client/activate.js index 69342a937..664e05d20 100644 --- a/services/client/common/methods/client/activate.js +++ b/services/client/common/methods/client/activate.js @@ -1,13 +1,24 @@ +var request = require('request'); +var app = require('../../../server/server'); + module.exports = function(Client) { Client.remoteMethod('activate', { description: 'Activate or deactive client', - accepts: { - arg: 'id', - type: 'number', - required: true, - description: 'Model id', - http: {source: 'path'} - }, + accepts: [ + { + arg: 'id', + type: 'number', + required: true, + description: 'Model id', + http: {source: 'path'} + }, { + arg: 'context', + type: 'object', + http: function(ctx) { + return ctx; + } + } + ], returns: { arg: 'active', type: 'boolean' @@ -18,10 +29,31 @@ module.exports = function(Client) { } }); - Client.activate = function(id, cb) { + Client.activate = function(id, ctx, cb) { Client.findById(id, function(err, client) { - if (!err) { - Client.update({id: client.id}, {active: !client.active}); + if(!err) { + Client.update({id: client.id}, {active: !client.active}); + + let filter = {where: {clientFk: client.id}, fields: ['started', 'ended']}; + + app.models.CreditClassification.findOne(filter, function(err, data) { + let currentDate = new Date(); + + if (client.active && data.ended >= currentDate) { + let host = ctx.req.headers.host.split(':')[0]; + var options = { + url: `http://${host}:5000/mailer/notification/client-deactivate/${client.id}`, + method: 'POST', + headers: { + 'content-type': 'application/json', + 'authorization': ctx.req.headers.authorization + }, + json: {} + }; + request(options); + } + }); + cb(null, !client.active); } }); diff --git a/services/client/common/methods/client/card.js b/services/client/common/methods/client/card.js index c3ed18fd1..752f7ce6a 100644 --- a/services/client/common/methods/client/card.js +++ b/services/client/common/methods/client/card.js @@ -29,8 +29,17 @@ module.exports = function(Client) { Client.find(filter, function(err, instances) { if (!err) { - cb(null, instances[0]); + cb(null, formatCard(instances[0])); } }); }; + + function formatCard(card) { + let cardFormated = JSON.parse(JSON.stringify(card)); + cardFormated.salesPerson = { + id: card.salesPerson().id, + name: `${card.salesPerson().name} ${card.salesPerson().surname}` + }; + return cardFormated; + } }; diff --git a/services/client/common/methods/client/card.json b/services/client/common/methods/client/card.json index 05b86ea6f..e9224b2ab 100644 --- a/services/client/common/methods/client/card.json +++ b/services/client/common/methods/client/card.json @@ -2,7 +2,7 @@ { "relation": "salesPerson", "scope": { - "fields": ["id", "name"] + "fields": ["id", "name", "surname"] } }, { "relation": "contactChannel", diff --git a/services/client/common/methods/client/roles.js b/services/client/common/methods/client/roles.js index 74b41e641..1e8a1f475 100644 --- a/services/client/common/methods/client/roles.js +++ b/services/client/common/methods/client/roles.js @@ -22,7 +22,7 @@ module.exports = Client => { ], returns: { arg: 'data', - type: Boolean, + type: 'boolean', root: true }, http: { @@ -36,7 +36,7 @@ module.exports = Client => { const params = [id]; Client.rawSql(query, params, callback) .then(response => { - callback(null, response); + callback(null, response[0]); }) .catch(reject => { callback(reject, null); diff --git a/services/client/common/methods/client/salesperson.js b/services/client/common/methods/client/salesperson.js index 30df4229e..6b493f996 100644 --- a/services/client/common/methods/client/salesperson.js +++ b/services/client/common/methods/client/salesperson.js @@ -2,7 +2,6 @@ module.exports = (Client) => { Client.remoteMethod('activeSalesPerson', { description: 'returns actives employees with salesperson role', accessType: 'READ', - isStatic: true, accepts: [{ arg: 'filter', type: 'Object', @@ -26,16 +25,17 @@ module.exports = (Client) => { let limit = filter.limit || 10; let where = getCondition(filter.where); - let query = `SELECT em.id, em.name, em.surname FROM Employee em + let query = `SELECT em.id, em.name, em.surname + FROM Employee em JOIN Account ac ON em.userFk = ac.id JOIN Role ON Role.id = ac.roleFK WHERE ac.active AND Role.\`name\`='salesPerson' ${where} ORDER BY em.name ASC LIMIT ${limit} OFFSET ${skip}`; - + Client.rawSql(query, [], callback) .then(response => { - callback(null, response); + callback(null, formatSalesPerson(response)); }) .catch(reject => { callback(reject, null); @@ -44,19 +44,36 @@ module.exports = (Client) => { function getCondition(where) { let out = []; - if(typeof where === 'object') { Object.keys(where).forEach((k) => { let value = where[k]; - if(typeof value !== 'object') { + if (typeof value === 'number') { + out.push(`em.${k}=${value}`); + } else if (typeof value === 'string') { out.push(`em.${k}='${value}'`); - } else { + } else if (typeof value === 'boolean' || value === null) { + out.push(`em.${k} IS ${String(value).toUpperCase()}`); + } else if (Object.keys(value).length) { let firstProperty = Object.keys(value)[0]; out.push(`em.${k} ${firstProperty} '${value[firstProperty]}'`); + } else { + throw new Error ('Error: unexpected type'); } }); } + return out.length ? `AND (${out.join(' AND ')})` : ''; + } - return out.length ? 'AND ' + out.join(' AND ') : ''; + function formatSalesPerson (response) { + let results = []; + + response.forEach( person => { + results.push({ + id: person.id, + name: `${person.name} ${person.surname}` + }); + }); + + return results; } }; \ No newline at end of file diff --git a/services/client/common/models/address.js b/services/client/common/models/address.js index b72618112..c9bcfb0d8 100644 --- a/services/client/common/models/address.js +++ b/services/client/common/models/address.js @@ -22,6 +22,18 @@ module.exports = function(Address) { getAddress(ctx, data, next); }); + Address.beforeRemote('findById', function(ctx, modelInstance, next) { + ctx.args.filter = { + "include": { + "relation": "province", + "scope": { + "fields": ["id", "name"] + } + } + }; + next(); + }); + function getAddress(ctx, data, next){ var address = Address.findOne( {where: { id: data.id}}, function (err, address){ if(address) diff --git a/services/client/common/models/credit-classification.json b/services/client/common/models/credit-classification.json new file mode 100644 index 000000000..e972d5908 --- /dev/null +++ b/services/client/common/models/credit-classification.json @@ -0,0 +1,40 @@ +{ + "name": "CreditClassification", + "description": "Clientes clasificados.", + "base": "MyModel", + "validateUpsert": true, + "properties": { + "id": { + "id": true, + "type": "Number", + "description": "Identifier" + }, + "started": { + "type": "date" + }, + "ended": { + "type": "date" + } + }, + "relations": { + "client": { + "type": "belongsTo", + "model": "Client", + "foreignKey": "clientFk" + } + }, + "acls": [ + { + "accessType": "*", + "principalType": "ROLE", + "principalId": "$everyone", + "permission": "DENY" + }, + { + "accessType": "*", + "principalType": "ROLE", + "principalId": "root", + "permission": "ALLOW" + } + ] +} \ No newline at end of file diff --git a/services/client/server/model-config.json b/services/client/server/model-config.json index 7a1565916..6de494d1a 100644 --- a/services/client/server/model-config.json +++ b/services/client/server/model-config.json @@ -74,5 +74,8 @@ }, "Employee": { "dataSource": "vn" + }, + "CreditClassification": { + "dataSource": "vn" } } diff --git a/services/mailer/application/auth.js b/services/mailer/application/auth.js new file mode 100644 index 000000000..11f8f0025 --- /dev/null +++ b/services/mailer/application/auth.js @@ -0,0 +1,66 @@ +var database = require('./database.js'); + +module.exports = { + +/** + * Initialize auth + * @param {Object} request - Request object + * @param {Object} response - Response object + * @param {Object} next - Next object + */ + init: function(request, response, next) { + this.request = request; + this.response = response; + this.next = next; + + this.validateToken(); + }, + +/** + * Validate auth token + */ + validateToken: function() { + let query = 'SELECT userId, ttl, created FROM salix.AccessToken WHERE id = ?'; + + 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 (this.isTokenExpired(token.created, token.ttl)) + return this.response.status(401).send({status: 'REJECT', data: {message: 'Token expired'}}); + + this.request.userId = token.userId; + + this.next(); + }); + }, + +/** + * Get request token + * @return {String} Token + */ + getToken: function() { + return this.request.headers.authorization; + }, + +/** + * Checks if the token has expired + * @param {String} created - Creation date + * @param {Integer} ttl - Ttl seconds + * @return {Boolean} True if the token has expired + */ + isTokenExpired: function(created, ttl) { + let date = new Date(created); + let currentDate = new Date(); + + date.setSeconds(date.getSeconds() + ttl); + + if (currentDate > date) + return true; + } +}; diff --git a/services/mailer/application/config/smtp.json b/services/mailer/application/config/smtp.json index e4953c14d..db98587f2 100644 --- a/services/mailer/application/config/smtp.json +++ b/services/mailer/application/config/smtp.json @@ -3,10 +3,12 @@ "port": 465, "secure": true, "auth": { + "id": 10240, "user": "noreply", "pass": "" }, "tls": { "rejectUnauthorized": false - } + }, + "pool": true } \ No newline at end of file diff --git a/services/mailer/application/locale.js b/services/mailer/application/locale.js index b4a4dd94a..ac2cc8b0c 100644 --- a/services/mailer/application/locale.js +++ b/services/mailer/application/locale.js @@ -3,12 +3,12 @@ var settings = require('./settings.js'); var path = require('path'); module.exports = { - /** - * Returns template locale - * @param {String} template - Template name - * @param {String} countryCode - Language code - * @param {Object} cb - Callback - */ +/** + * Returns template locale + * @param {String} template - Template name + * @param {String} countryCode - Language code + * @param {Object} cb - Callback + */ load: function(template, countryCode, cb) { var localeFile = path.join(__dirname, 'template', `${template}`, 'locale', `${countryCode}.json`); var defaultLocaleFile = path.join(__dirname, 'template', `${template}`, 'locale', `${settings.app().defaultLanguage}.json`); @@ -25,5 +25,18 @@ module.exports = { cb({status: 'ACCEPT', data: {locale: require(localeFile)}}); } }); + }, + +/** + * Parse locale text + * @param {String} text - Locale text + * @param {Object} params - Locale params + * @return {String} - Returns parsed text + */ + parseText: function(text, params) { + for (var key in params) { + text = text.replace(`%${key}%`, params[key]); + } + return text; } }; diff --git a/services/mailer/application/route/notification.js b/services/mailer/application/route/notification.js index 13108dcd6..acab692df 100644 --- a/services/mailer/application/route/notification.js +++ b/services/mailer/application/route/notification.js @@ -2,9 +2,9 @@ var express = require('express'); var router = new express.Router(); var mail = require('../mail.js'); var database = require('../database.js'); - +var settings = require('../settings.js'); // Single user notification -router.post('/:recipient/noticeUserSend', function(request, response) { +/* router.post('/:recipient/noticeUserSend', function(request, response) { var params = { recipient: request.params.recipient, sender: request.body.sender, @@ -21,14 +21,14 @@ router.post('/:recipient/noticeUserSend', function(request, response) { WHERE c.keyName = ? AND s.userFk = ?`; database.pool.query(query, [params.category, params.recipient, params.sender], (error, result) => { - mail.sendWithTemplate('notice', params, result => { + mail.sendWithTemplate('notification-notice', params, result => { return response.json(result); }); }); -}); +}); */ // Send notification to all user subscribed to category -router.post('/:category/noticeCategorySend', function(request, response) { +/* router.post('/:category/noticeCategorySend', function(request, response) { var params = { sender: request.body.sender, category: request.params.category, @@ -42,23 +42,38 @@ router.post('/:category/noticeCategorySend', function(request, response) { result.forEach(function(user) { params.recipient = user.id; - mail.sendWithTemplate('notice', params, result => { + mail.sendWithTemplate('notification-notice', params, result => { return response.json(result); }); }, this); }); -}); +}); */ // Send system notification -router.post('/:recipient/noticeSystemSend', function(request, response) { +/* router.post('/:recipient/noticeSystemSend', function(request, response) { var params = { recipient: request.params.recipient, - sender: 50069, // verdnatura + sender: settings.smtp().auth.id, category: request.body.category, message: request.body.message }; - mail.sendWithTemplate('notice', params, result => { + 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 => { return response.json(result); }); }); diff --git a/services/mailer/application/template.js b/services/mailer/application/template.js index 6099846ff..4da1d7a80 100644 --- a/services/mailer/application/template.js +++ b/services/mailer/application/template.js @@ -13,9 +13,9 @@ module.exports = { * @param {Object} cb - Callback */ get: function(template, params, cb) { - var templatePath = path.join(__dirname, 'template', `${template}`, `${template}.html`); + var templatePath = path.join(__dirname, 'template', `${template}`, `index.html`); var classPath = path.join(__dirname, 'template', `${template}`, `${template}.js`); - var stylePath = path.join(__dirname, 'template', `${template}`, `${template}.css`); + var stylePath = path.join(__dirname, 'template', `default`, `style.css`); fs.stat(templatePath, (error, stat) => { if (error) @@ -26,9 +26,13 @@ module.exports = { let getRenderedStyles = body => { this.renderStyles(stylePath, body, body => { - var titleSubject = body.match(new RegExp('(.*?)', 'i'))[1]; + 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: titleSubject, body: body, attachments: attachments}}); + cb({status: 'ACCEPT', data: {recipient: instance.recipient, subject: params.subject, body: body, attachments: attachments}}); }); }); }; @@ -99,7 +103,7 @@ module.exports = { for (var i = 0; i < tplAttachments.length; i++) { var name = tplAttachments[i].replace('src="cid:', '').replace('"', ''); - var attachmentPath = path.join(__dirname, 'template/image', name); + var attachmentPath = path.join(__dirname, 'template/default/image', name); attachments.push({filename: name, path: attachmentPath, cid: name}); } diff --git a/services/mailer/application/template/payment-update/payment-update.html b/services/mailer/application/template/UNUSED/printer-setup/index.html similarity index 100% rename from services/mailer/application/template/payment-update/payment-update.html rename to services/mailer/application/template/UNUSED/printer-setup/index.html diff --git a/services/mailer/application/template/UNUSED/printer-setup/locale/es.json b/services/mailer/application/template/UNUSED/printer-setup/locale/es.json new file mode 100644 index 000000000..144cdc346 --- /dev/null +++ b/services/mailer/application/template/UNUSED/printer-setup/locale/es.json @@ -0,0 +1,18 @@ +{ + "subject": "Cambios en las condiciones de pago", + "title": "Cambio en las condiciones", + "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.", + "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", + "privacy": "- AVISO - Este mensaje es privado y confidencial, y debe ser utilizado exclusivamente por la persona destinataria del mismo. Si usted ha recibido este mensaje por error, le rogamos lo comunique al remitente y borre dicho mensaje y cualquier documento adjunto que pudiera contener. Verdnatura Levante SL no renuncia a la confidencialidad ni a ningún privilegio por causa de transmisión errónea o mal funcionamiento. Igualmente no se hace responsable de los cambios, alteraciones, errores u omisiones que pudieran hacerse al mensaje una vez enviado.", + "privacyLaw": "En cumplimiento de lo dispuesto en la Ley Orgánica 15/1999, de Protección de Datos de Carácter Personal, le comunicamos que los datos personales que facilite se incluirán en ficheros automatizados de VERDNATURA LEVANTE S.L., pudiendo en todo momento ejercitar los derechos de acceso, rectificación, cancelación y oposición, comunicándolo por escrito al domicilio social de la entidad. La finalidad del fichero es la gestión administrativa, contabilidad, y facturación." +} \ No newline at end of file diff --git a/services/mailer/application/template/UNUSED/printer-setup/printer-setup.js b/services/mailer/application/template/UNUSED/printer-setup/printer-setup.js new file mode 100644 index 000000000..73fdb89c1 --- /dev/null +++ b/services/mailer/application/template/UNUSED/printer-setup/printer-setup.js @@ -0,0 +1,41 @@ +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/image/action.png b/services/mailer/application/template/default/image/action.png similarity index 100% rename from services/mailer/application/template/image/action.png rename to services/mailer/application/template/default/image/action.png diff --git a/services/mailer/application/template/image/facebook.png b/services/mailer/application/template/default/image/facebook.png similarity index 100% rename from services/mailer/application/template/image/facebook.png rename to services/mailer/application/template/default/image/facebook.png diff --git a/services/mailer/application/template/image/header.png b/services/mailer/application/template/default/image/header.png similarity index 100% rename from services/mailer/application/template/image/header.png rename to services/mailer/application/template/default/image/header.png diff --git a/services/mailer/application/template/image/info.png b/services/mailer/application/template/default/image/info.png similarity index 100% rename from services/mailer/application/template/image/info.png rename to services/mailer/application/template/default/image/info.png diff --git a/services/mailer/application/template/image/instagram.png b/services/mailer/application/template/default/image/instagram.png similarity index 100% rename from services/mailer/application/template/image/instagram.png rename to services/mailer/application/template/default/image/instagram.png diff --git a/services/mailer/application/template/image/linkedin.png b/services/mailer/application/template/default/image/linkedin.png similarity index 100% rename from services/mailer/application/template/image/linkedin.png rename to services/mailer/application/template/default/image/linkedin.png diff --git a/services/mailer/application/template/image/pinterest.png b/services/mailer/application/template/default/image/pinterest.png similarity index 100% rename from services/mailer/application/template/image/pinterest.png rename to services/mailer/application/template/default/image/pinterest.png diff --git a/services/mailer/application/template/image/twitter.png b/services/mailer/application/template/default/image/twitter.png similarity index 100% rename from services/mailer/application/template/image/twitter.png rename to services/mailer/application/template/default/image/twitter.png diff --git a/services/mailer/application/template/image/youtube.png b/services/mailer/application/template/default/image/youtube.png similarity index 100% rename from services/mailer/application/template/image/youtube.png rename to services/mailer/application/template/default/image/youtube.png diff --git a/services/mailer/application/template/notice/notice.css b/services/mailer/application/template/default/style.css similarity index 100% rename from services/mailer/application/template/notice/notice.css rename to services/mailer/application/template/default/style.css diff --git a/services/mailer/application/template/notice/attachment.json b/services/mailer/application/template/notification-alias/attachment.json similarity index 100% rename from services/mailer/application/template/notice/attachment.json rename to services/mailer/application/template/notification-alias/attachment.json diff --git a/services/mailer/application/template/notification-alias/index.html b/services/mailer/application/template/notification-alias/index.html new file mode 100644 index 000000000..ab00f8ef6 --- /dev/null +++ b/services/mailer/application/template/notification-alias/index.html @@ -0,0 +1,74 @@ + + + + {{_.subject}} + + + +
+ +
+ VerdNatura +
+ + + +
+

{{_.title}}

+
+ + + +
+

{{_.hello}}, #{{alias}}

+

{{message}}

+

+ + + +
+ +
{{_.actionButton}}
+
+
+ + +
{{_.infoButton}}
+
+
+
+ + + +
+ + Visita nuestro Facebook + + + Visita nuestro Twitter + + + Visita nuestro canal de Youtube + + + Visita nuestro Pinterest + + + Visita nuestro Instagram + + + Visita nuestro Linkedin + +
+ + + +
+

{{_.fiscalAddress}}

+

{{_.privacy}}

+

{{_.privacyLaw}}

+
+ +
+ + \ No newline at end of file diff --git a/services/mailer/application/template/notification-alias/locale/es.json b/services/mailer/application/template/notification-alias/locale/es.json new file mode 100644 index 000000000..0deeb1604 --- /dev/null +++ b/services/mailer/application/template/notification-alias/locale/es.json @@ -0,0 +1,16 @@ +{ + "subject": "Has recibido una nueva notificación", + "title": "Nueva notificación", + "hello": "Hola", + "notificationCode": { + "clientDeactivate": { + "subject": "Gestionar baja de contrato", + "message": "El cliente con id %clientId% está clasificado, por favor, gestione la baja del contrato primero." + } + }, + "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", + "privacy": "- AVISO - Este mensaje es privado y confidencial, y debe ser utilizado exclusivamente por la persona destinataria del mismo. Si usted ha recibido este mensaje por error, le rogamos lo comunique al remitente y borre dicho mensaje y cualquier documento adjunto que pudiera contener. Verdnatura Levante SL no renuncia a la confidencialidad ni a ningún privilegio por causa de transmisión errónea o mal funcionamiento. Igualmente no se hace responsable de los cambios, alteraciones, errores u omisiones que pudieran hacerse al mensaje una vez enviado.", + "privacyLaw": "En cumplimiento de lo dispuesto en la Ley Orgánica 15/1999, de Protección de Datos de Carácter Personal, le comunicamos que los datos personales que facilite se incluirán en ficheros automatizados de VERDNATURA LEVANTE S.L., pudiendo en todo momento ejercitar los derechos de acceso, rectificación, cancelación y oposición, comunicándolo por escrito al domicilio social de la entidad. La finalidad del fichero es la gestión administrativa, contabilidad, y facturación." +} \ No newline at end of file diff --git a/services/mailer/application/template/notification-alias/notification-alias.js b/services/mailer/application/template/notification-alias/notification-alias.js new file mode 100644 index 000000000..132d037f4 --- /dev/null +++ b/services/mailer/application/template/notification-alias/notification-alias.js @@ -0,0 +1,29 @@ +var path = require('path'); +var database = require(path.join(__dirname, '../../database.js')); +var locale = require(path.join(__dirname, '../../locale.js')); + +module.exports = class NotificationAlias { + getData(params, cb) { + this.params = params; + + let query = `SELECT alias, CONCAT(alias, '@verdnatura.es') AS recipient + FROM account.mailAlias + WHERE alias = ?`; + + database.pool.query(query, [params.alias], (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 subject() { + return this._.notificationCode[this.params.code].subject; + } + + get message() { + return locale.parseText(this._.notificationCode[this.params.code].message, this.params.bodyParams); + } +}; diff --git a/services/mailer/application/template/notification-notice/attachment.json b/services/mailer/application/template/notification-notice/attachment.json new file mode 100644 index 000000000..0637a088a --- /dev/null +++ b/services/mailer/application/template/notification-notice/attachment.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/services/mailer/application/template/notice/notice.html b/services/mailer/application/template/notification-notice/index.html similarity index 100% rename from services/mailer/application/template/notice/notice.html rename to services/mailer/application/template/notification-notice/index.html diff --git a/services/mailer/application/template/notice/locale/es.json b/services/mailer/application/template/notification-notice/locale/es.json similarity index 100% rename from services/mailer/application/template/notice/locale/es.json rename to services/mailer/application/template/notification-notice/locale/es.json diff --git a/services/mailer/application/template/notice/notice.js b/services/mailer/application/template/notification-notice/notification-notice.js similarity index 96% rename from services/mailer/application/template/notice/notice.js rename to services/mailer/application/template/notification-notice/notification-notice.js index e27a49a54..493261913 100644 --- a/services/mailer/application/template/notice/notice.js +++ b/services/mailer/application/template/notification-notice/notification-notice.js @@ -1,7 +1,7 @@ var path = require('path'); var database = require(path.join(__dirname, '../../database.js')); -module.exports = class Notice { +module.exports = class NotificationNotice { getData(params, cb) { let query = `SELECT LOWER(ct.code) countryCode, diff --git a/services/mailer/application/template/payment-update/index.html b/services/mailer/application/template/payment-update/index.html new file mode 100644 index 000000000..caec77e90 --- /dev/null +++ b/services/mailer/application/template/payment-update/index.html @@ -0,0 +1,80 @@ + + + + {{_.subject}} + + + +
+
+ + + + + +
+

{{_.title}}

+
+ + + +
+

{{_.dear}},

+

{{_.bodyDescription}}

+

+

{{_.paymentMethod}}: {{payMethodName}}
+ {{{paymentDay}}} +

+

{{paymentAdvice}}

+

{{_.notifyError}}

+
+ + + + + + + + + + + +
+

{{_.fiscalAddress}}

+

{{_.privacy}}

+

{{_.privacyLaw}}

+
+ +
+
+ + \ No newline at end of file diff --git a/services/mailer/application/template/payment-update/payment-update.css b/services/mailer/application/template/payment-update/payment-update.css deleted file mode 100644 index 83fe2dd6d..000000000 --- a/services/mailer/application/template/payment-update/payment-update.css +++ /dev/null @@ -1,92 +0,0 @@ -img { - margin: 0 -} - -.wrapper { - background-color: #EEE -} - -.container { - font-family: arial, sans-serif; - max-width: 600px; - min-width: 320px; - font-size: 16px; - margin: 0 auto; - color: #555 -} - -.banner img { - width: 100% -} - -.title { - background-color: #95d831; - text-align: center; - padding: 35px 0 -} - -.title h1 { - font-size: 32px; - color: #333; - margin: 0 -} - -.body { - background-color:#FFF; - padding: 20px -} - -.buttons { - background-color: #FFF; - text-align: center; - width: 100% -} - -.buttons a { - text-decoration: none; - font-size: 18px; - color: #fff -} - -.buttons .btn { - background-color: #333; - min-width: 300px; - height: 72px; - display: inline-block; - text-align: center -} - -.buttons .btn .text { - display: inline-block; - padding-top: 22px -} - -.buttons .btn .icon { - background-color: #95d831; - text-align: center; - padding-top: 22px; - float: right; - height: 50px; - width: 70px -} - -.footer { - background-color: #555; - text-align: center; - padding: 20px 0 -} - -.footer a { - text-decoration: none; - margin-right: 5px -} - -.footer a img { - margin: 0 -} - -.privacy { - padding: 20px 0; - font-size: 10px; - font-weight: 100 -} \ No newline at end of file diff --git a/services/mailer/server.js b/services/mailer/server.js index 4939621a5..63a7c1596 100644 --- a/services/mailer/server.js +++ b/services/mailer/server.js @@ -7,26 +7,29 @@ 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'); -// Middleware +// Body parser middleware app.use(bodyParser.json()); app.use(bodyParser.urlencoded({extended: true})); -// Cargar rutas +// Auth middleware +var requestToken = function(request, response, next) { + auth.init(request, response, next); +}; + +app.use(requestToken); + +// Load routes app.use('/', require('./application/router.js')); -app.use(function(err, req, res, next) { - console.error(err.message); - res.status(500).send('Something broke!'); -}); - -// Iniciar escucha del servidor app.start = function() { var listener = app.listen(settings.app().port, function() { var servicePath = 'http://' + listener.address().address + ':' + listener.address().port; mail.init(); database.init(); database.testEmail(); + console.log('Web server ' + settings.app().name.toUpperCase() + ' listening at: ' + servicePath); console.log('Browse your REST API at: ' + servicePath + '/mailer'); if (settings.app().debug) {