Skip to content

Instantly share code, notes, and snippets.

@nikaspran
Created October 23, 2013 19:11
Show Gist options
  • Save nikaspran/7124744 to your computer and use it in GitHub Desktop.
Save nikaspran/7124744 to your computer and use it in GitHub Desktop.
server.get('/api/relations', function (req, res, next) {
var predicates = [];
if (req.query.type) {
predicates.push(Predicates.eq('type', req.query.type));
}
if (req.query.sourceId) {
predicates.push(Predicates.eq('sourceId', req.query.sourceId));
}
if (req.query.targetId) {
predicates.push(Predicates.eq('targetId', req.query.targetId));
}
if (req.query.eitherId) {
predicates.push(Predicates.or(
Predicates.eq('sourceId', req.query.eitherId),
Predicates.eq('targetId', req.query.eitherId)));
}
Relation.filter(function (doc) {
return Predicates.all(predicates, doc);
}, function (err, result) {
if (err) {
return next(err);
}
res.send(result);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment