mbouclas / loopback-ds-tree-mixin

Transform a loopback model into a tree using the Array of Ancestors pattern
MIT License
6 stars 4 forks source link

moveNode parameter #2

Closed Jcbobo closed 5 years ago

Jcbobo commented 7 years ago

is possible to pass as parameter (both for the parent and for the node) just the id of the nodes?

mi question is for coherence respect the other functionality

mbouclas commented 7 years ago

Not 100% sure what you're asking but check this in case i got it right

As you can see you can eihter do addNode({permalink: 'a-category'}... or Category.addNode('5616204f1c6a443c256c7a2f'...

Same goes for retrieving the tree

Category.asTree({category : 'Books'})

OR

Category.asTree('5616204f1c6a443c256c7a2f')

OR

Category.findOne({where : {category : 'Books'}})
.then(function(Parent) {
//note, that we will use the Parent.id in our query to locate children
  Category.asTree(Parent)
    .then(function (results) {
    console.log(results);
  });
});
Jcbobo commented 7 years ago

the moveNode method from the explorer (so curl/rests) the parent and the node need to be passed in the form of where parameter ({"id":"58c6b769189b4e1b380e0395"} ) the addNode method insteand can be called direcly passing only the id

mbouclas commented 7 years ago

I had issues with that on the way loopback handles the ctx object. I might have another crack at it cause in theory this is what i'm doing in the code. There is one method for locating parents/children and it is always with either and object, a loopback object or a string ID.

For some reason though, in the move method something always went wrong and i had to drop it cause i had it pointed somewhere deep in the framework (it's been like a year since i touched this). So i might try it again at some point soon.