       unless oldRel.property 'removed'
         n1 = db.nodes form.from
         n2 = db.nodes form.to
-        n1.setProperty {updatedAt}
-        n2.setProperty {updatedAt}
         if form.type isnt oldRel.get().type
           oldRel.setProperties
             removed: true

  db = new Neo4jDB 'http://localhost:7474', {username: 'neo4j', password: '1234'}

  unless db.queryOne 'MATCH (n) RETURN n LIMIT 1'
    db.querySync 'WITH ["Andres","Wes","Rik","Mark","Peter","Kenny","Michael","Stefan","Max","Chris"] AS names FOREACH (r IN range(0,19) | CREATE (:Person {removed: false, updatedAt: timestamp(), createdAt: timestamp(), name:names[r % size(names)]+" "+r}));'


  Meteor.methods
    graph: (timestamp = 0) -> 
      check timestamp, Number
      nodes = []
      edges = []

      visGraph = 
        nodes : []
        edges: []
      graph = db.graph('MATCH (a)-[r]-(b), (n) WHERE n.createdAt >= {timestamp} OR n.updatedAt >= {timestamp} RETURN DISTINCT n, r', {timestamp}).fetch()

      if graph.length is 0
        graph = db.graph('MATCH n WHERE n.createdAt >= {timestamp} OR n.updatedAt >= {timestamp} RETURN DISTINCT n', {timestamp}).fetch()

      for row in graph
        if row.nodes.length > 0
          for n in row.nodes
            node = 
              id: n.id
              labels: n.labels
              label: n.properties.name
              group: n.labels[0]
            node = _.extend node, n.properties
            nodes[n.id] = node

        if row.relationships.length > 0
          for r in row.relationships
            edge = 
              id: r.id
              from: r.startNode or r.start
              to: r.endNode or r.end
              type: r.type
              label: r.type
              arrows: 'to'
              group: r.type
            edges[r.id] = _.extend edge, r.properties

      visGraph.edges = (value for key, value of edges)
      visGraph.nodes = (value for key, value of nodes)

      return {updatedAt: +new Date, data: visGraph}

    createNode: (form) ->
      check form, Object
      updatedAt = +new Date
      n = db.nodes({description: form.description, name: form.name, createdAt: updatedAt, updatedAt}).replaceLabels([form.label]).get()
      n.label = n.name
      n.group = n.labels[0]
      n

      updatedAt = +new Date
      r = db.getRelation id
      _r = r.get()

      unless r.property 'removed'
        r.setProperties
