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 = {
|
module.exports = {
|
||||||
up: function (queryInterface, Sequelize) {
|
up: function (queryInterface, Sequelize) {
|
||||||
queryInterface.createTable('atlases', {
|
queryInterface.createTable('atlases', {
|
||||||
id:
|
id: {
|
||||||
{ type: 'UUID',
|
type: 'UUID',
|
||||||
allowNull: false,
|
allowNull: false,
|
||||||
defaultValue: null,
|
primaryKey: true
|
||||||
special: [],
|
},
|
||||||
primaryKey: true },
|
name: {
|
||||||
name:
|
type: 'CHARACTER VARYING',
|
||||||
{ type: 'CHARACTER VARYING',
|
allowNull: true,
|
||||||
allowNull: true,
|
},
|
||||||
defaultValue: null,
|
description: {
|
||||||
special: [],
|
type: 'CHARACTER VARYING',
|
||||||
primaryKey: false },
|
allowNull: true,
|
||||||
description:
|
},
|
||||||
{ type: 'CHARACTER VARYING',
|
type: {
|
||||||
allowNull: true,
|
type: 'CHARACTER VARYING',
|
||||||
defaultValue: null,
|
allowNull: true,
|
||||||
special: [],
|
},
|
||||||
primaryKey: false },
|
atlasStructure: {
|
||||||
type:
|
type: 'JSONB',
|
||||||
{ type: 'CHARACTER VARYING',
|
allowNull: true,
|
||||||
allowNull: true,
|
},
|
||||||
defaultValue: null,
|
createdAt: {
|
||||||
special: [],
|
type: 'TIMESTAMP WITH TIME ZONE',
|
||||||
primaryKey: false },
|
allowNull: false,
|
||||||
atlasStructure:
|
},
|
||||||
{ type: 'JSONB',
|
updatedAt: {
|
||||||
allowNull: true,
|
type: 'TIMESTAMP WITH TIME ZONE',
|
||||||
defaultValue: null,
|
allowNull: false,
|
||||||
special: [],
|
},
|
||||||
primaryKey: false },
|
teamId: {
|
||||||
createdAt:
|
type: 'UUID',
|
||||||
{ type: 'TIMESTAMP WITH TIME ZONE',
|
allowNull: false,
|
||||||
allowNull: false,
|
references: {
|
||||||
defaultValue: null,
|
model: "teams",
|
||||||
special: [],
|
key: "id",
|
||||||
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 } }
|
|
||||||
);
|
|
||||||
|
|
||||||
// documents
|
|
||||||
queryInterface.createTable('documents', {
|
queryInterface.createTable('documents', {
|
||||||
id:
|
id:
|
||||||
{ type: 'UUID',
|
{ type: 'UUID',
|
||||||
allowNull: false,
|
allowNull: false,
|
||||||
defaultValue: null,
|
|
||||||
special: [],
|
|
||||||
primaryKey: true },
|
primaryKey: true },
|
||||||
urlId:
|
urlId:
|
||||||
{ type: 'CHARACTER VARYING',
|
{ type: 'CHARACTER VARYING',
|
||||||
allowNull: false,
|
allowNull: false,
|
||||||
unique: true,
|
unique: true, },
|
||||||
defaultValue: null,
|
|
||||||
special: [],
|
|
||||||
primaryKey: false },
|
|
||||||
private:
|
private:
|
||||||
{ type: 'BOOLEAN',
|
{ type: 'BOOLEAN',
|
||||||
allowNull: false,
|
allowNull: false,
|
||||||
defaultValue: true,
|
defaultValue: true,
|
||||||
special: [],
|
},
|
||||||
primaryKey: false },
|
|
||||||
title:
|
title:
|
||||||
{ type: 'CHARACTER VARYING',
|
{ type: 'CHARACTER VARYING',
|
||||||
allowNull: false,
|
allowNull: false,
|
||||||
defaultValue: null,
|
},
|
||||||
special: [],
|
|
||||||
primaryKey: false },
|
|
||||||
text:
|
text:
|
||||||
{ type: 'TEXT',
|
{ type: 'TEXT',
|
||||||
allowNull: true,
|
allowNull: true,
|
||||||
defaultValue: null,
|
},
|
||||||
special: [],
|
|
||||||
primaryKey: false },
|
|
||||||
html:
|
html:
|
||||||
{ type: 'TEXT',
|
{ type: 'TEXT',
|
||||||
allowNull: true,
|
allowNull: true,
|
||||||
defaultValue: null,
|
},
|
||||||
special: [],
|
|
||||||
primaryKey: false },
|
|
||||||
preview:
|
preview:
|
||||||
{ type: 'TEXT',
|
{ type: 'TEXT',
|
||||||
allowNull: true,
|
allowNull: true,
|
||||||
defaultValue: null,
|
},
|
||||||
special: [],
|
|
||||||
primaryKey: false },
|
|
||||||
createdAt:
|
createdAt:
|
||||||
{ type: 'TIMESTAMP WITH TIME ZONE',
|
{ type: 'TIMESTAMP WITH TIME ZONE',
|
||||||
allowNull: false,
|
allowNull: false,
|
||||||
defaultValue: null,
|
},
|
||||||
special: [],
|
|
||||||
primaryKey: false },
|
|
||||||
updatedAt:
|
updatedAt:
|
||||||
{ type: 'TIMESTAMP WITH TIME ZONE',
|
{ type: 'TIMESTAMP WITH TIME ZONE',
|
||||||
allowNull: false,
|
allowNull: false,
|
||||||
defaultValue: null,
|
},
|
||||||
special: [],
|
userId: {
|
||||||
primaryKey: false },
|
type: 'UUID',
|
||||||
userId:
|
allowNull: true,
|
||||||
{ type: 'UUID',
|
references: {
|
||||||
allowNull: true,
|
model: "users",
|
||||||
defaultValue: null,
|
key: "id",
|
||||||
special: [],
|
}
|
||||||
primaryKey: false },
|
},
|
||||||
atlasId:
|
atlasId: {
|
||||||
{ type: 'UUID',
|
type: 'UUID',
|
||||||
allowNull: true,
|
allowNull: true,
|
||||||
defaultValue: null,
|
references: {
|
||||||
special: [],
|
model: "atlases",
|
||||||
primaryKey: false },
|
key: "id",
|
||||||
parentDocumentForId:
|
}
|
||||||
{ type: 'UUID',
|
},
|
||||||
allowNull: true,
|
teamId: {
|
||||||
defaultValue: null,
|
type: 'UUID',
|
||||||
special: [],
|
allowNull: true,
|
||||||
primaryKey: false },
|
references: {
|
||||||
teamId:
|
model: "teams",
|
||||||
{ type: 'UUID',
|
key: "id",
|
||||||
allowNull: true,
|
}
|
||||||
defaultValue: null,
|
}
|
||||||
special: [],
|
|
||||||
primaryKey: false }
|
|
||||||
});
|
});
|
||||||
|
|
||||||
queryInterface.createTable('teams', {
|
queryInterface.createTable('teams', {
|
||||||
id:
|
id: {
|
||||||
{ type: 'UUID',
|
type: 'UUID',
|
||||||
allowNull: false,
|
allowNull: false,
|
||||||
defaultValue: null,
|
primaryKey: true
|
||||||
special: [],
|
},
|
||||||
primaryKey: true },
|
name: {
|
||||||
name:
|
type: 'CHARACTER VARYING',
|
||||||
{ type: 'CHARACTER VARYING',
|
allowNull: true,
|
||||||
allowNull: true,
|
},
|
||||||
defaultValue: null,
|
slackId: {
|
||||||
special: [],
|
type: 'CHARACTER VARYING',
|
||||||
primaryKey: false },
|
allowNull: true,
|
||||||
slackId:
|
unique: true
|
||||||
{ type: 'CHARACTER VARYING',
|
},
|
||||||
allowNull: true,
|
slackData: {
|
||||||
defaultValue: null,
|
type: 'JSONB',
|
||||||
special: [],
|
allowNull: true,
|
||||||
primaryKey: true },
|
},
|
||||||
slackData:
|
createdAt: {
|
||||||
{ type: 'JSONB',
|
type: 'TIMESTAMP WITH TIME ZONE',
|
||||||
allowNull: true,
|
allowNull: false,
|
||||||
defaultValue: null,
|
},
|
||||||
special: [],
|
updatedAt: {
|
||||||
primaryKey: false },
|
type: 'TIMESTAMP WITH TIME ZONE',
|
||||||
createdAt:
|
allowNull: false,
|
||||||
{ 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 } }
|
|
||||||
);
|
|
||||||
|
|
||||||
queryInterface.createTable('users', {
|
queryInterface.createTable('users', {
|
||||||
id:
|
id: {
|
||||||
{ type: 'UUID',
|
type: 'UUID',
|
||||||
allowNull: false,
|
allowNull: false,
|
||||||
defaultValue: null,
|
primaryKey: true
|
||||||
special: [],
|
},
|
||||||
primaryKey: true },
|
email: {
|
||||||
email:
|
type: 'CHARACTER VARYING',
|
||||||
{ type: 'CHARACTER VARYING',
|
allowNull: false,
|
||||||
allowNull: false,
|
},
|
||||||
defaultValue: null,
|
username: {
|
||||||
special: [],
|
type: 'CHARACTER VARYING',
|
||||||
primaryKey: false },
|
allowNull: false,
|
||||||
username:
|
},
|
||||||
{ type: 'CHARACTER VARYING',
|
name: {
|
||||||
allowNull: false,
|
type: 'CHARACTER VARYING',
|
||||||
defaultValue: null,
|
allowNull: false,
|
||||||
special: [],
|
},
|
||||||
primaryKey: false },
|
isAdmin: {
|
||||||
name:
|
type: 'BOOLEAN',
|
||||||
{ type: 'CHARACTER VARYING',
|
allowNull: true,
|
||||||
allowNull: false,
|
defaultValue: false,
|
||||||
defaultValue: null,
|
},
|
||||||
special: [],
|
slackAccessToken: {
|
||||||
primaryKey: false },
|
type: 'bytea',
|
||||||
isAdmin:
|
allowNull: true, },
|
||||||
{ type: 'BOOLEAN',
|
slackId: {
|
||||||
allowNull: true,
|
type: 'CHARACTER VARYING',
|
||||||
defaultValue: false,
|
unique: true,
|
||||||
special: [],
|
allowNull: false,
|
||||||
primaryKey: false },
|
},
|
||||||
slackAccessToken:
|
slackData: {
|
||||||
{ type: 'bytea',
|
type: 'JSONB',
|
||||||
allowNull: true,
|
allowNull: true,
|
||||||
defaultValue: null,
|
},
|
||||||
special: [],
|
jwtSecret: {
|
||||||
primaryKey: false },
|
type: 'bytea',
|
||||||
slackId:
|
allowNull: true,
|
||||||
{ type: 'CHARACTER VARYING',
|
},
|
||||||
allowNull: false,
|
createdAt: {
|
||||||
defaultValue: null,
|
type: 'TIMESTAMP WITH TIME ZONE',
|
||||||
unique: true,
|
allowNull: false,
|
||||||
special: [],
|
},
|
||||||
primaryKey: false },
|
updatedAt: {
|
||||||
slackData:
|
type: 'TIMESTAMP WITH TIME ZONE',
|
||||||
{ type: 'JSONB',
|
allowNull: false,
|
||||||
allowNull: true,
|
},
|
||||||
defaultValue: null,
|
teamId: {
|
||||||
special: [],
|
type: 'UUID',
|
||||||
primaryKey: false },
|
allowNull: true,
|
||||||
jwtSecret:
|
references: {
|
||||||
{ type: 'bytea',
|
model: "teams",
|
||||||
allowNull: true,
|
key: "id",
|
||||||
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 }
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
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: {
|
instanceMethods: {
|
||||||
// buildUrl() {
|
|
||||||
// const slugifiedTitle = slug(this.title);
|
|
||||||
// return `${slugifiedTitle}-${this.urlId}`;
|
|
||||||
// }
|
|
||||||
async buildStructure() {
|
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: {
|
const rootDocument = await Document.findOne({ where: {
|
||||||
parentDocumentForId: null,
|
parentDocumentId: null,
|
||||||
atlasId: this.id,
|
atlasId: this.id,
|
||||||
}});
|
}});
|
||||||
|
|
||||||
return {
|
return await getNodeForDocument(rootDocument);
|
||||||
name: rootDocument.title,
|
|
||||||
id: rootDocument.id,
|
|
||||||
url: rootDocument.getUrl(),
|
|
||||||
children: null,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Atlas.hasMany(Document, { as: 'documents', foreignKey: 'atlasId' });
|
Atlas.hasMany(Document, { as: 'documents', foreignKey: 'atlasId' });
|
||||||
Atlas.hasOne(Document, { as: 'parentDocument', foreignKey: 'parentDocumentForId', constraints: false });
|
|
||||||
|
|
||||||
export default Atlas;
|
export default Atlas;
|
||||||
|
@ -27,6 +27,8 @@ const Document = sequelize.define('document', {
|
|||||||
text: DataTypes.TEXT,
|
text: DataTypes.TEXT,
|
||||||
html: DataTypes.TEXT,
|
html: DataTypes.TEXT,
|
||||||
preview: DataTypes.TEXT,
|
preview: DataTypes.TEXT,
|
||||||
|
|
||||||
|
parentDocumentId: DataTypes.UUID,
|
||||||
}, {
|
}, {
|
||||||
hooks: {
|
hooks: {
|
||||||
beforeValidate: (doc) => {
|
beforeValidate: (doc) => {
|
||||||
|
Reference in New Issue
Block a user