From 7ddbab83e98e09cfac41e3ed18ea2fb5eb468faa Mon Sep 17 00:00:00 2001 From: ALau2088 Date: Sat, 18 May 2019 23:32:24 -0700 Subject: [PATCH] 552-update_comment --- backend/src/resolvers/comments.js | 54 +++++++++++++++---------------- 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/backend/src/resolvers/comments.js b/backend/src/resolvers/comments.js index 8023fb334..72d2f96fb 100644 --- a/backend/src/resolvers/comments.js +++ b/backend/src/resolvers/comments.js @@ -40,6 +40,7 @@ export default { if (!post) { throw new UserInputError(NO_POST_ERR_MESSAGE) } + const comment = await neo4jgraphql( object, params, @@ -67,7 +68,6 @@ export default { // Strip element tags and remove leading/trailing white spaces from content const content = params.content.replace(/<(?:.|\n)*?>/gm, '').trim() const { id } = params - console.log(id) // Check length of content if (!params.content || content.length < COMMENT_MIN_LENGTH) { throw new UserInputError( @@ -79,49 +79,47 @@ export default { const session = context.driver.session() const commentQueryRes = await session.run( ` - MATCH (comment: COMMENT) - WHERE id(comment)=$id + MATCH (comment: Comment { id:$id}) RETURN comment`, { id } ) - console.log(id) - console.log(commentQueryRes) + // Destructure content from session results array const [comment] = commentQueryRes.records.map(record => { - console.log(record.get('comment')) + const a = record.get('comment') + console.log(a) return record.get('comment') }) // Send error message if cannot find a matching comment. - // if (!comment) { - // throw new UserInputError(NO_COMMENT_ERR_MESSAGE) - // } + if (!comment) { + throw new UserInputError(NO_COMMENT_ERR_MESSAGE) + } // Update comment. - // const commentRev = await neo4jgraphql( - // object, - // params, - // context, - // resolveInfo, - // false - // ) + const commentRev = await neo4jgraphql( + object, + params, + context, + resolveInfo, + false + ) - // await session.run( - // ` - // MATCH (comment:Comment) - // WHERE id(comment)=$id, - // SET comment.content = $content - // `, - // { - // id, - // content - // } - // ) + await session.run( + ` + MATCH (comment: Comment { id:$id}) + SET comment.content = 'bbb' + `, + { + id, + content + } + ) session.close() - // return commentRev + return commentRev } } }