From 7424fc9774f3f1eeca565a35a5f7ab9751b4995d Mon Sep 17 00:00:00 2001 From: Belen Curcio Date: Wed, 12 Apr 2017 19:42:39 -0300 Subject: [PATCH] Create comments with Tags --- client/coral-framework/graphql/mutations/index.js | 1 - graph/mutators/comment.js | 9 ++++++--- graph/resolvers/root_mutation.js | 4 ++-- graph/typeDefs.graphql | 5 ++--- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/client/coral-framework/graphql/mutations/index.js b/client/coral-framework/graphql/mutations/index.js index 8b1feed66..9eb3d1a21 100644 --- a/client/coral-framework/graphql/mutations/index.js +++ b/client/coral-framework/graphql/mutations/index.js @@ -16,7 +16,6 @@ export const postComment = graphql(POST_COMMENT, { props: ({ownProps, mutate}) => ({ postItem: comment => { const {asset_id, body, parent_id, tags = []} = comment; - console.log(tags) return mutate({ variables: { comment diff --git a/graph/mutators/comment.js b/graph/mutators/comment.js index 728603ae2..982f7ade7 100644 --- a/graph/mutators/comment.js +++ b/graph/mutators/comment.js @@ -16,11 +16,14 @@ const Wordlist = require('../../services/wordlist'); * @param {String} [status='NONE'] the status of the new comment * @return {Promise} resolves to the created comment */ -const createComment = ({user, loaders: {Comments}}, {body, asset_id, parent_id = null}, status = 'NONE') => { +const createComment = ({user, loaders: {Comments}}, {body, asset_id, parent_id = null, tags = []}, status = 'NONE') => { - let tags = []; + // Building array of tags + tags = tags.map(tag => ({name: tag})); + + // If admin or moderator, adding STAFF tag if (user.hasRoles('ADMIN') || user.hasRoles('MODERATOR')) { - tags = [{name: 'STAFF'}]; + tags.push({name: 'STAFF'}); } return CommentsService.publicCreate({ diff --git a/graph/resolvers/root_mutation.js b/graph/resolvers/root_mutation.js index 9d7a1d1e6..641d566cb 100644 --- a/graph/resolvers/root_mutation.js +++ b/graph/resolvers/root_mutation.js @@ -2,8 +2,8 @@ const wrapResponse = require('../helpers/response'); const CommentsService = require('../../services/comments'); const RootMutation = { - createComment(_, {comment: {asset_id, parent_id, body}}, {mutators: {Comment}}) { - return wrapResponse('comment')(Comment.create({asset_id, parent_id, body})); + createComment(_, {comment}, {mutators: {Comment}}) { + return wrapResponse('comment')(Comment.create(comment)); }, createLike(_, {like: {item_id, item_type}}, {mutators: {Action}}) { return wrapResponse('like')(Action.create({item_id, item_type, action_type: 'LIKE'})); diff --git a/graph/typeDefs.graphql b/graph/typeDefs.graphql index 1b369329f..02eb02705 100644 --- a/graph/typeDefs.graphql +++ b/graph/typeDefs.graphql @@ -595,8 +595,7 @@ input CreateLikeInput { -enum TAG { - STAFF +enum TAG_TYPE { OFF_TOPIC } @@ -612,7 +611,7 @@ input CreateCommentInput { body: String! # Tags - tags: [TAG] + tags: [TAG_TYPE] }