Enabling metadata for comment edition

This commit is contained in:
okbel
2018-02-22 10:34:22 -03:00
parent 6f6fe69129
commit 4579537709
3 changed files with 9 additions and 4 deletions
+2 -1
View File
@@ -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
+2 -2
View File
@@ -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 (
_,
+5 -1
View File
@@ -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;