Further cleanup

This commit is contained in:
Jori Lallo
2017-06-05 01:00:29 -07:00
parent 1be0ff8105
commit 3528b2d0ef
2 changed files with 3 additions and 30 deletions

View File

@ -74,25 +74,4 @@ router.post('collections.list', auth(), pagination(), async ctx => {
}; };
}); });
router.post('collections.updateNavigationTree', auth(), async ctx => {
const { id, tree } = ctx.body;
ctx.assertPresent(id, 'id is required');
const user = ctx.state.user;
const atlas = await Collection.findOne({
where: {
id,
teamId: user.teamId,
},
});
if (!atlas) throw httpErrors.NotFound();
await atlas.updateNavigationTree(tree);
ctx.body = {
data: await presentCollection(ctx, atlas, true),
};
});
export default router; export default router;

View File

@ -116,15 +116,9 @@ const Collection = sequelize.define(
const updateChildren = (children, document) => { const updateChildren = (children, document) => {
const id = document.id; const id = document.id;
console.log(id);
if (_.find(children, { id })) { if (_.find(children, { id })) {
console.log(1);
children = children.map(childDocument => { children = children.map(childDocument => {
console.log(
childDocument.id,
childDocument.title,
childDocument.id === id
);
if (childDocument.id === id) { if (childDocument.id === id) {
childDocument = { childDocument = {
...document.toJSON(), ...document.toJSON(),
@ -134,7 +128,6 @@ const Collection = sequelize.define(
return childDocument; return childDocument;
}); });
} else { } else {
console.log(2);
children = children.map(childDocument => { children = children.map(childDocument => {
return updateChildren(childDocument.children, id); return updateChildren(childDocument.children, id);
}); });
@ -146,7 +139,8 @@ const Collection = sequelize.define(
this.documentStructure, this.documentStructure,
document document
); );
this.save();
await this.save();
return this; return this;
}, },