Created
October 30, 2013 19:15
-
-
Save nikaspran/7238432 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/entities', function (req, res, next) { | |
var criteria = new Predicates.Criteria(server.db); | |
criteria.select('Entity').from('Entity'); | |
if (req.query.type) { | |
criteria.add(Predicates.eq('Entity.type', req.query.type)); | |
} | |
if (req.query.name) { //TODO: escape regex | |
criteria.add(Predicates.match('Entity.name', '^' + req.query.name)); | |
} | |
if (req.query.sourceOf){ | |
criteria.from('Relation'); | |
criteria.eqJoin('Entity', 'sourceId', 'Entity'); | |
criteria.add(Predicates.eq('Relation.type', req.query.sourceOf)); | |
} | |
Entity.execute(criteria.all(), 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