Following codes doesnt render view.Please help thanks! probably mistakes
with callbacks
routes handleRequest url set in another file. http request is
profile = require(routes/profile.js);
app.get(/profile/:uid, profile.handelRequest)
*routes/profile.js*
function handleRequest(req, res, next) {
var fid = req.params.uid;
UserModel.by_uid(fid, function (err, friend) {
if (err || !friend) return next(err || new Error('no such user: ' +
uid));
var frienduser = friend.data();
var useremail = req.session.user.email;
console.log('user email ' + useremail);
UserModel.by_email(useremail, function (err, userNode) {
if (err) util.log(err);
var user = userNode.data();
UserModel.checkRelationship(user, fid , function (err, relation) {
if (!err && relation) {
console.log('relationship ' + JSON.stringify(relation));
var locals = {
user: req.session.user,
frienduser: frienduser,
};
res.render('friend-profile', locals);
}
next(err);
});
});
});
}
( UserModel )
User.checkRelationship = function (user, fid, callback) {
var uids = [user.uid, fid];
async.map(uids, User.by_uid, function (err, usernodes) {
if (!err && usernodes && usernodes.length) {
User.relsCheck(usernodes, function (err, rels) {
if (!err && rels) {
callback(null, rels);
} else {
callback(err || new Error('relationships does\'nt exists'));
}
});
} else {
callback(err || new Error('Unable to fetch user nodes: ' +
uids.join(',')));
}
});
};
ser.relsCheck = function (nodes, callback) {
if (nodes.length !== 2) {
return callback(new Error('Invalid/insufficient arguments'));
}
var query = [
'START user=node({userId}), other=node({otherId})',
'MATCH (user) -[rels?]-> (other)',
'RETURN TYPE(rels)'
].join('\n');
var params = {
userId: nodes[0].node().id,
otherId: nodes[1].node().id,
};
console.log('user id other id ' + JSON.stringify(params));
db.query(query, params, callback);
};
--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.