Merge pull request #304 from jorilallo/jori/rm-navigationtree

Removed legacy navigationtree
This commit is contained in:
Jori Lallo
2017-10-15 18:42:49 -07:00
committed by GitHub
4 changed files with 17 additions and 28 deletions

View File

@@ -0,0 +1,12 @@
module.exports = {
up: function(queryInterface, Sequelize) {
queryInterface.removeColumn('collections', 'navigationTree');
},
down: function(queryInterface, Sequelize) {
queryInterface.addColumn('collections', 'navigationTree', {
type: Sequelize.JSONB,
allowNull: true,
});
},
};

View File

@@ -29,7 +29,6 @@ const Collection = sequelize.define(
creatorId: DataTypes.UUID,
/* type: atlas */
navigationTree: DataTypes.JSONB, // legacy
documentStructure: DataTypes.JSONB,
},
{
@@ -98,28 +97,6 @@ Collection.prototype.getUrl = function() {
return `/collections/${this.id}`;
};
Collection.prototype.getDocumentsStructure = async function() {
// Lazy fill this.documentStructure - TMP for internal release
if (!this.documentStructure) {
this.documentStructure = this.navigationTree.children;
// Remove parent references from all root documents
await this.navigationTree.children.forEach(async ({ id }) => {
const document = await Document.findById(id);
document.parentDocumentId = null;
await document.save();
});
// Remove root document
const rootDocument = await Document.findById(this.navigationTree.id);
await rootDocument.destroy();
await this.save();
}
return this.documentStructure;
};
Collection.prototype.addDocumentToStructure = async function(
document,
index,

View File

@@ -19,7 +19,7 @@ async function present(ctx: Object, collection: Collection) {
};
if (collection.type === 'atlas') {
data.documents = await collection.getDocumentsStructure();
data.documents = collection.documentStructure;
}
if (collection.documents) {