Skip to content

Instantly share code, notes, and snippets.

@artcommacode
Created January 16, 2014 23:25
Show Gist options
  • Save artcommacode/8465494 to your computer and use it in GitHub Desktop.
Save artcommacode/8465494 to your computer and use it in GitHub Desktop.
async.parallel({
/*collections: function (callback) {
Collection.find().populate('parent children').sort('position').exec(callback);
},*/
featured: function (callback) {
Page.findAndPopulate({
featured: true
}, callback);
},
whatsOn: function (callback) {
var whatsOn = [];
Collection.findOne({url: 'whats-on'}).populate('children', null, null, {sort: 'position'}).exec(function (error, collection) {
async.forEachSeries(collection.children, function (child, callback) {
Collection.findAndPopulate({_id: child._id}, function (error, child) {
if (child) whatsOn.push(child);
callback();
});
}, function (error) {
callback(error, whatsOn);
});
});
},
opportunities: function (callback) {
Collection.findAndPopulate({url: 'opportunities'}, callback);
},
news: function (callback) {
Collection.findAndPopulate({url: 'news'}, callback);
},
contact: function (callback) {
Collection.findAndPopulate({url: 'contact'}, callback);
},
about: function (callback) {
Collection.findAndPopulate({url: 'about'}, callback);
}
}, function (error, results) {
if (error) console.log(error);
if (results.news.pages.length) results.news.pages = results.news.pages.slice(0, 3);
res.render('client/views/index', {
whatsOn: results.whatsOn,
featured: results.featured,
opportunities: results.opportunities,
news: results.news,
contact: results.contact,
about: results.about,
collection: {url: 'index'}
});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment