mirror of
https://github.com/wassname/talk.git
synced 2026-07-22 13:00:29 +08:00
Enabling metadata for comment edition
This commit is contained in:
@@ -264,7 +264,7 @@ const setStatus = async ({ user, loaders: { Comments } }, { id, status }) => {
|
||||
* @param {Object} edit describes how to edit the comment
|
||||
* @param {String} edit.body the new Comment body
|
||||
*/
|
||||
const edit = async (ctx, { id, asset_id, edit: { body } }) => {
|
||||
const edit = async (ctx, { id, asset_id, edit: { body, metadata = {} } }) => {
|
||||
const { connectors: { services: { Moderation } } } = ctx;
|
||||
|
||||
// Build up the new comment we're setting. We need to check this with
|
||||
@@ -280,6 +280,7 @@ const edit = async (ctx, { id, asset_id, edit: { body } }) => {
|
||||
author_id: ctx.user.id,
|
||||
body,
|
||||
status,
|
||||
metadata,
|
||||
});
|
||||
|
||||
// Create all the actions that were determined during the moderation check
|
||||
|
||||
@@ -13,10 +13,10 @@ const RootMutation = {
|
||||
},
|
||||
editComment: async (
|
||||
_,
|
||||
{ id, asset_id, edit: { body } },
|
||||
{ id, asset_id, edit: { body, metadata } },
|
||||
{ mutators: { Comment } }
|
||||
) => ({
|
||||
comment: await Comment.edit({ id, asset_id, edit: { body } }),
|
||||
comment: await Comment.edit({ id, asset_id, edit: { body, metadata } }),
|
||||
}),
|
||||
createFlag: async (
|
||||
_,
|
||||
|
||||
@@ -84,7 +84,7 @@ module.exports = class CommentsService {
|
||||
* @param {String} body the new Comment body
|
||||
* @param {String} status the new Comment status
|
||||
*/
|
||||
static async edit({ id, author_id, body, status }) {
|
||||
static async edit({ id, author_id, body, status, metadata = {} }) {
|
||||
const EDITABLE_STATUSES = ['NONE', 'PREMOD', 'ACCEPTED'];
|
||||
const created_at = new Date();
|
||||
|
||||
@@ -110,6 +110,7 @@ module.exports = class CommentsService {
|
||||
$set: {
|
||||
body,
|
||||
status,
|
||||
metadata,
|
||||
},
|
||||
$push: {
|
||||
body_history: {
|
||||
@@ -164,11 +165,14 @@ module.exports = class CommentsService {
|
||||
body,
|
||||
created_at,
|
||||
});
|
||||
|
||||
editedComment.status_history.push({
|
||||
type: status,
|
||||
created_at,
|
||||
});
|
||||
|
||||
editedComment.metadata = metadata;
|
||||
|
||||
await events.emitAsync(COMMENTS_EDIT, originalComment, editedComment);
|
||||
|
||||
return editedComment;
|
||||
|
||||
Reference in New Issue
Block a user