Created
October 23, 2013 19:11
-
-
Save nikaspran/7124744 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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