Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save atomicsamurai/a37c0430a428703e6daf1c5160cb0782 to your computer and use it in GitHub Desktop.

Select an option

Save atomicsamurai/a37c0430a428703e6daf1c5160cb0782 to your computer and use it in GitHub Desktop.
Cypher for querying driver's access to trunk
MATCH (driver:User {name: 'Cathy'})
WITH driver
// find the trunk from the drive and the package
// the package and the location are the key to open the trunk
OPTIONAL MATCH driver_item_path=(driver)-[:DRIVES|INCLUDES*]-(item:Item {name: 'Item'})-[:DELIVER_TO]->(trunk:Door)
WITH driver_item_path,trunk
OPTIONAL MATCH item_work_path=(trunk)<-[:INCLUDES*..5]-(intermediate:Collection)-[:INCLUDES*..5]->(:Location {name: 'Work'})
USING JOIN ON intermediate
RETURN CASE
WHEN driver_item_path IS NULL THEN { result: false, advice: "Driver not authorized on package."}
WHEN item_work_path IS NOT NULL THEN { result: true, advice: "Driver authorized on package at current location."}
WHEN item_work_path IS NULL THEN { result: false, advice: "Driver not authorized on package at current location."}
ELSE false
END AS result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment