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
'use strict'; | |
// load deps | |
let lab = exports.lab = require('lab').script(); | |
global.expect = require('chai').expect; | |
// prepare environment | |
global. it = lab.it; | |
global.describe = lab.describe; | |
global.before = lab.before; | |
global.beforeEach = lab.beforeEach; |
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
// [GET] /user/{id} | |
UserController.prototype.get = function (request, reply) { | |
let id = request.params.id; | |
this.model.findOneAsync({_id: id}) | |
.then((user) => { | |
if (!user) { | |
return reply.notFound('User not found for the id: '+id); | |
} |
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
'use strict'; | |
const Boom = require('boom'); | |
exports.register = register; | |
exports.register.attributes = { | |
name: 'reply-decorates', | |
version: '1.0.0' | |
}; |
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
// [GET] /user/{id} | |
UserController.prototype.get = function (request, reply) { | |
let id = request.params.id; | |
this.model.findOneAsync({_id: id}) | |
.then((user) => { | |
if (!user) { | |
reply(Boom.notFound()); | |
return; | |
} |
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
'use strict'; | |
const Boom = require('boom'); | |
exports.register = register; | |
exports.register.attributes = { | |
name: 'reply-decorates', | |
version: '1.0.0' | |
}; |
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
var date = require('date.js'); | |
var moment = require('moment'); | |
function buildInterval(interval) { | |
ret = date(interval); | |
return millisecondsTo(ret); | |
function millisecondsTo(date) { | |
date = moment(date).diff(moment()); |
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
var self = this; | |
return Promise | |
.bind(this) | |
.return(_.filter(data, 'to')) | |
.map(function(email){ | |
var rawEmail = new this.sendgrid.Email({ | |
to: email['to'], | |
from: raw['from'], | |
subject: raw['subject'], |
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
Promise | |
.bind(this) | |
.tap([1, 2, 4]) | |
.each(function(item){ | |
return new Promise(function(resolve, reject){ | |
someAsyncFn(item, function(err, data){ | |
if(err) reject(err); | |
resolve(data); | |
}); |
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
var Inflector = require('inflected'); | |
module.exports = function(emitter){ | |
var oldEmitter = emitter.emit; | |
emitter.emit = function(){ | |
var event = Inflector.camelize('before_' + arguments[0], false); | |
var args = Array.prototype.slice.call(arguments); | |
oldEmitter.apply(emitter, [event].concat(args)); |