Atlas > Collection

This commit is contained in:
Tom Moor
2017-05-27 11:08:52 -07:00
parent 8883231f01
commit 639a0ec45c
8 changed files with 30 additions and 27 deletions

View File

@ -152,7 +152,7 @@ router.post('auth.slack', async ctx => {
} }
if (!teamExisted) { if (!teamExisted) {
await team.createFirstAtlas(user.id); await team.createFirstCollection(user.id);
} }
ctx.body = { ctx.body = {

View File

@ -5,7 +5,7 @@ import _ from 'lodash';
import auth from './middlewares/authentication'; import auth from './middlewares/authentication';
import pagination from './middlewares/pagination'; import pagination from './middlewares/pagination';
import { presentCollection } from '../presenters'; import { presentCollection } from '../presenters';
import { Atlas } from '../models'; import { Collection } from '../models';
const router = new Router(); const router = new Router();
@ -15,7 +15,7 @@ router.post('collections.create', auth(), async ctx => {
const user = ctx.state.user; const user = ctx.state.user;
const atlas = await Atlas.create({ const atlas = await Collection.create({
name, name,
description, description,
type: type || 'atlas', type: type || 'atlas',
@ -33,7 +33,7 @@ router.post('collections.info', auth(), async ctx => {
ctx.assertPresent(id, 'id is required'); ctx.assertPresent(id, 'id is required');
const user = ctx.state.user; const user = ctx.state.user;
const atlas = await Atlas.findOne({ const atlas = await Collection.findOne({
where: { where: {
id, id,
teamId: user.teamId, teamId: user.teamId,
@ -49,7 +49,7 @@ router.post('collections.info', auth(), async ctx => {
router.post('collections.list', auth(), pagination(), async ctx => { router.post('collections.list', auth(), pagination(), async ctx => {
const user = ctx.state.user; const user = ctx.state.user;
const collections = await Atlas.findAll({ const collections = await Collection.findAll({
where: { where: {
teamId: user.teamId, teamId: user.teamId,
}, },
@ -58,7 +58,7 @@ router.post('collections.list', auth(), pagination(), async ctx => {
limit: ctx.state.pagination.limit, limit: ctx.state.pagination.limit,
}); });
// Atlases // Collectiones
let data = []; let data = [];
await Promise.all( await Promise.all(
collections.map(async atlas => { collections.map(async atlas => {
@ -79,7 +79,7 @@ router.post('collections.updateNavigationTree', auth(), async ctx => {
ctx.assertPresent(id, 'id is required'); ctx.assertPresent(id, 'id is required');
const user = ctx.state.user; const user = ctx.state.user;
const atlas = await Atlas.findOne({ const atlas = await Collection.findOne({
where: { where: {
id, id,
teamId: user.teamId, teamId: user.teamId,

View File

@ -8,7 +8,7 @@ const URL_REGEX = /^[a-zA-Z0-9-]*-([a-zA-Z0-9]{10,15})$/;
import auth from './middlewares/authentication'; import auth from './middlewares/authentication';
// import pagination from './middlewares/pagination'; // import pagination from './middlewares/pagination';
import { presentDocument } from '../presenters'; import { presentDocument } from '../presenters';
import { Document, Atlas } from '../models'; import { Document, Collection } from '../models';
const router = new Router(); const router = new Router();
@ -102,7 +102,7 @@ router.post('documents.create', auth(), async ctx => {
ctx.assertPresent(text, 'text is required'); ctx.assertPresent(text, 'text is required');
const user = ctx.state.user; const user = ctx.state.user;
const ownerCollection = await Atlas.findOne({ const ownerCollection = await Collection.findOne({
where: { where: {
id: collection, id: collection,
teamId: user.teamId, teamId: user.teamId,
@ -176,7 +176,7 @@ router.post('documents.update', auth(), async ctx => {
// Update // Update
// TODO: Add locking // TODO: Add locking
const collection = await Atlas.findById(document.atlasId); const collection = await Collection.findById(document.atlasId);
if (collection.type === 'atlas') { if (collection.type === 'atlas') {
await collection.updateNavigationTree(); await collection.updateNavigationTree();
} }
@ -195,7 +195,7 @@ router.post('documents.delete', auth(), async ctx => {
const user = ctx.state.user; const user = ctx.state.user;
const document = await getDocumentForId(id); 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) if (!document || document.teamId !== user.teamId)
throw httpErrors.BadRequest(); throw httpErrors.BadRequest();

View File

@ -19,7 +19,7 @@ CREATE TRIGGER documents_tsvectorupdate BEFORE INSERT OR UPDATE
ON documents FOR EACH ROW EXECUTE PROCEDURE documents_search_trigger(); ON documents FOR EACH ROW EXECUTE PROCEDURE documents_search_trigger();
`; `;
const searchAtlas = ` const searchCollection = `
ALTER TABLE atlases ADD COLUMN "searchVector" tsvector; ALTER TABLE atlases ADD COLUMN "searchVector" tsvector;
CREATE INDEX atlases_tsv_idx ON atlases USING gin("searchVector"); 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(searchDocument);
queryInterface.sequelize.query(searchAtlas); queryInterface.sequelize.query(searchCollection);
}, },
down: function(queryInterface, Sequelize) { down: function(queryInterface, Sequelize) {

View File

@ -6,9 +6,9 @@ import Document from './Document';
slug.defaults.mode = 'rfc3986'; slug.defaults.mode = 'rfc3986';
const allowedAtlasTypes = [['atlas', 'journal']]; const allowedCollectionTypes = [['atlas', 'journal']];
const Atlas = sequelize.define( const Collection = sequelize.define(
'atlas', 'atlas',
{ {
id: { id: {
@ -19,7 +19,10 @@ const Atlas = sequelize.define(
urlId: { type: DataTypes.STRING, unique: true }, urlId: { type: DataTypes.STRING, unique: true },
name: DataTypes.STRING, name: DataTypes.STRING,
description: DataTypes.STRING, description: DataTypes.STRING,
type: { type: DataTypes.STRING, validate: { isIn: allowedAtlasTypes } }, type: {
type: DataTypes.STRING,
validate: { isIn: allowedCollectionTypes },
},
creatorId: DataTypes.UUID, creatorId: DataTypes.UUID,
/* type: atlas */ /* 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;

View File

@ -1,5 +1,5 @@
import { DataTypes, sequelize } from '../sequelize'; import { DataTypes, sequelize } from '../sequelize';
import Atlas from './Atlas'; import Collection from './Collection';
import Document from './Document'; import Document from './Document';
import User from './User'; import User from './User';
@ -17,10 +17,10 @@ const Team = sequelize.define(
}, },
{ {
instanceMethods: { instanceMethods: {
async createFirstAtlas(userId) { async createFirstCollection(userId) {
const atlas = await Atlas.create({ const atlas = await Collection.create({
name: this.name, name: this.name,
description: 'Your first Atlas', description: 'Your first Collection',
type: 'atlas', type: 'atlas',
teamId: this.id, teamId: this.id,
creatorId: userId, 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(Document, { as: 'documents' });
Team.hasMany(User, { as: 'users' }); Team.hasMany(User, { as: 'users' });

View File

@ -1,8 +1,8 @@
import User from './User'; import User from './User';
import Team from './Team'; import Team from './Team';
import Atlas from './Atlas'; import Collection from './Collection';
import Document from './Document'; import Document from './Document';
import Revision from './Revision'; import Revision from './Revision';
import ApiKey from './ApiKey'; import ApiKey from './ApiKey';
export { User, Team, Atlas, Document, Revision, ApiKey }; export { User, Team, Collection, Document, Revision, ApiKey };

View File

@ -1,5 +1,5 @@
import _ from 'lodash'; import _ from 'lodash';
import { Document, Atlas, User } from './models'; import { Document, Collection, User } from './models';
import presentUser from './presenters/user'; import presentUser from './presenters/user';
@ -40,7 +40,7 @@ export async function presentDocument(ctx, document, options) {
if (options.includeCollection) { if (options.includeCollection) {
data.collection = await ctx.cache.get(document.atlasId, async () => { data.collection = await ctx.cache.get(document.atlasId, async () => {
const collection = await Atlas.findOne({ const collection = await Collection.findOne({
where: { where: {
id: document.atlasId, id: document.atlasId,
}, },