diff --git a/services/mailer/.gitignore b/services/mailer/.gitignore index b66335f8f..b863d0b61 100644 --- a/services/mailer/.gitignore +++ b/services/mailer/.gitignore @@ -1,3 +1,4 @@ node_modules -mailerMysql.json -mailerSmtp.json \ No newline at end of file +app.development.json +smtp.development.json +mysql.development.json \ No newline at end of file diff --git a/services/mailer/Application/Config/mailerApp.json b/services/mailer/Application/Config/app.json similarity index 57% rename from services/mailer/Application/Config/mailerApp.json rename to services/mailer/Application/Config/app.json index b6b16e16a..f7a13d3ef 100644 --- a/services/mailer/Application/Config/mailerApp.json +++ b/services/mailer/Application/Config/app.json @@ -4,6 +4,6 @@ "port": 3003, "debug": true, "defaultLanguage": "es", - "senderMail": "nocontestar@verdnatura.es", - "senderName": "VerdNatura" + "senderMail": "noreply@localhost", + "senderName": "" } \ No newline at end of file diff --git a/services/mailer/Application/Config/mysql.json b/services/mailer/Application/Config/mysql.json new file mode 100644 index 000000000..ddfd88bed --- /dev/null +++ b/services/mailer/Application/Config/mysql.json @@ -0,0 +1,7 @@ +{ + "host": "localhost", + "port": 3306, + "user": "reports", + "password": "", + "database": "" +} \ No newline at end of file diff --git a/services/mailer/Application/Config/smtp.json b/services/mailer/Application/Config/smtp.json new file mode 100644 index 000000000..a6579d067 --- /dev/null +++ b/services/mailer/Application/Config/smtp.json @@ -0,0 +1,9 @@ +{ + "host": "localhost", + "port": 465, + "secure": true, + "auth": { + "user": "noreply", + "pass": "" + } +} \ No newline at end of file diff --git a/services/mailer/Application/Util/system.js b/services/mailer/Application/Util/system.js index 08092ad5c..358346184 100644 --- a/services/mailer/Application/Util/system.js +++ b/services/mailer/Application/Util/system.js @@ -1,5 +1,4 @@ module.exports = { - /** * Obtiene las variables de entorno * @param {String} env - Nombre de la variable de entorno diff --git a/services/mailer/Application/database.js b/services/mailer/Application/database.js index 5682b3e5b..0b4144775 100644 --- a/services/mailer/Application/database.js +++ b/services/mailer/Application/database.js @@ -3,7 +3,6 @@ var settings = require('./settings.js'); var logger = require('./logger.js'); module.exports = { - /** * Variable de instancia del pool */ diff --git a/services/mailer/Application/language.js b/services/mailer/Application/language.js index 7cd13f367..b73042429 100644 --- a/services/mailer/Application/language.js +++ b/services/mailer/Application/language.js @@ -1,10 +1,8 @@ var fs = require('fs'); var settings = require('./settings.js'); -var logger = require('./logger.js'); var path = require('path'); module.exports = { - /** * Devuelve las claves de idioma de una plantilla * @param {String} templateName - Nombre de la plantilla @@ -12,15 +10,15 @@ module.exports = { * @return {Object} Devuelve el objeto con las claves de idioma */ load: function(templateName, langCode) { - // Comprobamos que exista una traducción para esta plantilla var localeFile = path.join(__dirname, 'Language', `${langCode}.${templateName}.json`); var defaultLocaleFile = path.join(__dirname, 'Language', `${settings.defaultLanguage}.${templateName}.json`); + if (fs.existsSync(localeFile)) { return require(localeFile); } else if (fs.existsSync(defaultLocaleFile)) { return require(defaultLocaleFile); - } else { - throw new Error('No se ha encontrado ninguna traducción para la plantilla ' + templateName + '.'); } + + throw new Error('No se ha encontrado ninguna traducción para la plantilla ' + templateName + '.'); } -}; \ No newline at end of file +}; diff --git a/services/mailer/Application/logger.js b/services/mailer/Application/logger.js index c7442c33f..03434d464 100644 --- a/services/mailer/Application/logger.js +++ b/services/mailer/Application/logger.js @@ -1,28 +1,28 @@ - -// Tipos de advertencias -global.__LOG_INFO = 1; -global.__LOG_WARNING = 2; -global.__LOG_ERROR = 3; - -module.exports = { - - /** - * Imprimir advertencia directamente en consola - * @param {Integer} type - Constante tipo de advertencia - */ - print: function(type, message) - { - if (type == __LOG_INFO) - { - console.log('[INFORMACIÓN] -> ' + message); - } - else if(type == __LOG_WARNING) - { - console.log('[ADVERTENCIA] -> ' + message); - } - else if(type == __LOG_ERROR) - { - console.log('[ERROR] -> ' + message); - } - } -} \ No newline at end of file + +/** + * Tipos de advertencias + */ +global.__LOG_INFO = 1; +global.__LOG_WARNING = 2; +global.__LOG_ERROR = 3; + +module.exports = { + /** + * Imprimir advertencia directamente en consola + * @param {Integer} type Constante tipo de advertencia + * @param {String} message Mensaje a mostrar + */ + print: function(type, message) { + switch (type) { + case __LOG_INFO: + console.log(`[INFO] -> ${message}`); + break; + case __LOG_WARNING: + console.log(`[WARN] -> ${message}`); + break; + case __LOG_ERROR: + console.log(`[ERROR] -> ${message}`); + break; + } + } +}; diff --git a/services/mailer/Application/mail.js b/services/mailer/Application/mail.js index c0e9d58c2..3eb7e57ac 100644 --- a/services/mailer/Application/mail.js +++ b/services/mailer/Application/mail.js @@ -3,9 +3,10 @@ var settings = require('./settings.js'); var logger = require('./logger.js'); var path = require('path'); -// Módulo para el envío de emails +/** + * Módulo para el envío de emails + */ module.exports = { - transporter: null, /** @@ -24,10 +25,10 @@ module.exports = { }); }, -/** - * Envia un email con los datos recibidos desde un vector. - * @param {Object} data - Datos para el envío del email - */ + /** + * Envia un email con los datos recibidos desde un vector. + * @param {Object} data - Datos para el envío del email + */ send: function(data) { var filePath = 'Template/images/'; let mailOptions = { @@ -57,5 +58,5 @@ module.exports = { return true; } }); - }, -} \ No newline at end of file + } +}; diff --git a/services/mailer/Application/router.js b/services/mailer/Application/router.js index 03aecafe2..dbdd8c5f4 100644 --- a/services/mailer/Application/router.js +++ b/services/mailer/Application/router.js @@ -8,9 +8,9 @@ router.get('/', function(request, response) { }); // Rutas de los escritos. -router.use('/manuscript', require('./Route/Manuscript.js')); +router.use('/manuscript', require('./Route/manuscript.js')); // Rutas de las notificaciones. -router.use('/notification', require('./Route/Notification.js')); +router.use('/notification', require('./Route/notification.js')); module.exports = router; diff --git a/services/mailer/Application/settings.js b/services/mailer/Application/settings.js index e501e82f6..eccef95fe 100644 --- a/services/mailer/Application/settings.js +++ b/services/mailer/Application/settings.js @@ -1,12 +1,31 @@ -// Módulo de configuración + +var path = require('path'); + +/** + * Módulo de configuración + */ module.exports = { + /** + * Obtiene la configuración en función del entorno en el que se está + * ejecutando la aplicación. + * @param {String} name Nombre del fichero + * @return {Object} Objeto de configuración + */ + getConfig: function(name) { + let env = process.env.NODE_ENV; + + if (!env) + env = 'development'; + + return require(path.join(__dirname, 'Config', `${name}.${env}.json`)); + }, /** * Configuración de la aplicación * @return {Object} Objeto de configuración app */ app: function() { - return require('./Config/mailerApp.json'); + return this.getConfig('app'); }, /** @@ -14,7 +33,7 @@ module.exports = { * @return {Object} Objeto de configuración smtp */ smtp: function() { - return require('./Config/mailerSmtp.json'); + return this.getConfig('smtp'); }, /** @@ -22,6 +41,6 @@ module.exports = { * @return {Object} Objeto de configuración MySQL */ mysql: function() { - return require('./Config/mailerMysql.json'); + return this.getConfig('mysql'); } -} +}; diff --git a/services/mailer/Application/template.js b/services/mailer/Application/template.js index 6cf79722b..89267f398 100644 --- a/services/mailer/Application/template.js +++ b/services/mailer/Application/template.js @@ -3,10 +3,10 @@ var mustache = require('mustache'); var database = require('./database.js'); var language = require('./language.js'); var path = require('path'); -var Template = { +var Template = { /** - * Obtiene la plantilla + * Obtiene la plantilla. * @param {String} templateName - Nombre de la plantilla * @param {Object} langCode - Código del idioma * @param {Object} params - Datos a reemplazar.