-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
166816213-feature(article, Article, ArticleLikes, User, helpers, utils)
- Add model and migration for ArticleLike - Add ArticleLike model instance and class methods - Add validation for like and dislike endpoint - Add likeArticle and dislikeArticle method in Article controller - Add route for like and dislike article - Add integration tests for the endpoint - Document endpoint [Delivers #166816213]
- Loading branch information
1 parent
b6d9bdf
commit f1df15f
Showing
9 changed files
with
288 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
module.exports = { | ||
up: (queryInterface, Sequelize) => queryInterface.createTable('ArticleVotes', { | ||
id: { | ||
allowNull: false, | ||
autoIncrement: true, | ||
primaryKey: true, | ||
type: Sequelize.INTEGER | ||
}, | ||
userId: { | ||
type: Sequelize.INTEGER, | ||
required: true, | ||
references: { | ||
model: 'Users', | ||
key: 'id', | ||
as: 'user', | ||
}, | ||
}, | ||
articleId: { | ||
type: Sequelize.INTEGER, | ||
required: true, | ||
references: { | ||
model: 'Articles', | ||
key: 'id', | ||
as: 'article', | ||
}, | ||
}, | ||
status: { | ||
allowNull: false, | ||
type: Sequelize.BOOLEAN, | ||
required: true | ||
}, | ||
createdAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
}, | ||
updatedAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
} | ||
}), | ||
down: queryInterface => queryInterface.dropTable('ArticleVotes') | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
module.exports = (sequelize, DataTypes) => { | ||
const ArticleVote = sequelize.define('ArticleVote', { | ||
status: DataTypes.BOOLEAN | ||
}, {}); | ||
ArticleVote.associate = (models) => { | ||
ArticleVote.belongsTo(models.User, { | ||
foreignKey: 'userId', | ||
as: 'user' | ||
}); | ||
ArticleVote.belongsTo(models.Article, { | ||
foreignKey: 'articleId', | ||
as: 'article' | ||
}); | ||
}; | ||
|
||
ArticleVote.getArticleVotes = (data) => { | ||
const { articleId, status } = data; | ||
return ArticleVote.count({ | ||
where: { | ||
articleId, | ||
status | ||
} | ||
}); | ||
}; | ||
|
||
ArticleVote.findArticleVote = (data) => { | ||
const { userId, articleId } = data; | ||
return ArticleVote.findOne({ | ||
where: { | ||
userId, | ||
articleId | ||
} | ||
}); | ||
}; | ||
|
||
ArticleVote.prototype.updateArticleVote = function update(status) { | ||
return this.update({ | ||
status | ||
}); | ||
}; | ||
|
||
ArticleVote.prototype.deleteArticleVote = function deleteVote() { | ||
return this.destroy(); | ||
}; | ||
|
||
return ArticleVote; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters