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..e3059a1 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(); } @@ -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 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..b2f6163 100644 --- a/lib/orm/mail_archive.js +++ b/lib/orm/mail_archive.js @@ -1,31 +1,30 @@ /* 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'}, 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'}, - attempts: {type: 'integer', columnName: 'attempts'} + 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 3e4ff60..d9d1a1f 100644 --- a/lib/orm/mail_outbox.js +++ b/lib/orm/mail_outbox.js @@ -1,31 +1,30 @@ /* 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'}, 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'}, - attempts: {type: 'integer', columnName: 'attempts'} + error: {type: 'string', columnName: 'error', allowNull: true}, + 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",