diff --git a/graph/mutators/comment.js b/graph/mutators/comment.js index 7e0607287..df180627f 100644 --- a/graph/mutators/comment.js +++ b/graph/mutators/comment.js @@ -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 diff --git a/graph/resolvers/root_mutation.js b/graph/resolvers/root_mutation.js index 8a638f589..ef583e06c 100644 --- a/graph/resolvers/root_mutation.js +++ b/graph/resolvers/root_mutation.js @@ -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 ( _, diff --git a/services/comments.js b/services/comments.js index 68f991324..5ac61764d 100644 --- a/services/comments.js +++ b/services/comments.js @@ -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;