From f00b36b99ec039d00401b8476dba90ae6eb32cbb Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Wed, 29 Mar 2023 17:36:36 +0200 Subject: [PATCH] update posts with post type parameter --- backend/src/schema/resolvers/posts.js | 11 ++++++++++- backend/src/schema/resolvers/posts.spec.js | 19 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/backend/src/schema/resolvers/posts.js b/backend/src/schema/resolvers/posts.js index cc3dad8fd..b21373d89 100644 --- a/backend/src/schema/resolvers/posts.js +++ b/backend/src/schema/resolvers/posts.js @@ -184,7 +184,16 @@ export default { ` } - updatePostCypher += `RETURN post {.*}` + if (params.postType) { + updatePostCypher += ` + REMOVE post:Article + REMOVE post:Event + SET post:${params.postType} + WITH post + ` + } + + updatePostCypher += `RETURN post {.*, postType: filter(l IN labels(post) WHERE NOT l = "Post")}` const updatePostVariables = { categoryIds, params } try { const writeTxResultPromise = session.writeTransaction(async (transaction) => { diff --git a/backend/src/schema/resolvers/posts.spec.js b/backend/src/schema/resolvers/posts.spec.js index 47992dc60..1f9b646e8 100644 --- a/backend/src/schema/resolvers/posts.spec.js +++ b/backend/src/schema/resolvers/posts.spec.js @@ -354,6 +354,7 @@ describe('UpdatePost', () => { $content: String! $image: ImageInput $categoryIds: [ID] + $postType: PostType ) { UpdatePost( id: $id @@ -361,6 +362,7 @@ describe('UpdatePost', () => { content: $content image: $image categoryIds: $categoryIds + postType: $postType ) { id title @@ -374,6 +376,7 @@ describe('UpdatePost', () => { categories { id } + postType } } ` @@ -495,6 +498,22 @@ describe('UpdatePost', () => { }) }) + describe('post type', () => { + it.only('changes the post type', async () => { + await expect( + mutate({ mutation: updatePostMutation, variables: { ...variables, postType: 'Event' } }), + ).resolves.toMatchObject({ + data: { + UpdatePost: { + id: newlyCreatedPost.id, + postType: ['Event'], + }, + }, + errors: undefined, + }) + }) + }) + describe.skip('params.image', () => { describe('is object', () => { beforeEach(() => {