update posts with post type parameter

This commit is contained in:
Moriz Wahl 2023-03-29 17:36:36 +02:00
parent 2c52d08a94
commit f00b36b99e
2 changed files with 29 additions and 1 deletions

View File

@ -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) => {

View File

@ -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(() => {