diff --git a/backend/src/graphql/resolvers/posts.ts b/backend/src/graphql/resolvers/posts.ts
index 2a70857ec..50aa6050e 100644
--- a/backend/src/graphql/resolvers/posts.ts
+++ b/backend/src/graphql/resolvers/posts.ts
@@ -203,6 +203,7 @@ export default {
// return null
// }
+ // Attachments
const writeFilesPromise = session.writeTransaction(async (transaction) => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const atns: any[] = []
@@ -224,6 +225,7 @@ export default {
const atns = await writeFilesPromise
+ // TODO: this can be removed if we can insert the file before the psot
for await (const atn of atns) {
post.content = post.content.replace(
`
`,
@@ -257,13 +259,15 @@ export default {
},
UpdatePost: async (_parent, params, context: Context, _resolveInfo) => {
const { config } = context
- const { categoryIds } = params
+ const { categoryIds, files = [] } = params
+ console.log(files)
const { image: imageInput } = params
const locationName = validateEventParams(params)
delete params.categoryIds
delete params.image
+ delete params.files
const session = context.driver.session()
let updatePostCypher = `
MATCH (post:Post {id: $params.id})
@@ -310,12 +314,59 @@ export default {
)
const [post] = updatePostTransactionResponse.records.map((record) => record.get('post'))
await images(context.config).mergeImage(post, 'HERO_IMAGE', imageInput, { transaction })
+
return post
})
const post = await writeTxResultPromise
if (locationName) {
await createOrUpdateLocations('Post', post.id, locationName, session, context)
}
+
+ // Attachments
+ const writeFilesPromise = session.writeTransaction(async (transaction) => {
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ const atns: any[] = []
+
+ for await (const file of files) {
+ const atn = await attachments(CONFIG).add(
+ post,
+ 'ATTACHMENT',
+ file,
+ {},
+ {
+ transaction,
+ },
+ )
+ atns.push(atn)
+ }
+ return atns
+ })
+
+ const atns = await writeFilesPromise
+
+ // TODO: this can be removed if we can insert the file before the psot
+ for await (const atn of atns) {
+ post.content = post.content.replace(
+ `
`,
+ `
`,
+ )
+ post.contentExcerpt = post.contentExcerpt.replace(
+ `
`,
+ `
`,
+ )
+ }
+
+ await context.database.write({
+ query: `
+ MATCH (post:Post {id: $post.id})
+ SET post.content = $post.content
+ SET post.contentExcerpt = $post.contentExcerpt
+ `,
+ variables: {
+ post,
+ },
+ })
+
return post
} finally {
await session.close()
diff --git a/backend/src/graphql/types/type/Post.gql b/backend/src/graphql/types/type/Post.gql
index d742a6938..7a35ab0d9 100644
--- a/backend/src/graphql/types/type/Post.gql
+++ b/backend/src/graphql/types/type/Post.gql
@@ -232,6 +232,7 @@ type Mutation {
slug: String
content: String!
contentExcerpt: String
+ files: [FileInput]
image: ImageInput,
visibility: Visibility
language: String
diff --git a/webapp/graphql/PostMutations.js b/webapp/graphql/PostMutations.js
index 5059654b5..6ef0d5ccf 100644
--- a/webapp/graphql/PostMutations.js
+++ b/webapp/graphql/PostMutations.js
@@ -62,6 +62,7 @@ export default () => {
$id: ID!
$title: String!
$content: String!
+ $files: [FileInput]
$image: ImageInput
$categoryIds: [ID]
$postType: PostType
@@ -71,6 +72,7 @@ export default () => {
id: $id
title: $title
content: $content
+ files: $files
image: $image
categoryIds: $categoryIds
postType: $postType