-
-
Save laser/390eddc614664999f42c to your computer and use it in GitHub Desktop.
o
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
function ensure(notOkCode, notOkMessage, response, okFx) { | |
return function(err) { | |
if (err) { | |
response.status(notOkCode).json({"message": notOkMessage}); | |
} | |
else { | |
okFx.apply(okFx, Array.prototype.slice.call(arguments, 1)); | |
} | |
}; | |
} | |
var ensureFound = _.partial(ensure, 404, "Not Found"), | |
ensureValid = _.partial(ensure, 400, "Bad Request"); | |
expressRouter.get("/api/ledgers/:id", function(req, res) { | |
UserService.getLedgerById(req.params.id, ensureFound(ledger) { | |
res.status(200).json(ledger); | |
}); | |
}); | |
expressRouter.patch("/api/users/:id", function(req, res) { | |
UserService.getUserById(req.params.id, ensureFound(res, function(user) { | |
UserService.updateUser(user, req.body, ensureValid(res, function(updated) { | |
res.status(200).json(updated); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment