From b034d22732eac595d5d8d59133aad0c5cdfa047b Mon Sep 17 00:00:00 2001 From: Matt Rider Date: Mon, 1 Jul 2019 18:50:24 -0300 Subject: [PATCH] Fix failing cypress test --- backend/src/schema/resolvers/posts.js | 13 ++++++------- webapp/graphql/PostMutations.js | 1 - 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/backend/src/schema/resolvers/posts.js b/backend/src/schema/resolvers/posts.js index 261ca8caa..0c8dfb7f0 100644 --- a/backend/src/schema/resolvers/posts.js +++ b/backend/src/schema/resolvers/posts.js @@ -4,23 +4,22 @@ import fileUpload from './fileUpload' export default { Mutation: { UpdatePost: async (object, params, context, resolveInfo) => { - const { id: postId, categoryIds } = params + const { categoryIds } = params delete params.categoryIds params = await fileUpload(params, { file: 'imageUpload', url: 'image' }) - const session = context.driver.session() const cypherDeletePreviousRelations = ` - MATCH (post:Post { id: $postId })-[previousRelations:CATEGORIZED]->(category:Category) + MATCH (post:Post { id: $params.id })-[previousRelations:CATEGORIZED]->(category:Category) DELETE previousRelations RETURN post, category ` - await session.run(cypherDeletePreviousRelations, { postId }) + await session.run(cypherDeletePreviousRelations, { params }) - let updatePostCypher = `MATCH (post:Post {id: $postId}) + let updatePostCypher = `MATCH (post:Post {id: $params.id}) SET post = $params ` - if (categoryIds) { + if (categoryIds && categoryIds.length) { updatePostCypher += `WITH post UNWIND $categoryIds AS categoryId MATCH (category:Category {id: categoryId}) @@ -28,7 +27,7 @@ export default { ` } updatePostCypher += `RETURN post` - const updatePostVariables = { postId, categoryIds, params } + const updatePostVariables = { categoryIds, params } const transactionRes = await session.run(updatePostCypher, updatePostVariables) const [post] = transactionRes.records.map(record => { diff --git a/webapp/graphql/PostMutations.js b/webapp/graphql/PostMutations.js index 0aac535ca..dba8d32a5 100644 --- a/webapp/graphql/PostMutations.js +++ b/webapp/graphql/PostMutations.js @@ -22,7 +22,6 @@ export default () => { content contentExcerpt language - image } } `,