Last active
August 29, 2015 14:08
-
-
Save jedahan/ef5fcff1fb7e4ad7500c to your computer and use it in GitHub Desktop.
how to refactor to use middleware?
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 /participants | |
app.get '/participants', parseTimestamp, -> | |
options = timestamp: $gte: (+ @query?.start or 0) | |
@body = mustache.render table_template, participants: yield participants.find(options) | |
# GET /participants.json | |
app.get '/participants.json', parseTimestamp, -> | |
options = timestamp: $gte: (+ @query?.start or 0) | |
@body = yield participants.find(options) | |
# GET /participants.csv | |
app.get '/participants.csv', parseTimestamp, -> | |
options = timestamp: $gte: (+ @query?.start or 0) | |
@body = yield json2csv data: yield participants.find(options) | |
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
app.get('/participants', parseTimestamp, function*() { | |
var options = { | |
timestamp: { | |
$gte: +(this.query.start || 0) | |
} | |
}; | |
return this.body = mustache.render(table_template, { | |
participants: (yield participants.find(options)) | |
}); | |
}); | |
app.get('/participants.json', parseTimestamp, function*() { | |
var options = { | |
timestamp: { | |
$gte: +(this.query.start || 0) | |
} | |
}; | |
return this.body = (yield participants.find(options)); | |
}); | |
app.get('/participants.csv', parseTimestamp, function*() { | |
var options = { | |
timestamp: { | |
$gte: +(this.query.start || 0) | |
} | |
}; | |
return this.body = (yield json2csv({ | |
data: (yield participants.find(options)) | |
})); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment