From fe4d3a8ee7591de941749697399fddd7ad25fc1b Mon Sep 17 00:00:00 2001 From: Nitin Jain Date: Tue, 21 Sep 2021 17:27:49 +0530 Subject: [PATCH 1/3] waterline version upgrade fix --- lib/config.js | 5 +++-- lib/emailjs.js | 6 +++--- lib/orm/index.js | 4 ++-- lib/orm/mail_archive.js | 13 ++++++------- lib/orm/mail_outbox.js | 13 ++++++------- lib/orm/mail_rules.js | 22 +++++++++++----------- package.json | 4 ++-- 7 files changed, 33 insertions(+), 34 deletions(-) diff --git a/lib/config.js b/lib/config.js index 7734be5..fd844e7 100644 --- a/lib/config.js +++ b/lib/config.js @@ -9,13 +9,14 @@ module.exports = { rulestable: 'mail_rules' } }, - connections: { + datastores: { enabledProvider: 'postgres', providers: { postgres: { adapter: 'sails-postgresql', + schemaName: 'sloop_one', url: 'postgres://localhost/test', - ssl: true, + ssl: { rejectUnauthorized: false }, multipleStatements: true, wlNext: { caseSensitive: true diff --git a/lib/emailjs.js b/lib/emailjs.js index cf5fa56..24361b0 100644 --- a/lib/emailjs.js +++ b/lib/emailjs.js @@ -137,8 +137,8 @@ exportable = (function () { if (config.connections.enabledProvider !== 'postgres') { return deferred.resolve(); } - orm.config.connections.myPostgres = Object.assign({}, - defConfig.connections.providers.postgres, + orm.config.datastores.myPostgres = Object.assign({}, + defConfig.datastores.providers.postgres, config.connections.providers.postgres); orm.schemaConfig.settings = Object.assign({}, defConfig.defaults.schema, config.defaults.schema); @@ -149,7 +149,7 @@ exportable = (function () { deferred.reject(err); } else { db.models = models.collections; - db.connections = models.connections; + db.connections = models.datastores; log('Initialized postgres models'); deferred.resolve(); } diff --git a/lib/orm/index.js b/lib/orm/index.js index 18c4a8d..7ed1fe1 100644 --- a/lib/orm/index.js +++ b/lib/orm/index.js @@ -8,7 +8,7 @@ var config = { 'sails-postgresql': postgresAdapter }, - connections: { + datastores: { myPostgres: { } }, @@ -42,7 +42,7 @@ function initialize () { case 'mail_rules': model.tableName = schemaConfig.settings.rulestable; break; } model = Waterline.Collection.extend(model); - orm.loadCollection(model); + orm.registerModel(model); }); } diff --git a/lib/orm/mail_archive.js b/lib/orm/mail_archive.js index f19792c..6c53147 100644 --- a/lib/orm/mail_archive.js +++ b/lib/orm/mail_archive.js @@ -1,18 +1,17 @@ /* jshint node:true */ var Archive = { - connection: 'myPostgres', + datastore: 'myPostgres', tableName: 'mail_archive', identity: 'MailArchive', meta: { schemaName: 'public' }, - autoPK: false, - autoCreatedAt: true, - autoUpdatedAt: true, + primaryKey: 'eid', attributes: { - eid: {type: 'integer', columnName: 'eid', - primaryKey: true, autoIncrement: true}, + createdAt: { type: 'string', autoCreatedAt: true, }, + updatedAt: { type: 'string', autoUpdatedAt: true, }, + eid: {type: 'number', columnName: 'eid', autoMigrations: {autoIncrement: true}}, eventname: {type: 'string', columnName: 'eventname'}, template: {type: 'string', columnName: 'template'}, content: {type: 'json', columnName: 'content'}, @@ -25,7 +24,7 @@ var Archive = { text: {type: 'string', columnName: 'text'}, attachments: {type: 'json', columnName: 'attachments'}, error: {type: 'string', columnName: 'error'}, - attempts: {type: 'integer', columnName: 'attempts'} + attempts: {type: 'number', columnName: 'attempts'} } }; diff --git a/lib/orm/mail_outbox.js b/lib/orm/mail_outbox.js index 3e4ff60..22732f0 100644 --- a/lib/orm/mail_outbox.js +++ b/lib/orm/mail_outbox.js @@ -1,18 +1,17 @@ /* jshint node:true */ var Outbox = { - connection: 'myPostgres', + datastore: 'myPostgres', tableName: 'mail_outbox', identity: 'MailOutbox', meta: { schemaName: 'public' }, - autoPK: false, - autoCreatedAt: true, - autoUpdatedAt: true, + primaryKey: 'eid', attributes: { - eid: {type: 'integer', columnName: 'eid', - primaryKey: true, autoIncrement: true}, + createdAt: { type: 'string', autoCreatedAt: true, }, + updatedAt: { type: 'string', autoUpdatedAt: true, }, + eid: {type: 'number', columnName: 'eid', autoMigrations: {autoIncrement: true}}, eventname: {type: 'string', columnName: 'eventname'}, template: {type: 'string', columnName: 'template'}, content: {type: 'json', columnName: 'content'}, @@ -25,7 +24,7 @@ var Outbox = { text: {type: 'string', columnName: 'text'}, attachments: {type: 'json', columnName: 'attachments'}, error: {type: 'string', columnName: 'error'}, - attempts: {type: 'integer', columnName: 'attempts'} + attempts: {type: 'number', columnName: 'attempts'} } }; diff --git a/lib/orm/mail_rules.js b/lib/orm/mail_rules.js index 989caea..060fb70 100644 --- a/lib/orm/mail_rules.js +++ b/lib/orm/mail_rules.js @@ -1,25 +1,25 @@ /* jshint node:true */ var Rules = { - connection: 'myPostgres', + datastore: 'myPostgres', tableName: 'mail_rules', identity: 'MailRules', meta: { schemaName: 'public' }, - autoPK: false, - autoCreatedAt: true, - autoUpdatedAt: true, + primaryKey: 'eventname', attributes: { - ruleid: {type: 'int', columnName: 'ruleid'}, - eventname: {type: 'string', columnName: 'eventname'}, + createdAt: { type: 'string', autoCreatedAt: true }, + updatedAt: { type: 'string', autoUpdatedAt: true, }, + ruleid: {type: 'string', columnName: 'ruleid', allowNull: true }, + eventname: {type: 'string', columnName: 'eventname', required: true}, enabled: {type: 'boolean', columnName: 'enabled'}, template: {type: 'string', columnName: 'template'}, - from: {type: 'string', columnName: 'from'}, - to: {type: 'string', columnName: 'to'}, - cc: {type: 'string', columnName: 'cc'}, - bcc: {type: 'string', columnName: 'bcc'}, - subject: {type: 'string', columnName: 'subject'} + from: {type: 'string', columnName: 'from', allowNull: true}, + to: {type: 'string', columnName: 'to', allowNull: true}, + cc: {type: 'string', columnName: 'cc', allowNull: true}, + bcc: {type: 'string', columnName: 'bcc', allowNull: true}, + subject: {type: 'string', columnName: 'subject', allowNull: true} } }; diff --git a/package.json b/package.json index ad5fac4..2ca2e30 100644 --- a/package.json +++ b/package.json @@ -25,8 +25,8 @@ "handlebars": "3.0.0", "q": "1.4.1", "lodash": "2.4.1", - "sails-postgresql": "0.11.4", - "waterline": "0.12.2" + "sails-postgresql": "2.0.0", + "waterline": "0.13.6" }, "devDependencies": { "chai": "3.5.0", From bb6b6f1e6f7d26d822e883e8bd9bb2d38ecfd1be Mon Sep 17 00:00:00 2001 From: Nitin Jain Date: Wed, 6 Oct 2021 22:52:40 +0530 Subject: [PATCH 2/3] Adding allowNull properties --- lib/orm/mail_archive.js | 8 ++++---- lib/orm/mail_outbox.js | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/orm/mail_archive.js b/lib/orm/mail_archive.js index 6c53147..b2f6163 100644 --- a/lib/orm/mail_archive.js +++ b/lib/orm/mail_archive.js @@ -18,12 +18,12 @@ var Archive = { subject: {type: 'string', columnName: 'subject'}, from: {type: 'string', columnName: 'from'}, to: {type: 'string', columnName: 'to'}, - cc: {type: 'string', columnName: 'cc'}, - bcc: {type: 'string', columnName: 'bcc'}, + cc: {type: 'string', columnName: 'cc', allowNull: true}, + bcc: {type: 'string', columnName: 'bcc', allowNull: true}, html: {type: 'string', columnName: 'html'}, - text: {type: 'string', columnName: 'text'}, + text: {type: 'string', columnName: 'text', allowNull: true}, attachments: {type: 'json', columnName: 'attachments'}, - error: {type: 'string', columnName: 'error'}, + error: {type: 'string', columnName: 'error', allowNull: true}, attempts: {type: 'number', columnName: 'attempts'} } }; diff --git a/lib/orm/mail_outbox.js b/lib/orm/mail_outbox.js index 22732f0..d9d1a1f 100644 --- a/lib/orm/mail_outbox.js +++ b/lib/orm/mail_outbox.js @@ -18,12 +18,12 @@ var Outbox = { subject: {type: 'string', columnName: 'subject'}, from: {type: 'string', columnName: 'from'}, to: {type: 'string', columnName: 'to'}, - cc: {type: 'string', columnName: 'cc'}, - bcc: {type: 'string', columnName: 'bcc'}, + cc: {type: 'string', columnName: 'cc', allowNull: true}, + bcc: {type: 'string', columnName: 'bcc', allowNull: true}, html: {type: 'string', columnName: 'html'}, - text: {type: 'string', columnName: 'text'}, + text: {type: 'string', columnName: 'text', allowNull: true}, attachments: {type: 'json', columnName: 'attachments'}, - error: {type: 'string', columnName: 'error'}, + error: {type: 'string', columnName: 'error', allowNull: true}, attempts: {type: 'number', columnName: 'attempts'} } }; From 3e8b25e799f033e39d8445b49e1e16cb1a60bdd7 Mon Sep 17 00:00:00 2001 From: Nitin Jain Date: Mon, 25 Oct 2021 16:04:04 +0530 Subject: [PATCH 3/3] Adding email sending using html --- lib/emailjs.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/emailjs.js b/lib/emailjs.js index 24361b0..e3059a1 100644 --- a/lib/emailjs.js +++ b/lib/emailjs.js @@ -308,8 +308,9 @@ exportable = (function () { options = options || {}; var template = templates[options.template]; + var isHTML = options.isHTML; - if (!template) { + if (!template && !isHTML) { return handleExcp(cb, 'Template not found: '+options.template); } if (!options.to || !options.subject) { @@ -318,7 +319,7 @@ exportable = (function () { } options.from = options.from || defaultFrom; - renderMail(template, content) + renderMail(template, content, options) .then(function (results) { options.html = results.html; options.text = results.text; @@ -375,9 +376,13 @@ exportable = (function () { return deferred.promise; } - function renderMail (template, content) { + function renderMail (template, content, options) { var deferred = Q.defer(); - + if (options.isHTML && content) { + console.log('---------- Allowed sending custom email --------------'); + deferred.resolve(content); + return deferred.promise; + } if (template) { template.render(content, function (err, results) { if (err) { @@ -473,4 +478,4 @@ exportable = (function () { return emailJS; })(); -module.exports = exports = exportable; +module.exports = exports = exportable; \ No newline at end of file