-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(comment): like specific comment
- Add endpoint for liking a comment - Add option of get results - Add tests - Add documentation [Delivers #165413123]
- Loading branch information
1 parent
e6842c7
commit ba80399
Showing
11 changed files
with
431 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
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 @@ | ||
const commentFeedbacksMigrations = { | ||
up: (queryInterface, Sequelize) => queryInterface.createTable('CommentFeedbacks', { | ||
id: { | ||
allowNull: false, | ||
autoIncrement: true, | ||
primaryKey: true, | ||
type: Sequelize.INTEGER | ||
}, | ||
userId: { | ||
type: Sequelize.INTEGER, | ||
onDelete: 'CASCADE', | ||
onUpdate: 'CASCADE', | ||
references: { | ||
model: 'Users', | ||
key: 'id' | ||
} | ||
}, | ||
commentId: { | ||
type: Sequelize.INTEGER, | ||
onDelete: 'CASCADE', | ||
onUpdate: 'CASCADE', | ||
references: { | ||
model: 'Comments', | ||
key: 'id' | ||
} | ||
}, | ||
feedback: { | ||
type: Sequelize.ENUM, | ||
values: ['like', 'neutral'] | ||
}, | ||
createdAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
}, | ||
updatedAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
} | ||
}), | ||
down: queryInterface => queryInterface.dropTable('CommentFeedbacks') | ||
}; | ||
export default commentFeedbacksMigrations; |
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,26 @@ | ||
const commentFeedbacks = (sequelize, DataTypes) => { | ||
const CommentFeedback = sequelize.define('CommentFeedback', { | ||
userId: DataTypes.INTEGER, | ||
commentId: DataTypes.INTEGER, | ||
feedback: DataTypes.ENUM({ | ||
values: ['like', 'neutral'] | ||
}) | ||
}, {}); | ||
CommentFeedback.associate = (models) => { | ||
CommentFeedback.belongsTo(models.User, { | ||
foreignKey: 'userId', | ||
as: 'liked', | ||
onDelete: 'CASCADE', | ||
onupdate: 'CASCADE' | ||
}); | ||
CommentFeedback.belongsTo(models.Comment, { | ||
foreignKey: 'commentId', | ||
as: 'like', | ||
targetKey: 'id', | ||
onDelete: 'CASCADE', | ||
onupdate: 'CASCADE' | ||
}); | ||
}; | ||
return CommentFeedback; | ||
}; | ||
export default commentFeedbacks; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import express from 'express'; | ||
import Auth from '../../../middlewares/auth'; | ||
import comment from '../../../controllers/comment.controller'; | ||
import commentHelper from '../../../helpers/commentHelper'; | ||
|
||
const router = express.Router(); | ||
router.delete('/:id', Auth, commentHelper.isFeedbackExist, comment.deleteFeedback); | ||
router.post('/:id/feedback/:option', Auth, commentHelper.isValidOption, commentHelper.isItValidComment, comment.reactOnComment); | ||
router.get('/:id/likes', commentHelper.likesNumber, comment.getLikes); | ||
|
||
|
||
export default router; |
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
Oops, something went wrong.