diff --git a/server/migrations/20180727115808-create-user.js b/server/migrations/20180727115808-create-user.js index b320532..891b04a 100644 --- a/server/migrations/20180727115808-create-user.js +++ b/server/migrations/20180727115808-create-user.js @@ -1,67 +1,65 @@ module.exports = { - up: (queryInterface, Sequelize) => { - queryInterface.createTable('Users', { - id: { - allowNull: false, - autoIncrement: true, - primaryKey: true, - type: Sequelize.INTEGER, - }, - username: { - type: Sequelize.STRING, - allowNull: false, - unique: true, - }, - email: { - type: Sequelize.STRING, - allowNull: false, - unique: true, - }, - googleId: { - type: Sequelize.STRING, - allowNull: true, - }, - facebookId: { - type: Sequelize.STRING, - allowNull: true, - }, - twitterId: { - type: Sequelize.STRING, - allowNull: true, - }, - firstName: { - type: Sequelize.STRING, - allowNull: false, - }, - lastName: { - type: Sequelize.STRING, - allowNull: false, - }, - password: { - type: Sequelize.STRING, - allowNull: true, - }, - verified: { - type: Sequelize.BOOLEAN, - defaultValue: false, - }, - bio: { - type: Sequelize.TEXT, - allowNull: true, - }, - image: { - type: Sequelize.STRING, - allowNull: true, - }, - createdAt: { - allowNull: false, - type: Sequelize.DATE, - }, - updatedAt: { - allowNull: false, - type: Sequelize.DATE, - }, - }); - }, + up: (queryInterface, Sequelize) => queryInterface.createTable('Users', { + id: { + allowNull: false, + autoIncrement: true, + type: Sequelize.INTEGER, + }, + username: { + type: Sequelize.STRING, + allowNull: false, + primaryKey: true, + unique: true, + }, + firstName: { + type: Sequelize.STRING, + allowNull: false, + }, + lastName: { + type: Sequelize.STRING, + allowNull: false, + }, + googleId: { + type: Sequelize.STRING, + allowNull: true, + }, + facebookId: { + type: Sequelize.STRING, + allowNull: true, + }, + twitterId: { + type: Sequelize.STRING, + allowNull: true, + }, + email: { + type: Sequelize.STRING, + allowNull: false, + unique: true, + }, + password: { + type: Sequelize.STRING, + allowNull: true, + }, + verified: { + type: Sequelize.BOOLEAN, + defaultValue: false, + }, + bio: { + type: Sequelize.TEXT, + allowNull: true, + }, + image: { + type: Sequelize.STRING, + allowNull: true, + }, + createdAt: { + allowNull: false, + type: Sequelize.DATE, + }, + updatedAt: { + allowNull: false, + type: Sequelize.DATE, + }, + }), down: (queryInterface) => { queryInterface.dropTable('Users'); }, }; diff --git a/server/migrations/20180806205756-create-reply.js b/server/migrations/20180806205756-create-reply.js deleted file mode 100644 index 7e68290..0000000 --- a/server/migrations/20180806205756-create-reply.js +++ /dev/null @@ -1,39 +0,0 @@ - -module.exports = { - up: (queryInterface, Sequelize) => queryInterface.createTable('Replies', { - id: { - allowNull: false, - autoIncrement: true, - primaryKey: true, - type: Sequelize.INTEGER - }, - articleId: { - type: Sequelize.INTEGER, - allowNull: false - }, - commentId: { - type: Sequelize.INTEGER, - allowNull: false, - onDelete: 'CASCADE', - onUpdate: 'CASCADE', - references: { - model: 'Comments', - key: 'id', - as: 'commentId' - }, - }, - body: { - type: Sequelize.TEXT, - allowNull: false - }, - createdAt: { - allowNull: false, - type: Sequelize.DATE - }, - updatedAt: { - allowNull: false, - type: Sequelize.DATE - } - }), - down: queryInterface => queryInterface.dropTable('Replies') -}; diff --git a/server/models/article.js b/server/models/article.js index c4251ee..de60ebc 100644 --- a/server/models/article.js +++ b/server/models/article.js @@ -1,4 +1,3 @@ - export default (sequelize, DataTypes) => { const Article = sequelize.define('Article', { slug: { @@ -18,7 +17,6 @@ export default (sequelize, DataTypes) => { type: DataTypes.BLOB, allowNull: true }, - }); Article.associate = (models) => { Article.belongsTo(models.User, { @@ -40,7 +38,7 @@ export default (sequelize, DataTypes) => { }); Article.belongsTo(models.Category, { foreignKey: 'categoryId', - as: 'categories' + as: 'categories', }); }; return Article; diff --git a/server/models/comment.js b/server/models/comment.js index a423fac..ae9a0cb 100644 --- a/server/models/comment.js +++ b/server/models/comment.js @@ -1,14 +1,5 @@ - export default (sequelize, DataTypes) => { const Comment = sequelize.define('Comment', { - articleId: { - type: DataTypes.INTEGER, - allowNull: false - }, - userId: { - type: DataTypes.INTEGER, - allowNull: false - }, body: { type: DataTypes.TEXT, allowNull: false diff --git a/server/models/reply.js b/server/models/reply.js deleted file mode 100644 index f2b5ad6..0000000 --- a/server/models/reply.js +++ /dev/null @@ -1,25 +0,0 @@ - -export default (sequelize, DataTypes) => { - const Reply = sequelize.define('Reply', { - articleId: { - type: DataTypes.INTEGER, - allowNull: false - }, - commentId: { - type: DataTypes.INTEGER, - allowNull: false - }, - body: { - type: DataTypes.TEXT, - allowNull: false - }, - }); - Reply.associate = (models) => { - Reply.belongsTo(models.Comment, { - foreignKey: 'commentId', - onDelete: 'CASCADE', - OnUpdate: 'CASCADE' - }); - }; - return Reply; -}; diff --git a/server/models/user.js b/server/models/user.js index 5931299..870ae2a 100644 --- a/server/models/user.js +++ b/server/models/user.js @@ -14,44 +14,44 @@ export default (sequelize, DataTypes) => { args: true, msg: 'Must be a valid email address', }, - unique: true - }, - firstName: { - type: DataTypes.STRING, - allowNull: false, - }, - lastName: { - type: DataTypes.STRING, - allowNull: false, - }, - googleId: { - type: DataTypes.STRING, - allowNull: true, - }, - facebookId: { - type: DataTypes.STRING, - allowNull: true, - }, - twitterId: { - type: DataTypes.STRING, - allowNull: true, - }, - password: { - type: DataTypes.STRING, - allowNull: true, - }, - verified: { - type: DataTypes.BOOLEAN, - defaultValue: false, - }, - bio: { - type: DataTypes.TEXT, - allowNull: true, - }, - image: { - type: DataTypes.STRING, - allowNull: true, }, + unique: true, + }, + googleId: { + type: DataTypes.STRING, + allowNull: true, + }, + facebookId: { + type: DataTypes.STRING, + allowNull: true, + }, + twitterId: { + type: DataTypes.STRING, + allowNull: true, + }, + firstName: { + type: DataTypes.STRING, + allowNull: false, + }, + lastName: { + type: DataTypes.STRING, + allowNull: false, + }, + password: { + type: DataTypes.STRING, + allowNull: true, + }, + verified: { + type: DataTypes.BOOLEAN, + defaultValue: false, + }, + bio: { + type: DataTypes.TEXT, + allowNull: true, + }, + image: { + type: DataTypes.STRING, + allowNull: true, }, }); diff --git a/server/routes/article.js b/server/routes/article.js index 2b58e5c..f5f7a22 100644 --- a/server/routes/article.js +++ b/server/routes/article.js @@ -2,7 +2,6 @@ import { Router } from 'express'; import ArticleController from '../controllers/ArticleController'; import userAuthenticate from '../middlewares/isLoggedIn'; import ArticleValidation from '../middlewares/validations/ArticleValidation'; -import isUser from '../middlewares/isUser'; import CommentValidation from '../middlewares/validations/CommentValidation'; import CommentController from '../controllers/CommentController'; @@ -14,10 +13,6 @@ articleRouter.put('/articles/:slug', userAuthenticate, ArticleValidation.validat articleRouter.delete('/articles/:slug', userAuthenticate, ArticleController.removeArticle); -articleRouter.post('/articles/:slug/comments', userAuthenticate, CommentValidation.validateNewComment, CommentController.createComment); - -articleRouter.get('/articles/:slug/comments', userAuthenticate, CommentController.getComments); - articleRouter.post('/articles/:slug/comments', userAuthenticate, CommentValidation.validateComment, CommentController.createComment); articleRouter.get('/articles/:slug/comments', userAuthenticate, CommentController.getComments); diff --git a/server/seeders/20180806182424-demo-user.js b/server/seeders/20180806182424-demo-user.js index 66f2e56..e58ccd1 100644 --- a/server/seeders/20180806182424-demo-user.js +++ b/server/seeders/20180806182424-demo-user.js @@ -19,7 +19,6 @@ module.exports = { lastName: 'Doe', username: 'oyomi', email: 'seayomi@gmail.com', - verified: true, createdAt: '2018-08-01 21:54:49', updatedAt: '2018-08-04 21:54:49', }