More tree
This commit is contained in:
@@ -122,7 +122,7 @@ module.exports = {
|
||||
defaultValue: null,
|
||||
special: [],
|
||||
primaryKey: false },
|
||||
rootDocumentForId:
|
||||
parentDocumentForId:
|
||||
{ type: 'UUID',
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
|
||||
@@ -34,10 +34,24 @@ const Atlas = sequelize.define('atlas', {
|
||||
// const slugifiedTitle = slug(this.title);
|
||||
// return `${slugifiedTitle}-${this.urlId}`;
|
||||
// }
|
||||
async buildStructure() {
|
||||
// TODO
|
||||
const rootDocument = await Document.findOne({ where: {
|
||||
parentDocumentForId: null,
|
||||
atlasId: this.id,
|
||||
}});
|
||||
|
||||
return {
|
||||
name: rootDocument.title,
|
||||
id: rootDocument.id,
|
||||
url: rootDocument.getUrl(),
|
||||
children: null,
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Atlas.hasMany(Document, { as: 'documents', foreignKey: 'atlasId' });
|
||||
Atlas.hasOne(Document, { as: 'rootDocument', foreignKey: 'rootDocumentForId', constraints: false });
|
||||
Atlas.hasOne(Document, { as: 'parentDocument', foreignKey: 'parentDocumentForId', constraints: false });
|
||||
|
||||
export default Atlas;
|
||||
|
||||
@@ -45,7 +45,10 @@ const Document = sequelize.define('document', {
|
||||
buildUrl() {
|
||||
const slugifiedTitle = slug(this.title);
|
||||
return `${slugifiedTitle}-${this.urlId}`;
|
||||
}
|
||||
},
|
||||
getUrl() {
|
||||
return `/documents/${ this.id }`;
|
||||
},
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -31,6 +31,11 @@ export function presentAtlas(atlas, includeRecentDocuments=false) {
|
||||
type: atlas.type,
|
||||
}
|
||||
|
||||
if (atlas.type === 'atlas') {
|
||||
// Todo replace with `.atlasStructure`
|
||||
data.structure = await atlas.buildStructure();
|
||||
}
|
||||
|
||||
if (includeRecentDocuments) {
|
||||
const documents = await Document.findAll({
|
||||
where: {
|
||||
|
||||
Reference in New Issue
Block a user