Matt Rider d15857d240 Set user's posts/comments' delete attribute to true
- favor over actually deleting the node so that the comments will appear as anonymous and not lose the context of the conversation
- the post will not appear, but for admin it will be accessible
- follow @roschaefer `PR` review
2019-06-12 15:27:57 -03:00

38 lines
1.2 KiB
JavaScript

import { neo4jgraphql } from 'neo4j-graphql-js'
import fileUpload from './fileUpload'
export default {
Mutation: {
UpdateUser: async (object, params, context, resolveInfo) => {
params = await fileUpload(params, { file: 'avatarUpload', url: 'avatar' })
return neo4jgraphql(object, params, context, resolveInfo, false)
},
CreateUser: async (object, params, context, resolveInfo) => {
params = await fileUpload(params, { file: 'avatarUpload', url: 'avatar' })
return neo4jgraphql(object, params, context, resolveInfo, false)
},
DeleteUser: async (object, params, context, resolveInfo) => {
const { resource } = params
const session = context.driver.session()
if (resource && resource.length) {
await Promise.all(
resource.map(async node => {
await session.run(
`
MATCH (resource:${node})<-[:WROTE]-(author:User {id: $userId})
SET resource.deleted = true
RETURN author`,
{
userId: context.user.id,
},
)
}),
)
session.close()
}
return neo4jgraphql(object, params, context, resolveInfo, false)
},
},
}