From f08b3e0ac530f19b78d8beb4c3c922871438a8de Mon Sep 17 00:00:00 2001 From: Jori Lallo Date: Wed, 7 Feb 2018 00:04:39 -0800 Subject: [PATCH] Renamed Document#atlasId finally --- server/api/documents.js | 12 ++++++------ server/api/documents.test.js | 2 +- .../20180207075429-rename-collection-atlasid.js | 9 +++++++++ server/models/Collection.js | 6 +++--- server/models/Collection.test.js | 14 +++++++------- server/models/Document.js | 2 +- server/presenters/document.js | 2 +- server/test/support.js | 2 +- 8 files changed, 29 insertions(+), 20 deletions(-) create mode 100644 server/migrations/20180207075429-rename-collection-atlasid.js diff --git a/server/api/documents.js b/server/api/documents.js index 949dcb8c1..207768c0e 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, atlasId: collection }; + if (collection) where = { ...where, collectionId: 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, - atlasId: ownerCollection.id, + collectionId: ownerCollection.id, }, }); if (!parentDocumentObj) @@ -224,7 +224,7 @@ router.post('documents.create', auth(), async ctx => { const newDocument = await Document.create({ parentDocumentId: parentDocumentObj.id, - atlasId: ownerCollection.id, + collectionId: 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.atlasId); + const collection = await Collection.findById(document.collectionId); 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.atlasId !== document.atlasId) + if (!parent || parent.collectionId !== document.collectionId) 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.atlasId); + const collection = await Collection.findById(document.collectionId); authDocumentForUser(ctx, document); diff --git a/server/api/documents.test.js b/server/api/documents.test.js index 509050578..97af24705 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.atlasId }, + body: { token: user.getJwtToken(), collection: document.collectionId }, }); const body = await res.json(); diff --git a/server/migrations/20180207075429-rename-collection-atlasid.js b/server/migrations/20180207075429-rename-collection-atlasid.js new file mode 100644 index 000000000..3ced8f5cd --- /dev/null +++ b/server/migrations/20180207075429-rename-collection-atlasid.js @@ -0,0 +1,9 @@ +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 2b32e91e4..e3ccd7e63 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, - atlasId: collection.id, + collectionId: 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: 'atlasId', + foreignKey: 'collectionId', onDelete: 'cascade', }); Collection.belongsTo(models.Team, { @@ -98,7 +98,7 @@ Collection.associate = models => { Collection.addHook('afterDestroy', async model => { await Document.destroy({ where: { - atlasId: model.id, + collectionId: model.id, }, }); }); diff --git a/server/models/Collection.test.js b/server/models/Collection.test.js index 1327b0aeb..afb65a4ac 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, - atlasId: collection.id, + collectionId: 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, - atlasId: collection.id, + collectionId: 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: { - atlasId: collection.id, + collectionId: 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, - atlasId: collection.id, + collectionId: 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: { - atlasId: collection.id, + collectionId: 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, - atlasId: collection.id, + collectionId: collection.id, teamId: collection.teamId, userId: collection.creatorId, lastModifiedById: collection.creatorId, @@ -251,7 +251,7 @@ describe('#removeDocument', () => { const collectionDocuments = await Document.findAndCountAll({ where: { - atlasId: collection.id, + collectionId: collection.id, }, }); expect(collectionDocuments.count).toBe(2); diff --git a/server/models/Document.js b/server/models/Document.js index a15073261..826cb2280 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: 'atlasId', + foreignKey: 'collectionId', onDelete: 'cascade', }); Document.belongsTo(models.User, { diff --git a/server/presenters/document.js b/server/presenters/document.js index 2120cf9d4..d0d8932db 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.atlasId, + collectionId: document.collectionId, collaboratorCount: undefined, collection: undefined, views: undefined, diff --git a/server/test/support.js b/server/test/support.js index 7b1564e38..51f4dfac4 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, - atlasId: collection.id, + collectionId: collection.id, teamId: team.id, userId: collection.creatorId, lastModifiedById: collection.creatorId,