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

@@ -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;

View File

@@ -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' });

View File

@@ -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 };