Created
November 15, 2012 07:44
-
-
Save thejhh/4077250 to your computer and use it in GitHub Desktop.
Usage of Neo4j query with promise support to list all nodes a user has read access
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
| /** Get available objects for current user */ | |
| server.get('/', function(req, res, next) { | |
| var username = req.authorization.basic.username; | |
| db_query([ | |
| 'START root=node(0)', | |
| 'MATCH root-[:USERS_REF]->uroot-[:USER]->user-[:ACCEPT_READ]->n', | |
| 'WHERE user.name = {username}', | |
| 'RETURN n' | |
| ], {'username': username}).then(function(results) { | |
| var nodes = []; | |
| if( results && results.length ) { | |
| foreach(results).each(function(node) { | |
| var n = node.data; | |
| n._id = node.id; | |
| nodes.push(n); | |
| }); | |
| } | |
| return next(nodes); | |
| }, function(err) { | |
| console.log('Neo4j query failed: ' + err); | |
| if(err.stack) console.log('stack: ' + err.stack); | |
| next(new restify.InternalError("Database query failed")); | |
| }); | |
| }); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Error message:
Neo4j query failed: Error: key not found: user