-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
127 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,18 @@ | ||
const Agenda = require('agenda') | ||
const Graceful = require('node-graceful') | ||
const config = require('../config') | ||
const connection = require('../db/connection') | ||
|
||
module.exports = connection.then((conn) => { | ||
module.exports = connection.then((db) => { | ||
return new Promise((resolve, reject) => { | ||
const agenda = new Agenda({ mongo: conn }) | ||
const agenda = new Agenda({ | ||
mongo: db, | ||
db: { collection: config.get('collection') } | ||
}) | ||
|
||
agenda.on('error', reject) | ||
agenda.on('ready', () => resolve(agenda)) | ||
|
||
Graceful.on('exit', (done) => agenda.stop(done)) | ||
}) | ||
}).catch((err) => { throw err }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,8 +16,8 @@ | |
"ru", | ||
"uk" | ||
], | ||
"organizationName": "[email protected]", | ||
"organizationEmail": "The DemocracyOS team", | ||
"organizationName": "The DemocracyOS team", | ||
"organizationEmail": "[email protected]", | ||
"mailer": { | ||
"service": "", | ||
"auth": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
const db = require('.') | ||
|
||
module.exports = db.then(() => { | ||
module.exports = db.then((db) => { | ||
return db._db | ||
}) | ||
}).catch((err) => { throw err }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,26 @@ | ||
const monk = require('monk') | ||
const Graceful = require('node-graceful') | ||
const listenOnceOf = require('../utils/listen-once-of') | ||
const config = require('../config') | ||
|
||
const db = module.exports = monk(config.get('mongoUrl')) | ||
module.exports = monk(config.get('mongoUrl')).then((db) => { | ||
db.catch = db.then = new Promise((resolve, reject) => { | ||
switch (db._state) { | ||
case 'closed': | ||
reject(new Error('Connection closed')) | ||
break | ||
case 'open': | ||
resolve(db) | ||
break | ||
default: | ||
listenOnceOf(db, { | ||
open: resolve, | ||
'error-opening': reject | ||
}) | ||
} | ||
}) | ||
|
||
Graceful.on('exit', () => db.close()) | ||
Graceful.on('exit', (done) => db.close(done)) | ||
|
||
return db | ||
}).catch((err) => { throw err }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
var path = require('path') | ||
var requireAll = require('require-all') | ||
|
||
module.exports.init = function init () { | ||
const jobs = requireAll(path.join(__dirname, '/lib')) | ||
module.exports.init = function init (notifier) { | ||
const jobs = requireAll({ | ||
dirname: path.join(__dirname, '/lib'), | ||
resolve: (job) => typeof job === 'function' && job(notifier) | ||
}) | ||
|
||
return Promise.all(Object.keys(jobs).map((name) => jobs[name])) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,15 @@ | ||
const pify = require('pify') | ||
const config = require('../config') | ||
const transporter = require('./transporter') | ||
|
||
module.exports.send = function send (opts) { | ||
return new Promise((resolve, reject) => { | ||
if (!opts.from) { | ||
opts.from = { | ||
name: config.get('organizationName'), | ||
address: config.get('organizationEmail') | ||
} | ||
} | ||
const sendMail = pify(transporter.sendMail.bind(transporter)) | ||
|
||
const defaultSender = { | ||
name: config.get('organizationName'), | ||
address: config.get('organizationEmail') | ||
} | ||
|
||
transporter.sendMail(opts, (err) => { | ||
if (err) return reject(err) | ||
resolve() | ||
}) | ||
}) | ||
module.exports.send = function send (opts) { | ||
if (!opts.from) opts.from = defaultSender | ||
return sendMail(opts) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
module.exports.emailAddress = function emailAddress (user) { | ||
return { | ||
address: user.email, | ||
name: user.lastName ? user.firstName + ' ' + user.lastName : user.firstName | ||
name: user.lastName ? user.firstName + ' ' + user.lastName : user.firstName, | ||
address: user.email | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
module.exports = function listenOnceOf (emitter, callbacks) { | ||
const events = Object.keys(callbacks) | ||
const listeners = {} | ||
|
||
const removeListeners = () => { | ||
events.forEach((event) => { | ||
emitter.removeListener(event, listeners[event]) | ||
}) | ||
} | ||
|
||
events.forEach((event) => { | ||
const listener = listeners[event] = (...args) => { | ||
removeListeners() | ||
callbacks[event](...args) | ||
} | ||
|
||
emitter.once(event, listener) | ||
}) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters