From 3528b2d0ef19a14bc697f5fa0178434e308992f8 Mon Sep 17 00:00:00 2001 From: Jori Lallo Date: Mon, 5 Jun 2017 01:00:29 -0700 Subject: [PATCH] Further cleanup --- server/api/collections.js | 21 --------------------- server/models/Collection.js | 12 +++--------- 2 files changed, 3 insertions(+), 30 deletions(-) diff --git a/server/api/collections.js b/server/api/collections.js index 6cc5f6ff..b129c085 100644 --- a/server/api/collections.js +++ b/server/api/collections.js @@ -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; diff --git a/server/models/Collection.js b/server/models/Collection.js index c582cda3..187c7036 100644 --- a/server/models/Collection.js +++ b/server/models/Collection.js @@ -116,15 +116,9 @@ const Collection = sequelize.define( const updateChildren = (children, document) => { const id = document.id; - console.log(id); + if (_.find(children, { id })) { - console.log(1); children = children.map(childDocument => { - console.log( - childDocument.id, - childDocument.title, - childDocument.id === id - ); if (childDocument.id === id) { childDocument = { ...document.toJSON(), @@ -134,7 +128,6 @@ const Collection = sequelize.define( return childDocument; }); } else { - console.log(2); children = children.map(childDocument => { return updateChildren(childDocument.children, id); }); @@ -146,7 +139,8 @@ const Collection = sequelize.define( this.documentStructure, document ); - this.save(); + + await this.save(); return this; },