This file contains hidden or 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
return Promise.try(function () { | |
return MongoClient.connectAsync(MONGODB_CONNECTION_STRING) | |
}).then(function(db){ | |
return Promise.try(function(){ | |
return db.collection("downloads").findOneAsync({key: status.filename}); | |
}).then(function(item){ | |
return Promise.try(function() { | |
return db.closeAsync(); | |
}).then(function() { | |
return item; |
This file contains hidden or 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
ended: false, | |
endEmitted: false, | |
reading: true, | |
sync: false, | |
needReadable: true, | |
emittedReadable: false, | |
readableListening: false, | |
defaultEncoding: 'utf8', | |
ranOut: false, | |
awaitDrain: 0, |
This file contains hidden or 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
static login(email, password) { | |
return Promise.try(() => { | |
return Account.fetch(email)) | |
}).then((acc) => { | |
return Promise.try(() => { | |
bcrypt.compareAsync(password, acc.password) | |
}).then(result => { | |
if (result) { | |
console.log(`User logged in: ${acc.email}`); | |
const token = jwt.sign(_.pick(acc, ['id', 'email', 'agencyId']), |
This file contains hidden or 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
client.select('*').from(opts.table).stream() | |
.pipe(through.obj(function chunkToFiles (chunk, enc, callback) { | |
const primaryKey = chunk[opts.primaryKey] | |
Object.keys(chunk).forEach((key) => { | |
this.push(new File({ | |
path: `./${primaryKey}/${key}`, | |
contents: new Buffer(chunk[key] + '') | |
})) | |
}) |
This file contains hidden or 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
const basename = require('basename'); | |
const Promise = require('bluebird'); | |
const globAsync = Promise.promisify(require('glob')); | |
const dir = 'a'; | |
function galleryListPromise() { | |
return Promise.try( () => { | |
return globAsync("gallery/*/", {}) |
This file contains hidden or 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
var Promise = require('bluebird'); | |
var rdb = Promise.promisify(require('rethinkdb')); | |
module.exports = function(config) { | |
return { | |
connectToDb: function(){ | |
return Promise.try(() => { | |
return rdb.connect(config); | |
}); | |
} |
This file contains hidden or 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
var resultTemplate = "" + | |
" <ul class='searchList'>" + | |
" <% _.each(paymentActions,function(paymentActivity){ %>" + | |
" <li><span class='amount visible-phone'>-<%= paymentActivity.grossAmount %></span>" + | |
" </li>" + | |
" <% }); %>" + | |
" </ul>"; | |
var template = _.template(resultTemplate, { |
This file contains hidden or 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
'use strict'; | |
const _ = require('lodash'); | |
module.exports = (permissions, requiredPermissions) => { | |
if (!_.isPlainObject(requiredPermissions)) { | |
throw new TypeError('`requiredPermissions` is not an object'); | |
} else if (!_.isPlainObject(permissions)) { | |
throw new TypeError('`permissions` is not an object'); | |
} else { |
This file contains hidden or 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
/// Handler for /travel/{url} | |
module.exports.travel = (event, context, callback) => { | |
// Get the url from the resource path. | |
// Get the html. | |
// Turn it into a successful request. | |
// Attach the Node.js callback onto the end. | |
return Promise.try(() => { | |
return getURLFromPath(event.path); | |
}).then((url) => { |
This file contains hidden or 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
const ChartjsNode = require('chartjs-node'); | |
// 600x600 canvas size | |
var chartNode = new ChartjsNode(600, 600); | |
var randomnumber=Math.random(); | |
var imagename = "testimage"+randomnumber+".png" | |
module.exports = imagename | |
// each api returns a Promise | |
chartNode.drawChart({ | |
type: 'bar', |