Structures for atlases
This commit is contained in:
@ -56,4 +56,4 @@ router.post('atlases.list', auth(), pagination(), async (ctx) => {
|
||||
};
|
||||
});
|
||||
|
||||
export default router;
|
||||
export default router;
|
||||
|
@ -3,252 +3,193 @@
|
||||
module.exports = {
|
||||
up: function (queryInterface, Sequelize) {
|
||||
queryInterface.createTable('atlases', {
|
||||
id:
|
||||
{ type: 'UUID',
|
||||
allowNull: false,
|
||||
defaultValue: null,
|
||||
special: [],
|
||||
primaryKey: true },
|
||||
name:
|
||||
{ type: 'CHARACTER VARYING',
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
special: [],
|
||||
primaryKey: false },
|
||||
description:
|
||||
{ type: 'CHARACTER VARYING',
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
special: [],
|
||||
primaryKey: false },
|
||||
type:
|
||||
{ type: 'CHARACTER VARYING',
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
special: [],
|
||||
primaryKey: false },
|
||||
atlasStructure:
|
||||
{ type: 'JSONB',
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
special: [],
|
||||
primaryKey: false },
|
||||
createdAt:
|
||||
{ type: 'TIMESTAMP WITH TIME ZONE',
|
||||
allowNull: false,
|
||||
defaultValue: null,
|
||||
special: [],
|
||||
primaryKey: false },
|
||||
updatedAt:
|
||||
{ type: 'TIMESTAMP WITH TIME ZONE',
|
||||
allowNull: false,
|
||||
defaultValue: null,
|
||||
special: [],
|
||||
primaryKey: false },
|
||||
teamId:
|
||||
{ type: 'UUID',
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
special: [],
|
||||
primaryKey: false } }
|
||||
);
|
||||
id: {
|
||||
type: 'UUID',
|
||||
allowNull: false,
|
||||
primaryKey: true
|
||||
},
|
||||
name: {
|
||||
type: 'CHARACTER VARYING',
|
||||
allowNull: true,
|
||||
},
|
||||
description: {
|
||||
type: 'CHARACTER VARYING',
|
||||
allowNull: true,
|
||||
},
|
||||
type: {
|
||||
type: 'CHARACTER VARYING',
|
||||
allowNull: true,
|
||||
},
|
||||
atlasStructure: {
|
||||
type: 'JSONB',
|
||||
allowNull: true,
|
||||
},
|
||||
createdAt: {
|
||||
type: 'TIMESTAMP WITH TIME ZONE',
|
||||
allowNull: false,
|
||||
},
|
||||
updatedAt: {
|
||||
type: 'TIMESTAMP WITH TIME ZONE',
|
||||
allowNull: false,
|
||||
},
|
||||
teamId: {
|
||||
type: 'UUID',
|
||||
allowNull: false,
|
||||
references: {
|
||||
model: "teams",
|
||||
key: "id",
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// documents
|
||||
queryInterface.createTable('documents', {
|
||||
id:
|
||||
{ type: 'UUID',
|
||||
allowNull: false,
|
||||
defaultValue: null,
|
||||
special: [],
|
||||
primaryKey: true },
|
||||
urlId:
|
||||
{ type: 'CHARACTER VARYING',
|
||||
allowNull: false,
|
||||
unique: true,
|
||||
defaultValue: null,
|
||||
special: [],
|
||||
primaryKey: false },
|
||||
unique: true, },
|
||||
private:
|
||||
{ type: 'BOOLEAN',
|
||||
allowNull: false,
|
||||
defaultValue: true,
|
||||
special: [],
|
||||
primaryKey: false },
|
||||
},
|
||||
title:
|
||||
{ type: 'CHARACTER VARYING',
|
||||
allowNull: false,
|
||||
defaultValue: null,
|
||||
special: [],
|
||||
primaryKey: false },
|
||||
},
|
||||
text:
|
||||
{ type: 'TEXT',
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
special: [],
|
||||
primaryKey: false },
|
||||
},
|
||||
html:
|
||||
{ type: 'TEXT',
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
special: [],
|
||||
primaryKey: false },
|
||||
},
|
||||
preview:
|
||||
{ type: 'TEXT',
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
special: [],
|
||||
primaryKey: false },
|
||||
},
|
||||
createdAt:
|
||||
{ type: 'TIMESTAMP WITH TIME ZONE',
|
||||
allowNull: false,
|
||||
defaultValue: null,
|
||||
special: [],
|
||||
primaryKey: false },
|
||||
},
|
||||
updatedAt:
|
||||
{ type: 'TIMESTAMP WITH TIME ZONE',
|
||||
allowNull: false,
|
||||
defaultValue: null,
|
||||
special: [],
|
||||
primaryKey: false },
|
||||
userId:
|
||||
{ type: 'UUID',
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
special: [],
|
||||
primaryKey: false },
|
||||
atlasId:
|
||||
{ type: 'UUID',
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
special: [],
|
||||
primaryKey: false },
|
||||
parentDocumentForId:
|
||||
{ type: 'UUID',
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
special: [],
|
||||
primaryKey: false },
|
||||
teamId:
|
||||
{ type: 'UUID',
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
special: [],
|
||||
primaryKey: false }
|
||||
},
|
||||
userId: {
|
||||
type: 'UUID',
|
||||
allowNull: true,
|
||||
references: {
|
||||
model: "users",
|
||||
key: "id",
|
||||
}
|
||||
},
|
||||
atlasId: {
|
||||
type: 'UUID',
|
||||
allowNull: true,
|
||||
references: {
|
||||
model: "atlases",
|
||||
key: "id",
|
||||
}
|
||||
},
|
||||
teamId: {
|
||||
type: 'UUID',
|
||||
allowNull: true,
|
||||
references: {
|
||||
model: "teams",
|
||||
key: "id",
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
queryInterface.createTable('teams', {
|
||||
id:
|
||||
{ type: 'UUID',
|
||||
allowNull: false,
|
||||
defaultValue: null,
|
||||
special: [],
|
||||
primaryKey: true },
|
||||
name:
|
||||
{ type: 'CHARACTER VARYING',
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
special: [],
|
||||
primaryKey: false },
|
||||
slackId:
|
||||
{ type: 'CHARACTER VARYING',
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
special: [],
|
||||
primaryKey: true },
|
||||
slackData:
|
||||
{ type: 'JSONB',
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
special: [],
|
||||
primaryKey: false },
|
||||
createdAt:
|
||||
{ type: 'TIMESTAMP WITH TIME ZONE',
|
||||
allowNull: false,
|
||||
defaultValue: null,
|
||||
special: [],
|
||||
primaryKey: false },
|
||||
updatedAt:
|
||||
{ type: 'TIMESTAMP WITH TIME ZONE',
|
||||
allowNull: false,
|
||||
defaultValue: null,
|
||||
special: [],
|
||||
primaryKey: false } }
|
||||
);
|
||||
id: {
|
||||
type: 'UUID',
|
||||
allowNull: false,
|
||||
primaryKey: true
|
||||
},
|
||||
name: {
|
||||
type: 'CHARACTER VARYING',
|
||||
allowNull: true,
|
||||
},
|
||||
slackId: {
|
||||
type: 'CHARACTER VARYING',
|
||||
allowNull: true,
|
||||
unique: true
|
||||
},
|
||||
slackData: {
|
||||
type: 'JSONB',
|
||||
allowNull: true,
|
||||
},
|
||||
createdAt: {
|
||||
type: 'TIMESTAMP WITH TIME ZONE',
|
||||
allowNull: false,
|
||||
},
|
||||
updatedAt: {
|
||||
type: 'TIMESTAMP WITH TIME ZONE',
|
||||
allowNull: false,
|
||||
}
|
||||
});
|
||||
|
||||
queryInterface.createTable('users', {
|
||||
id:
|
||||
{ type: 'UUID',
|
||||
allowNull: false,
|
||||
defaultValue: null,
|
||||
special: [],
|
||||
primaryKey: true },
|
||||
email:
|
||||
{ type: 'CHARACTER VARYING',
|
||||
allowNull: false,
|
||||
defaultValue: null,
|
||||
special: [],
|
||||
primaryKey: false },
|
||||
username:
|
||||
{ type: 'CHARACTER VARYING',
|
||||
allowNull: false,
|
||||
defaultValue: null,
|
||||
special: [],
|
||||
primaryKey: false },
|
||||
name:
|
||||
{ type: 'CHARACTER VARYING',
|
||||
allowNull: false,
|
||||
defaultValue: null,
|
||||
special: [],
|
||||
primaryKey: false },
|
||||
isAdmin:
|
||||
{ type: 'BOOLEAN',
|
||||
allowNull: true,
|
||||
defaultValue: false,
|
||||
special: [],
|
||||
primaryKey: false },
|
||||
slackAccessToken:
|
||||
{ type: 'bytea',
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
special: [],
|
||||
primaryKey: false },
|
||||
slackId:
|
||||
{ type: 'CHARACTER VARYING',
|
||||
allowNull: false,
|
||||
defaultValue: null,
|
||||
unique: true,
|
||||
special: [],
|
||||
primaryKey: false },
|
||||
slackData:
|
||||
{ type: 'JSONB',
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
special: [],
|
||||
primaryKey: false },
|
||||
jwtSecret:
|
||||
{ type: 'bytea',
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
special: [],
|
||||
primaryKey: false },
|
||||
createdAt:
|
||||
{ type: 'TIMESTAMP WITH TIME ZONE',
|
||||
allowNull: false,
|
||||
defaultValue: null,
|
||||
special: [],
|
||||
primaryKey: false },
|
||||
updatedAt:
|
||||
{ type: 'TIMESTAMP WITH TIME ZONE',
|
||||
allowNull: false,
|
||||
defaultValue: null,
|
||||
special: [],
|
||||
primaryKey: false },
|
||||
teamId:
|
||||
{ type: 'UUID',
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
special: [],
|
||||
primaryKey: false }
|
||||
id: {
|
||||
type: 'UUID',
|
||||
allowNull: false,
|
||||
primaryKey: true
|
||||
},
|
||||
email: {
|
||||
type: 'CHARACTER VARYING',
|
||||
allowNull: false,
|
||||
},
|
||||
username: {
|
||||
type: 'CHARACTER VARYING',
|
||||
allowNull: false,
|
||||
},
|
||||
name: {
|
||||
type: 'CHARACTER VARYING',
|
||||
allowNull: false,
|
||||
},
|
||||
isAdmin: {
|
||||
type: 'BOOLEAN',
|
||||
allowNull: true,
|
||||
defaultValue: false,
|
||||
},
|
||||
slackAccessToken: {
|
||||
type: 'bytea',
|
||||
allowNull: true, },
|
||||
slackId: {
|
||||
type: 'CHARACTER VARYING',
|
||||
unique: true,
|
||||
allowNull: false,
|
||||
},
|
||||
slackData: {
|
||||
type: 'JSONB',
|
||||
allowNull: true,
|
||||
},
|
||||
jwtSecret: {
|
||||
type: 'bytea',
|
||||
allowNull: true,
|
||||
},
|
||||
createdAt: {
|
||||
type: 'TIMESTAMP WITH TIME ZONE',
|
||||
allowNull: false,
|
||||
},
|
||||
updatedAt: {
|
||||
type: 'TIMESTAMP WITH TIME ZONE',
|
||||
allowNull: false,
|
||||
},
|
||||
teamId: {
|
||||
type: 'UUID',
|
||||
allowNull: true,
|
||||
references: {
|
||||
model: "teams",
|
||||
key: "id",
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
|
22
server/migrations/20160622043741-add-parent-document.js
Normal file
22
server/migrations/20160622043741-add-parent-document.js
Normal file
@ -0,0 +1,22 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
up: function (queryInterface, Sequelize) {
|
||||
queryInterface.addColumn(
|
||||
'documents',
|
||||
'parentDocumentId',
|
||||
{
|
||||
type: Sequelize.UUID,
|
||||
allowNull: true,
|
||||
references: {
|
||||
model: "documents",
|
||||
key: "id",
|
||||
}
|
||||
}
|
||||
);
|
||||
},
|
||||
|
||||
down: function (queryInterface, Sequelize) {
|
||||
queryInterface.removeColumn('documents', 'parentDocumentId');
|
||||
}
|
||||
};
|
@ -30,28 +30,37 @@ const Atlas = sequelize.define('atlas', {
|
||||
// },
|
||||
},
|
||||
instanceMethods: {
|
||||
// buildUrl() {
|
||||
// const slugifiedTitle = slug(this.title);
|
||||
// return `${slugifiedTitle}-${this.urlId}`;
|
||||
// }
|
||||
async buildStructure() {
|
||||
// TODO
|
||||
const getNodeForDocument = async (document) => {
|
||||
const children = await Document.findAll({ where: {
|
||||
parentDocumentId: document.id,
|
||||
atlasId: this.id,
|
||||
}});
|
||||
|
||||
let childNodes = []
|
||||
await Promise.all(children.map(async (child) => {
|
||||
console.log(child.id)
|
||||
childNodes.push(await getNodeForDocument(child));
|
||||
}));
|
||||
|
||||
return {
|
||||
name: document.title,
|
||||
id: document.id,
|
||||
url: document.getUrl(),
|
||||
children: childNodes,
|
||||
};
|
||||
}
|
||||
|
||||
const rootDocument = await Document.findOne({ where: {
|
||||
parentDocumentForId: null,
|
||||
parentDocumentId: null,
|
||||
atlasId: this.id,
|
||||
}});
|
||||
|
||||
return {
|
||||
name: rootDocument.title,
|
||||
id: rootDocument.id,
|
||||
url: rootDocument.getUrl(),
|
||||
children: null,
|
||||
}
|
||||
return await getNodeForDocument(rootDocument);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Atlas.hasMany(Document, { as: 'documents', foreignKey: 'atlasId' });
|
||||
Atlas.hasOne(Document, { as: 'parentDocument', foreignKey: 'parentDocumentForId', constraints: false });
|
||||
|
||||
export default Atlas;
|
||||
|
@ -27,6 +27,8 @@ const Document = sequelize.define('document', {
|
||||
text: DataTypes.TEXT,
|
||||
html: DataTypes.TEXT,
|
||||
preview: DataTypes.TEXT,
|
||||
|
||||
parentDocumentId: DataTypes.UUID,
|
||||
}, {
|
||||
hooks: {
|
||||
beforeValidate: (doc) => {
|
||||
|
Reference in New Issue
Block a user