Created
February 24, 2014 17:29
-
-
Save Janpot/9192792 to your computer and use it in GitHub Desktop.
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 reportRoute = function (req, res) { | |
// Validate input parameters | |
req.assert("userId").notEmpty().isInt(); | |
req.assert("url").notEmpty().isUrl(); | |
req.assert("reportId").notEmpty().isInt(); | |
// Validate input | |
var errors = req.validationErrors(); | |
// Handle errors | |
if (errors) { | |
res.json({ error: "Invalid parameter(s)", details: errors }); | |
} else { | |
// Map a few variables | |
var userId = parseInt(req.param("userId"), 10) | |
, url = req.param("url") | |
, reportId = req.param("reportId"); | |
reportStore.getReport(reportId, !!userId) | |
.then(function (report) { | |
return report.fetchCriteria() | |
}) | |
.then(function (report) { | |
if (report.isFallbackReport) { | |
// store the fallback | |
report.storeCriteria(); | |
} | |
// serialize report and send to client | |
report.createReadStream() | |
.pipe(new Mustachifier(/* ... */)) | |
}) | |
.fail(function () { | |
// send bad response | |
}); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment