diff --git a/server/api/documents.js b/server/api/documents.js index 207768c0..949dcb8c 100644 --- a/server/api/documents.js +++ b/server/api/documents.js @@ -20,7 +20,7 @@ router.post('documents.list', auth(), pagination(), async ctx => { const user = ctx.state.user; let where = { teamId: user.teamId }; - if (collection) where = { ...where, collectionId: collection }; + if (collection) where = { ...where, atlasId: collection }; const userId = user.id; const starredScope = { method: ['withStarred', userId] }; @@ -215,7 +215,7 @@ router.post('documents.create', auth(), async ctx => { parentDocumentObj = await Document.findOne({ where: { id: parentDocument, - collectionId: ownerCollection.id, + atlasId: ownerCollection.id, }, }); if (!parentDocumentObj) @@ -224,7 +224,7 @@ router.post('documents.create', auth(), async ctx => { const newDocument = await Document.create({ parentDocumentId: parentDocumentObj.id, - collectionId: ownerCollection.id, + atlasId: ownerCollection.id, teamId: user.teamId, userId: user.id, lastModifiedById: user.id, @@ -287,7 +287,7 @@ router.post('documents.move', auth(), async ctx => { if (index) ctx.assertPositiveInteger(index, 'index must be an integer (>=0)'); const document = await Document.findById(id); - const collection = await Collection.findById(document.collectionId); + const collection = await Collection.findById(document.atlasId); authDocumentForUser(ctx, document); @@ -297,7 +297,7 @@ router.post('documents.move', auth(), async ctx => { // Set parent document if (parentDocument) { const parent = await Document.findById(parentDocument); - if (!parent || parent.collectionId !== document.collectionId) + if (!parent || parent.atlasId !== document.atlasId) throw httpErrors.BadRequest( 'Invalid parentDocument (must be same collection)' ); @@ -324,7 +324,7 @@ router.post('documents.delete', auth(), async ctx => { ctx.assertPresent(id, 'id is required'); const document = await Document.findById(id); - const collection = await Collection.findById(document.collectionId); + const collection = await Collection.findById(document.atlasId); authDocumentForUser(ctx, document); diff --git a/server/api/documents.test.js b/server/api/documents.test.js index 97af2470..50905057 100644 --- a/server/api/documents.test.js +++ b/server/api/documents.test.js @@ -37,7 +37,7 @@ describe('#documents.list', async () => { it('should allow filtering by collection', async () => { const { user, document } = await seed(); const res = await server.post('/api/documents.list', { - body: { token: user.getJwtToken(), collection: document.collectionId }, + body: { token: user.getJwtToken(), collection: document.atlasId }, }); const body = await res.json(); diff --git a/server/migrations/20180207075429-rename-collection-atlasid.js b/server/migrations/20180207075429-rename-collection-atlasid.js deleted file mode 100644 index 3ced8f5c..00000000 --- a/server/migrations/20180207075429-rename-collection-atlasid.js +++ /dev/null @@ -1,9 +0,0 @@ -module.exports = { - up: async (queryInterface, Sequelize) => { - await queryInterface.renameColumn('documents', 'atlasId', 'collectionId'); - }, - - down: async (queryInterface, Sequelize) => { - await queryInterface.renameColumn('documents', 'collectionId', 'atlasId'); - }, -}; diff --git a/server/models/Collection.js b/server/models/Collection.js index e3ccd7e6..2b32e91e 100644 --- a/server/models/Collection.js +++ b/server/models/Collection.js @@ -53,7 +53,7 @@ const Collection = sequelize.define( // Create intro document if first collection for team const document = await Document.create({ parentDocumentId: null, - collectionId: collection.id, + atlasId: collection.id, teamId: collection.teamId, userId: collection.creatorId, lastModifiedById: collection.creatorId, @@ -77,7 +77,7 @@ const Collection = sequelize.define( Collection.associate = models => { Collection.hasMany(models.Document, { as: 'documents', - foreignKey: 'collectionId', + foreignKey: 'atlasId', onDelete: 'cascade', }); Collection.belongsTo(models.Team, { @@ -98,7 +98,7 @@ Collection.associate = models => { Collection.addHook('afterDestroy', async model => { await Document.destroy({ where: { - collectionId: model.id, + atlasId: model.id, }, }); }); diff --git a/server/models/Collection.test.js b/server/models/Collection.test.js index afb65a4a..1327b0ae 100644 --- a/server/models/Collection.test.js +++ b/server/models/Collection.test.js @@ -119,7 +119,7 @@ describe('#updateDocument', () => { // Add a child for testing const newDocument = await Document.create({ parentDocumentId: document.id, - collectionId: collection.id, + atlasId: collection.id, teamId: collection.teamId, userId: collection.creatorId, lastModifiedById: collection.creatorId, @@ -155,7 +155,7 @@ describe('#moveDocument', () => { // Add a child for testing const newDocument = await Document.create({ parentDocumentId: document.id, - collectionId: collection.id, + atlasId: collection.id, teamId: collection.teamId, userId: collection.creatorId, lastModifiedById: collection.creatorId, @@ -190,7 +190,7 @@ describe('#removeDocument', () => { // Verify that the document was removed const collectionDocuments = await Document.findAndCountAll({ where: { - collectionId: collection.id, + atlasId: collection.id, }, }); expect(collectionDocuments.count).toBe(1); @@ -202,7 +202,7 @@ describe('#removeDocument', () => { // Add a child for testing const newDocument = await Document.create({ parentDocumentId: document.id, - collectionId: collection.id, + atlasId: collection.id, teamId: collection.teamId, userId: collection.creatorId, lastModifiedById: collection.creatorId, @@ -218,7 +218,7 @@ describe('#removeDocument', () => { expect(collection.documentStructure.length).toBe(1); const collectionDocuments = await Document.findAndCountAll({ where: { - collectionId: collection.id, + atlasId: collection.id, }, }); expect(collectionDocuments.count).toBe(1); @@ -230,7 +230,7 @@ describe('#removeDocument', () => { // Add a child for testing const newDocument = await Document.create({ parentDocumentId: document.id, - collectionId: collection.id, + atlasId: collection.id, teamId: collection.teamId, userId: collection.creatorId, lastModifiedById: collection.creatorId, @@ -251,7 +251,7 @@ describe('#removeDocument', () => { const collectionDocuments = await Document.findAndCountAll({ where: { - collectionId: collection.id, + atlasId: collection.id, }, }); expect(collectionDocuments.count).toBe(2); diff --git a/server/models/Document.js b/server/models/Document.js index 826cb228..a1507326 100644 --- a/server/models/Document.js +++ b/server/models/Document.js @@ -116,7 +116,7 @@ const Document = sequelize.define( Document.associate = models => { Document.belongsTo(models.Collection, { as: 'collection', - foreignKey: 'collectionId', + foreignKey: 'atlasId', onDelete: 'cascade', }); Document.belongsTo(models.User, { diff --git a/server/presenters/document.js b/server/presenters/document.js index d0d8932d..2120cf9d 100644 --- a/server/presenters/document.js +++ b/server/presenters/document.js @@ -39,7 +39,7 @@ async function present(ctx: Object, document: Document, options: ?Options) { collaborators: [], starred: !!(document.starred && document.starred.length), revision: document.revisionCount, - collectionId: document.collectionId, + collectionId: document.atlasId, collaboratorCount: undefined, collection: undefined, views: undefined, diff --git a/server/test/support.js b/server/test/support.js index 51f4dfac..7b1564e3 100644 --- a/server/test/support.js +++ b/server/test/support.js @@ -62,7 +62,7 @@ const seed = async () => { const document = await Document.create({ parentDocumentId: null, - collectionId: collection.id, + atlasId: collection.id, teamId: team.id, userId: collection.creatorId, lastModifiedById: collection.creatorId,