secret
Created

  • Download Gist
0_server.coffee
CoffeeScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
app.get '/view', requireUser, (req, res, next) ->
user = req.session.user
User.find user.uid, (err, obj) =>
return next(err) if err?
if obj?
obj.getFriends user, (err, friends) =>
return next(err) if err?
async.map friends, (item, cb) =>
User.find item, cb
, (err, friendsTags) =>
next(err) if err?
friendsTags = (friend.attrs for friend in friendsTags when friend?)
res.render 'view'
user: obj.attrs
friends: _(friendsTags).sortBy (u) -> u.name.toLowerCase()
else
res.redirect '/edit'
1_server-iced.coffee
CoffeeScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
app.get '/view', requireUser, (req, res, next) ->
user = req.session.user
await User.find user.uid, defer(err, obj)
return next(err) if err?
if obj?
await obj.getFriends user, defer(err, friends)
return next(err) if err?
friendsTags = []
await
for item, i in friends
User.find item, defer(err, friendsTags[i])
friendsTags = (friend.attrs for friend in friendsTags when friend?)
res.render 'view'
user: obj.attrs
friends: _(friendsTags).sortBy (u) -> u.name.toLowerCase()
else
res.redirect '/edit'

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.