Manually create a new document for second collection
This commit is contained in:
@ -39,19 +39,29 @@ const Collection = sequelize.define(
|
||||
collection.urlId = collection.urlId || randomstring.generate(10);
|
||||
},
|
||||
afterCreate: async collection => {
|
||||
const team = await collection.getTeam();
|
||||
const collections = await team.getCollections();
|
||||
|
||||
// Don't auto-create for journal types, yet
|
||||
if (collection.type !== 'atlas') return;
|
||||
|
||||
const document = await Document.create({
|
||||
parentDocumentId: null,
|
||||
atlasId: collection.id,
|
||||
teamId: collection.teamId,
|
||||
userId: collection.creatorId,
|
||||
lastModifiedById: collection.creatorId,
|
||||
createdById: collection.creatorId,
|
||||
title: 'Introduction',
|
||||
text: '# Introduction\n\nLets get started...',
|
||||
});
|
||||
collection.documentStructure = [document.toJSON()];
|
||||
if (collections.length === 0) {
|
||||
// Create intro document if first collection for team
|
||||
const document = await Document.create({
|
||||
parentDocumentId: null,
|
||||
atlasId: collection.id,
|
||||
teamId: collection.teamId,
|
||||
userId: collection.creatorId,
|
||||
lastModifiedById: collection.creatorId,
|
||||
createdById: collection.creatorId,
|
||||
title: 'Introduction',
|
||||
text: '# Introduction\n\nLets get started...',
|
||||
});
|
||||
collection.documentStructure = [document.toJSON()];
|
||||
} else {
|
||||
// Let user create first document
|
||||
collection.documentStructure = [];
|
||||
}
|
||||
await collection.save();
|
||||
},
|
||||
},
|
||||
@ -65,6 +75,9 @@ Collection.associate = models => {
|
||||
as: 'documents',
|
||||
foreignKey: 'atlasId',
|
||||
});
|
||||
Collection.belongsTo(models.Team, {
|
||||
as: 'team',
|
||||
});
|
||||
Collection.addScope('withRecentDocuments', {
|
||||
include: [
|
||||
{
|
||||
|
Reference in New Issue
Block a user