diff --git a/server/api/auth.js b/server/api/auth.js index e2069627..a677411a 100644 --- a/server/api/auth.js +++ b/server/api/auth.js @@ -152,7 +152,7 @@ router.post('auth.slack', async ctx => { } if (!teamExisted) { - await team.createFirstAtlas(user.id); + await team.createFirstCollection(user.id); } ctx.body = { diff --git a/server/api/collections.js b/server/api/collections.js index 86650a9e..6cc5f6ff 100644 --- a/server/api/collections.js +++ b/server/api/collections.js @@ -5,7 +5,7 @@ import _ from 'lodash'; import auth from './middlewares/authentication'; import pagination from './middlewares/pagination'; import { presentCollection } from '../presenters'; -import { Atlas } from '../models'; +import { Collection } from '../models'; const router = new Router(); @@ -15,7 +15,7 @@ router.post('collections.create', auth(), async ctx => { const user = ctx.state.user; - const atlas = await Atlas.create({ + const atlas = await Collection.create({ name, description, type: type || 'atlas', @@ -33,7 +33,7 @@ router.post('collections.info', auth(), async ctx => { ctx.assertPresent(id, 'id is required'); const user = ctx.state.user; - const atlas = await Atlas.findOne({ + const atlas = await Collection.findOne({ where: { id, teamId: user.teamId, @@ -49,7 +49,7 @@ router.post('collections.info', auth(), async ctx => { router.post('collections.list', auth(), pagination(), async ctx => { const user = ctx.state.user; - const collections = await Atlas.findAll({ + const collections = await Collection.findAll({ where: { teamId: user.teamId, }, @@ -58,7 +58,7 @@ router.post('collections.list', auth(), pagination(), async ctx => { limit: ctx.state.pagination.limit, }); - // Atlases + // Collectiones let data = []; await Promise.all( collections.map(async atlas => { @@ -79,7 +79,7 @@ router.post('collections.updateNavigationTree', auth(), async ctx => { ctx.assertPresent(id, 'id is required'); const user = ctx.state.user; - const atlas = await Atlas.findOne({ + const atlas = await Collection.findOne({ where: { id, teamId: user.teamId, diff --git a/server/api/documents.js b/server/api/documents.js index 537997cb..a8fa7982 100644 --- a/server/api/documents.js +++ b/server/api/documents.js @@ -8,7 +8,7 @@ const URL_REGEX = /^[a-zA-Z0-9-]*-([a-zA-Z0-9]{10,15})$/; import auth from './middlewares/authentication'; // import pagination from './middlewares/pagination'; import { presentDocument } from '../presenters'; -import { Document, Atlas } from '../models'; +import { Document, Collection } from '../models'; const router = new Router(); @@ -102,7 +102,7 @@ router.post('documents.create', auth(), async ctx => { ctx.assertPresent(text, 'text is required'); const user = ctx.state.user; - const ownerCollection = await Atlas.findOne({ + const ownerCollection = await Collection.findOne({ where: { id: collection, teamId: user.teamId, @@ -176,7 +176,7 @@ router.post('documents.update', auth(), async ctx => { // Update // TODO: Add locking - const collection = await Atlas.findById(document.atlasId); + const collection = await Collection.findById(document.atlasId); if (collection.type === 'atlas') { await collection.updateNavigationTree(); } @@ -195,7 +195,7 @@ router.post('documents.delete', auth(), async ctx => { const user = ctx.state.user; const document = await getDocumentForId(id); - const collection = await Atlas.findById(document.atlasId); + const collection = await Collection.findById(document.atlasId); if (!document || document.teamId !== user.teamId) throw httpErrors.BadRequest(); diff --git a/server/migrations/20160711071958-search-index.js b/server/migrations/20160711071958-search-index.js index bb9c7ec0..7ac7862d 100644 --- a/server/migrations/20160711071958-search-index.js +++ b/server/migrations/20160711071958-search-index.js @@ -19,7 +19,7 @@ CREATE TRIGGER documents_tsvectorupdate BEFORE INSERT OR UPDATE ON documents FOR EACH ROW EXECUTE PROCEDURE documents_search_trigger(); `; - const searchAtlas = ` + const searchCollection = ` ALTER TABLE atlases ADD COLUMN "searchVector" tsvector; CREATE INDEX atlases_tsv_idx ON atlases USING gin("searchVector"); @@ -37,7 +37,7 @@ ON atlases FOR EACH ROW EXECUTE PROCEDURE atlases_search_trigger(); `; queryInterface.sequelize.query(searchDocument); - queryInterface.sequelize.query(searchAtlas); + queryInterface.sequelize.query(searchCollection); }, down: function(queryInterface, Sequelize) { diff --git a/server/models/Atlas.js b/server/models/Collection.js similarity index 95% rename from server/models/Atlas.js rename to server/models/Collection.js index c7880458..01f8cf66 100644 --- a/server/models/Atlas.js +++ b/server/models/Collection.js @@ -6,9 +6,9 @@ import Document from './Document'; slug.defaults.mode = 'rfc3986'; -const allowedAtlasTypes = [['atlas', 'journal']]; +const allowedCollectionTypes = [['atlas', 'journal']]; -const Atlas = sequelize.define( +const Collection = sequelize.define( 'atlas', { id: { @@ -19,7 +19,10 @@ const Atlas = sequelize.define( urlId: { type: DataTypes.STRING, unique: true }, name: DataTypes.STRING, description: DataTypes.STRING, - type: { type: DataTypes.STRING, validate: { isIn: allowedAtlasTypes } }, + type: { + type: DataTypes.STRING, + validate: { isIn: allowedCollectionTypes }, + }, creatorId: DataTypes.UUID, /* type: atlas */ @@ -210,6 +213,6 @@ const Atlas = sequelize.define( } ); -Atlas.hasMany(Document, { as: 'documents', foreignKey: 'atlasId' }); +Collection.hasMany(Document, { as: 'documents', foreignKey: 'atlasId' }); -export default Atlas; +export default Collection; diff --git a/server/models/Team.js b/server/models/Team.js index fba3dff3..b1a8684f 100644 --- a/server/models/Team.js +++ b/server/models/Team.js @@ -1,5 +1,5 @@ import { DataTypes, sequelize } from '../sequelize'; -import Atlas from './Atlas'; +import Collection from './Collection'; import Document from './Document'; import User from './User'; @@ -17,10 +17,10 @@ const Team = sequelize.define( }, { instanceMethods: { - async createFirstAtlas(userId) { - const atlas = await Atlas.create({ + async createFirstCollection(userId) { + const atlas = await Collection.create({ name: this.name, - description: 'Your first Atlas', + description: 'Your first Collection', type: 'atlas', teamId: this.id, creatorId: userId, @@ -37,7 +37,7 @@ const Team = sequelize.define( } ); -Team.hasMany(Atlas, { as: 'atlases' }); +Team.hasMany(Collection, { as: 'atlases' }); Team.hasMany(Document, { as: 'documents' }); Team.hasMany(User, { as: 'users' }); diff --git a/server/models/index.js b/server/models/index.js index a3d7e55d..72dc96d8 100644 --- a/server/models/index.js +++ b/server/models/index.js @@ -1,8 +1,8 @@ import User from './User'; import Team from './Team'; -import Atlas from './Atlas'; +import Collection from './Collection'; import Document from './Document'; import Revision from './Revision'; import ApiKey from './ApiKey'; -export { User, Team, Atlas, Document, Revision, ApiKey }; +export { User, Team, Collection, Document, Revision, ApiKey }; diff --git a/server/presenters.js b/server/presenters.js index f1ff9d11..54846cf2 100644 --- a/server/presenters.js +++ b/server/presenters.js @@ -1,5 +1,5 @@ import _ from 'lodash'; -import { Document, Atlas, User } from './models'; +import { Document, Collection, User } from './models'; import presentUser from './presenters/user'; @@ -40,7 +40,7 @@ export async function presentDocument(ctx, document, options) { if (options.includeCollection) { data.collection = await ctx.cache.get(document.atlasId, async () => { - const collection = await Atlas.findOne({ + const collection = await Collection.findOne({ where: { id: document.atlasId, },