Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Waterline and sails-postgresql version upgrade #12

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 13 additions & 8 deletions lib/emailjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -473,4 +478,4 @@ exportable = (function () {
return emailJS;
})();

module.exports = exports = exportable;
module.exports = exports = exportable;
4 changes: 2 additions & 2 deletions lib/orm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var config = {
'sails-postgresql': postgresAdapter
},

connections: {
datastores: {
myPostgres: {
}
},
Expand Down Expand Up @@ -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);
});
}

Expand Down
21 changes: 10 additions & 11 deletions lib/orm/mail_archive.js
Original file line number Diff line number Diff line change
@@ -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'}
}
};

Expand Down
21 changes: 10 additions & 11 deletions lib/orm/mail_outbox.js
Original file line number Diff line number Diff line change
@@ -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'}
}
};

Expand Down
22 changes: 11 additions & 11 deletions lib/orm/mail_rules.js
Original file line number Diff line number Diff line change
@@ -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}
}
};

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down