Last active
August 29, 2015 14:25
-
-
Save designfrontier/fb95b0a212f55554a09b to your computer and use it in GitHub Desktop.
bernstein real world-ish with pseudo code
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 userCreationStack = bernstein.create([ | |
function (data, orig, next){ | |
var imageProm = imageServiceWrapper.sliceAndDice(data.image); | |
imageProm.then(function (imageData) { | |
data.images = imageData; | |
next(data); | |
}); | |
} | |
, function (data, orig, next) { | |
next(data.quote = getRandomQuote()); | |
} | |
, function (data, orig) { | |
data.type = "free"; | |
data.createdData = new Date(); | |
data.interactions = 0; | |
return new Promise(function (resolve, reject) { | |
var userProm = userService.save(data); | |
userProm.then(function (userObj) { | |
resolve(userObj); | |
}); | |
}); | |
} | |
]); | |
//inside some handler for a route... | |
var user = userCreationStack(req.body); | |
user.then(function (data) { | |
response.send(data); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment