-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(track-comment-history): track comment edit history
- track comment edit history [Finishes #166790019]
- Loading branch information
1 parent
4f10da9
commit f216234
Showing
17 changed files
with
228 additions
and
51 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
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,24 @@ | ||
import models from '../models/index'; | ||
|
||
const { articles, users } = models; | ||
|
||
/* @middleware which find if article is exist and | ||
check if user is allowed to update or delete article | ||
*/ | ||
export const checkArticleOwner = async (req, res, next) => { | ||
try { | ||
const article = await articles.findOne({ where: { slug: req.params.slug } }); | ||
const author = await users.findOne({ where: { email: req.decoded.email } }); | ||
if (!article) { | ||
return res.status(404).json({ error: 'sorry the requested article could not be found.' }); | ||
} | ||
// @check if authors are the same | ||
if (article.authorId !== author.id) { | ||
return res.status(403).json({ error: 'permission denied, you are not allowed to perform this action.' }); | ||
} | ||
req.findArticle = article; | ||
next(); | ||
} catch (error) { | ||
return res.status(500).json({ error: `something wrong please try again. ${error}` }); | ||
} | ||
}; |
File renamed without changes.
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,27 @@ | ||
export const up = (queryInterface, Sequelize) => queryInterface.createTable('commentEdits', { | ||
commentId: { | ||
type: Sequelize.UUID, | ||
references: { | ||
model: 'comments', | ||
key: 'id' | ||
}, | ||
onDelete: 'CASCADE', | ||
allowNull: false | ||
}, | ||
body: { | ||
type: Sequelize.TEXT, | ||
allowNull: false | ||
}, | ||
createdAt: { | ||
defaultValue: Sequelize.fn('now'), | ||
type: Sequelize.DATE, | ||
default: true | ||
}, | ||
updatedAt: { | ||
defaultValue: Sequelize.fn('now'), | ||
type: Sequelize.DATE, | ||
default: true | ||
} | ||
}); | ||
|
||
export const down = queryInterface => queryInterface.dropTable('commentEdits'); |
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,30 @@ | ||
export default (sequelize, DataTypes) => { | ||
const commentEdits = sequelize.define('commentEdits', { | ||
commentId: { | ||
type: DataTypes.UUID, | ||
references: { | ||
model: 'comments', | ||
key: 'id' | ||
}, | ||
onDelete: 'CASCADE', | ||
allowNull: false | ||
}, | ||
body: { | ||
type: DataTypes.TEXT, | ||
allowNull: false | ||
}, | ||
createdAt: { | ||
type: DataTypes.DATE, | ||
default: true | ||
}, | ||
updatedAt: { | ||
type: DataTypes.DATE, | ||
default: true | ||
} | ||
}, {}); | ||
commentEdits.removeAttribute('id'); | ||
commentEdits.associate = (models) => { | ||
commentEdits.belongsTo(models.comments, { foreignKey: 'commentId', as: 'edits' }); | ||
}; | ||
return commentEdits; | ||
}; |
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
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.