Renamed Document#atlasId finally
This commit is contained in:
@ -20,7 +20,7 @@ router.post('documents.list', auth(), pagination(), async ctx => {
|
|||||||
|
|
||||||
const user = ctx.state.user;
|
const user = ctx.state.user;
|
||||||
let where = { teamId: user.teamId };
|
let where = { teamId: user.teamId };
|
||||||
if (collection) where = { ...where, atlasId: collection };
|
if (collection) where = { ...where, collectionId: collection };
|
||||||
|
|
||||||
const userId = user.id;
|
const userId = user.id;
|
||||||
const starredScope = { method: ['withStarred', userId] };
|
const starredScope = { method: ['withStarred', userId] };
|
||||||
@ -215,7 +215,7 @@ router.post('documents.create', auth(), async ctx => {
|
|||||||
parentDocumentObj = await Document.findOne({
|
parentDocumentObj = await Document.findOne({
|
||||||
where: {
|
where: {
|
||||||
id: parentDocument,
|
id: parentDocument,
|
||||||
atlasId: ownerCollection.id,
|
collectionId: ownerCollection.id,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
if (!parentDocumentObj)
|
if (!parentDocumentObj)
|
||||||
@ -224,7 +224,7 @@ router.post('documents.create', auth(), async ctx => {
|
|||||||
|
|
||||||
const newDocument = await Document.create({
|
const newDocument = await Document.create({
|
||||||
parentDocumentId: parentDocumentObj.id,
|
parentDocumentId: parentDocumentObj.id,
|
||||||
atlasId: ownerCollection.id,
|
collectionId: ownerCollection.id,
|
||||||
teamId: user.teamId,
|
teamId: user.teamId,
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
lastModifiedById: 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)');
|
if (index) ctx.assertPositiveInteger(index, 'index must be an integer (>=0)');
|
||||||
|
|
||||||
const document = await Document.findById(id);
|
const document = await Document.findById(id);
|
||||||
const collection = await Collection.findById(document.atlasId);
|
const collection = await Collection.findById(document.collectionId);
|
||||||
|
|
||||||
authDocumentForUser(ctx, document);
|
authDocumentForUser(ctx, document);
|
||||||
|
|
||||||
@ -297,7 +297,7 @@ router.post('documents.move', auth(), async ctx => {
|
|||||||
// Set parent document
|
// Set parent document
|
||||||
if (parentDocument) {
|
if (parentDocument) {
|
||||||
const parent = await Document.findById(parentDocument);
|
const parent = await Document.findById(parentDocument);
|
||||||
if (!parent || parent.atlasId !== document.atlasId)
|
if (!parent || parent.collectionId !== document.collectionId)
|
||||||
throw httpErrors.BadRequest(
|
throw httpErrors.BadRequest(
|
||||||
'Invalid parentDocument (must be same collection)'
|
'Invalid parentDocument (must be same collection)'
|
||||||
);
|
);
|
||||||
@ -324,7 +324,7 @@ router.post('documents.delete', auth(), async ctx => {
|
|||||||
ctx.assertPresent(id, 'id is required');
|
ctx.assertPresent(id, 'id is required');
|
||||||
|
|
||||||
const document = await Document.findById(id);
|
const document = await Document.findById(id);
|
||||||
const collection = await Collection.findById(document.atlasId);
|
const collection = await Collection.findById(document.collectionId);
|
||||||
|
|
||||||
authDocumentForUser(ctx, document);
|
authDocumentForUser(ctx, document);
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ describe('#documents.list', async () => {
|
|||||||
it('should allow filtering by collection', async () => {
|
it('should allow filtering by collection', async () => {
|
||||||
const { user, document } = await seed();
|
const { user, document } = await seed();
|
||||||
const res = await server.post('/api/documents.list', {
|
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();
|
const body = await res.json();
|
||||||
|
|
||||||
|
@ -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');
|
||||||
|
},
|
||||||
|
};
|
@ -53,7 +53,7 @@ const Collection = sequelize.define(
|
|||||||
// Create intro document if first collection for team
|
// Create intro document if first collection for team
|
||||||
const document = await Document.create({
|
const document = await Document.create({
|
||||||
parentDocumentId: null,
|
parentDocumentId: null,
|
||||||
atlasId: collection.id,
|
collectionId: collection.id,
|
||||||
teamId: collection.teamId,
|
teamId: collection.teamId,
|
||||||
userId: collection.creatorId,
|
userId: collection.creatorId,
|
||||||
lastModifiedById: collection.creatorId,
|
lastModifiedById: collection.creatorId,
|
||||||
@ -77,7 +77,7 @@ const Collection = sequelize.define(
|
|||||||
Collection.associate = models => {
|
Collection.associate = models => {
|
||||||
Collection.hasMany(models.Document, {
|
Collection.hasMany(models.Document, {
|
||||||
as: 'documents',
|
as: 'documents',
|
||||||
foreignKey: 'atlasId',
|
foreignKey: 'collectionId',
|
||||||
onDelete: 'cascade',
|
onDelete: 'cascade',
|
||||||
});
|
});
|
||||||
Collection.belongsTo(models.Team, {
|
Collection.belongsTo(models.Team, {
|
||||||
@ -98,7 +98,7 @@ Collection.associate = models => {
|
|||||||
Collection.addHook('afterDestroy', async model => {
|
Collection.addHook('afterDestroy', async model => {
|
||||||
await Document.destroy({
|
await Document.destroy({
|
||||||
where: {
|
where: {
|
||||||
atlasId: model.id,
|
collectionId: model.id,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -119,7 +119,7 @@ describe('#updateDocument', () => {
|
|||||||
// Add a child for testing
|
// Add a child for testing
|
||||||
const newDocument = await Document.create({
|
const newDocument = await Document.create({
|
||||||
parentDocumentId: document.id,
|
parentDocumentId: document.id,
|
||||||
atlasId: collection.id,
|
collectionId: collection.id,
|
||||||
teamId: collection.teamId,
|
teamId: collection.teamId,
|
||||||
userId: collection.creatorId,
|
userId: collection.creatorId,
|
||||||
lastModifiedById: collection.creatorId,
|
lastModifiedById: collection.creatorId,
|
||||||
@ -155,7 +155,7 @@ describe('#moveDocument', () => {
|
|||||||
// Add a child for testing
|
// Add a child for testing
|
||||||
const newDocument = await Document.create({
|
const newDocument = await Document.create({
|
||||||
parentDocumentId: document.id,
|
parentDocumentId: document.id,
|
||||||
atlasId: collection.id,
|
collectionId: collection.id,
|
||||||
teamId: collection.teamId,
|
teamId: collection.teamId,
|
||||||
userId: collection.creatorId,
|
userId: collection.creatorId,
|
||||||
lastModifiedById: collection.creatorId,
|
lastModifiedById: collection.creatorId,
|
||||||
@ -190,7 +190,7 @@ describe('#removeDocument', () => {
|
|||||||
// Verify that the document was removed
|
// Verify that the document was removed
|
||||||
const collectionDocuments = await Document.findAndCountAll({
|
const collectionDocuments = await Document.findAndCountAll({
|
||||||
where: {
|
where: {
|
||||||
atlasId: collection.id,
|
collectionId: collection.id,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
expect(collectionDocuments.count).toBe(1);
|
expect(collectionDocuments.count).toBe(1);
|
||||||
@ -202,7 +202,7 @@ describe('#removeDocument', () => {
|
|||||||
// Add a child for testing
|
// Add a child for testing
|
||||||
const newDocument = await Document.create({
|
const newDocument = await Document.create({
|
||||||
parentDocumentId: document.id,
|
parentDocumentId: document.id,
|
||||||
atlasId: collection.id,
|
collectionId: collection.id,
|
||||||
teamId: collection.teamId,
|
teamId: collection.teamId,
|
||||||
userId: collection.creatorId,
|
userId: collection.creatorId,
|
||||||
lastModifiedById: collection.creatorId,
|
lastModifiedById: collection.creatorId,
|
||||||
@ -218,7 +218,7 @@ describe('#removeDocument', () => {
|
|||||||
expect(collection.documentStructure.length).toBe(1);
|
expect(collection.documentStructure.length).toBe(1);
|
||||||
const collectionDocuments = await Document.findAndCountAll({
|
const collectionDocuments = await Document.findAndCountAll({
|
||||||
where: {
|
where: {
|
||||||
atlasId: collection.id,
|
collectionId: collection.id,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
expect(collectionDocuments.count).toBe(1);
|
expect(collectionDocuments.count).toBe(1);
|
||||||
@ -230,7 +230,7 @@ describe('#removeDocument', () => {
|
|||||||
// Add a child for testing
|
// Add a child for testing
|
||||||
const newDocument = await Document.create({
|
const newDocument = await Document.create({
|
||||||
parentDocumentId: document.id,
|
parentDocumentId: document.id,
|
||||||
atlasId: collection.id,
|
collectionId: collection.id,
|
||||||
teamId: collection.teamId,
|
teamId: collection.teamId,
|
||||||
userId: collection.creatorId,
|
userId: collection.creatorId,
|
||||||
lastModifiedById: collection.creatorId,
|
lastModifiedById: collection.creatorId,
|
||||||
@ -251,7 +251,7 @@ describe('#removeDocument', () => {
|
|||||||
|
|
||||||
const collectionDocuments = await Document.findAndCountAll({
|
const collectionDocuments = await Document.findAndCountAll({
|
||||||
where: {
|
where: {
|
||||||
atlasId: collection.id,
|
collectionId: collection.id,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
expect(collectionDocuments.count).toBe(2);
|
expect(collectionDocuments.count).toBe(2);
|
||||||
|
@ -116,7 +116,7 @@ const Document = sequelize.define(
|
|||||||
Document.associate = models => {
|
Document.associate = models => {
|
||||||
Document.belongsTo(models.Collection, {
|
Document.belongsTo(models.Collection, {
|
||||||
as: 'collection',
|
as: 'collection',
|
||||||
foreignKey: 'atlasId',
|
foreignKey: 'collectionId',
|
||||||
onDelete: 'cascade',
|
onDelete: 'cascade',
|
||||||
});
|
});
|
||||||
Document.belongsTo(models.User, {
|
Document.belongsTo(models.User, {
|
||||||
|
@ -39,7 +39,7 @@ async function present(ctx: Object, document: Document, options: ?Options) {
|
|||||||
collaborators: [],
|
collaborators: [],
|
||||||
starred: !!(document.starred && document.starred.length),
|
starred: !!(document.starred && document.starred.length),
|
||||||
revision: document.revisionCount,
|
revision: document.revisionCount,
|
||||||
collectionId: document.atlasId,
|
collectionId: document.collectionId,
|
||||||
collaboratorCount: undefined,
|
collaboratorCount: undefined,
|
||||||
collection: undefined,
|
collection: undefined,
|
||||||
views: undefined,
|
views: undefined,
|
||||||
|
@ -62,7 +62,7 @@ const seed = async () => {
|
|||||||
|
|
||||||
const document = await Document.create({
|
const document = await Document.create({
|
||||||
parentDocumentId: null,
|
parentDocumentId: null,
|
||||||
atlasId: collection.id,
|
collectionId: collection.id,
|
||||||
teamId: team.id,
|
teamId: team.id,
|
||||||
userId: collection.creatorId,
|
userId: collection.creatorId,
|
||||||
lastModifiedById: collection.creatorId,
|
lastModifiedById: collection.creatorId,
|
||||||
|
Reference in New Issue
Block a user