Created
August 15, 2013 23:07
-
-
Save otang/6245793 to your computer and use it in GitHub Desktop.
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
# Retrieves the root pages and their children (level 0 and level 1) | |
exports.getPages = (req, res) -> | |
getChildren = (page, callback) -> | |
models.Page.find({ parent_id: page._id }).sort({ name: 'asc' }).exec (err, children) -> | |
page.children = children || [] | |
callback(null, page) | |
models.Page.find({ parent_id: null }).sort({ name: 'asc' }).exec (err, pages) -> | |
async.map pages, getChildren, (err, results) -> | |
res.json results |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment