-
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.
[ft-#167370397] allow admin to block/unblock reported comments
- Loading branch information
Showing
10 changed files
with
380 additions
and
4 deletions.
There are no files selected for viewing
6 changes: 3 additions & 3 deletions
6
...controllers/adminPermissionsController.js → ...llers/admin/adminPermissionsController.js
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,73 @@ | ||
import models from '../../models'; | ||
import status from '../../../helpers/constants/status.codes'; | ||
|
||
const { Comment } = models; | ||
|
||
/** | ||
* block and unblock reported comments | ||
* | ||
* @export | ||
* @class commentReportController | ||
*/ | ||
export default class commentReportController { | ||
/** | ||
* block Comment | ||
* | ||
* @static | ||
* @param {object} req - request body | ||
* @param {object} res - response body | ||
* @returns { object } - response | ||
* @memberof commentReportController | ||
*/ | ||
static async blockComment(req, res) { | ||
const { id } = req.params; | ||
const { body } = req; | ||
const isBlocked = true; | ||
|
||
await Comment.update({ | ||
isBlocked | ||
}, | ||
{ | ||
where: { | ||
id | ||
} | ||
}); | ||
return res.status(status.OK).json({ | ||
status: status.OK, | ||
message: `${body}:: blocked successfully`, | ||
data: { | ||
body | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* unblock Comment | ||
* | ||
* @static | ||
* @param {object} req - request body | ||
* @param {object} res - response body | ||
* @returns { object } - response | ||
* @memberof commentReportController | ||
*/ | ||
static async unBlockComment(req, res) { | ||
const { id } = req.params; | ||
const isBlocked = false; | ||
const { body } = req; | ||
await Comment.update({ | ||
isBlocked | ||
}, | ||
{ | ||
where: { | ||
id | ||
} | ||
}); | ||
return res.status(status.OK).json({ | ||
status: status.OK, | ||
message: `${body}:: unblocked successfully`, | ||
data: { | ||
body | ||
} | ||
}); | ||
} | ||
} |
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,8 @@ | ||
export default { | ||
up: (queryInterface, Sequelize) => queryInterface.addColumn('Comments', 'isBlocked', { | ||
type: Sequelize.BOOLEAN, | ||
defaultValue: false | ||
}), | ||
|
||
down: queryInterface => queryInterface.removeColumn('Comments', 'isBlocked') | ||
}; |
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,22 @@ | ||
export default { | ||
up: queryInterface => queryInterface.bulkInsert('ReportComments', | ||
[ | ||
{ | ||
userId: 12, | ||
reportedCommentId: 5, | ||
reasonId: 2, | ||
createdAt: new Date(), | ||
updatedAt: new Date() | ||
}, | ||
{ | ||
userId: 13, | ||
reportedCommentId: 6, | ||
reasonId: 1, | ||
createdAt: new Date(), | ||
updatedAt: new Date() | ||
} | ||
], | ||
{}), | ||
|
||
down: queryInterface => queryInterface.bulkDelete('ReportComments', null, {}) | ||
}; |
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,39 @@ | ||
import models from '../api/models'; | ||
import statusCode from '../helpers/constants/status.codes'; | ||
import sendError from '../helpers/error.sender'; | ||
|
||
const { Comment } = models; | ||
/** | ||
* check Comment middleware | ||
* | ||
* @export | ||
* @class checkIfCommentExist | ||
*/ | ||
class checkIfCommentExist { | ||
/** | ||
* this is a middleware which checks if comment exist. | ||
* | ||
* @author R | ||
* @static | ||
* @param {object} req the request | ||
* @param {object} res the response to be sent | ||
* @param { object } next A callback to allow the node process to continue | ||
* @memberof checkIfCommentExist | ||
* @returns {Object} res | ||
*/ | ||
static async checkIfExist(req, res, next) { | ||
const { id } = req.params; | ||
const result = await Comment.findOne({ | ||
where: { | ||
id | ||
} | ||
}); | ||
if (result) req.article = result.dataValues; | ||
|
||
return result | ||
? next() | ||
: sendError(statusCode.NOT_FOUND, res, 'id', `Comment with id ${id} is not found, Thanks`); | ||
} | ||
} | ||
|
||
export default checkIfCommentExist; |
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,43 @@ | ||
import models from '../api/models'; | ||
import status from '../helpers/constants/status.codes'; | ||
import sendError from '../helpers/error.sender'; | ||
|
||
const { Comment } = models; | ||
/** | ||
* check if Comment is blocked | ||
* | ||
* @export | ||
* @class checkIfBlocked | ||
*/ | ||
class checkIfBlocked { | ||
/** | ||
* this is a middleware which checks if a Comment is blocked. | ||
* | ||
* @static | ||
* @param {String} operation | ||
* @memberof checkComment | ||
* @returns {Object} res | ||
*/ | ||
static checkBlockedUnblocked(operation) { | ||
return async (req, res, next) => { | ||
const isBlocked = operation === 'blocked'; | ||
const messageString = isBlocked ? 'unblocked' : 'blocked'; | ||
const { id } = req.params; | ||
|
||
const result = await Comment.findOne({ | ||
where: { | ||
id, | ||
isBlocked | ||
} | ||
}); | ||
|
||
if (result) { | ||
req.body = result.dataValues.body; | ||
return next(); | ||
} | ||
sendError(status.BAD_REQUEST, res, 'isBlocked', `${id} is already ${messageString}`); | ||
}; | ||
} | ||
} | ||
|
||
export default checkIfBlocked; |
Oops, something went wrong.