Skip to content

Instantly share code, notes, and snippets.

@lymanlai
Created December 16, 2013 09:30
Show Gist options
  • Save lymanlai/7984430 to your computer and use it in GitHub Desktop.
Save lymanlai/7984430 to your computer and use it in GitHub Desktop.
Waterfall
function Waterfall(tasks, cb) {
async.waterfall(tasks, function(err, result){
var statusHash = {
not_validate: 403,
user_not_login: 401,
permission_deny: 401
};
if (!result) {
result = err;
}
if (statusHash[err]) {
cb( 'done', {status: statusHash[err], data: result} );
} else {
cb( err, result );
}
});
}
server.post(prefix, function (req, res, next) {
var connection = null;
Waterfall([
getDbHandle,
function(args, cb){
connection = args.connection;
args = {
connection : connection,
itemId: req.body.itemId,
parentId: req.body.parentId,
type: req.body.type,
content: req.body.content
};
cb(null, args);
},
User.isLogin,
Yaha.item,
Yaha.Reply.parentItem,
Yaha.Reply.add,
Yaha.Reply.parentItemUpdate,
Yaha.update,
], function(err, result){
releaseDbHandle(connection);
if (err == 'done') return res.send(result.status, result.data);
var status = 200
, output = {}
;
if (err) {
status = 403;
output = {err: err};
}
output.data = result.replyData;
res.send(status, output);
});
return next();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment