mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
Dry out resolver
This commit is contained in:
parent
6e420d68d1
commit
ed5f14d052
@ -12,29 +12,20 @@ export default {
|
||||
return neo4jgraphql(object, params, context, resolveInfo, false)
|
||||
},
|
||||
DeleteUser: async (object, params, context, resolveInfo) => {
|
||||
const { comments, posts } = params
|
||||
const { resource } = params
|
||||
const session = context.driver.session()
|
||||
if (comments) {
|
||||
await session.run(
|
||||
`
|
||||
MATCH (comments:Comment)<-[:WROTE]-(author:User {id: $userId})
|
||||
DETACH DELETE comments
|
||||
RETURN author`,
|
||||
{
|
||||
userId: context.user.id,
|
||||
},
|
||||
)
|
||||
}
|
||||
if (posts) {
|
||||
await session.run(
|
||||
`
|
||||
MATCH (posts:Post)<-[:WROTE]-(author:User {id: $userId})
|
||||
DETACH DELETE posts
|
||||
RETURN author`,
|
||||
{
|
||||
userId: context.user.id,
|
||||
},
|
||||
)
|
||||
if (resource && resource.length) {
|
||||
resource.forEach(async node => {
|
||||
await session.run(
|
||||
`
|
||||
MATCH (resource:${node})<-[:WROTE]-(author:User {id: $userId})
|
||||
DETACH DELETE resource
|
||||
RETURN author`,
|
||||
{
|
||||
userId: context.user.id,
|
||||
},
|
||||
)
|
||||
})
|
||||
}
|
||||
session.close()
|
||||
return neo4jgraphql(object, params, context, resolveInfo, false)
|
||||
|
||||
@ -88,8 +88,8 @@ describe('users', () => {
|
||||
let deleteUserVariables
|
||||
let asAuthor
|
||||
const deleteUserMutation = gql`
|
||||
mutation($id: ID!, $comments: Boolean, $posts: Boolean) {
|
||||
DeleteUser(id: $id, comments: $comments, posts: $posts) {
|
||||
mutation($id: ID!, $resource: [String]) {
|
||||
DeleteUser(id: $id, resource: $resource) {
|
||||
id
|
||||
}
|
||||
}
|
||||
@ -209,8 +209,18 @@ describe('users', () => {
|
||||
})
|
||||
|
||||
describe("deletes a user's", () => {
|
||||
it('posts on request', async () => {
|
||||
deleteUserVariables = { id: 'u343', resource: ['Post'] }
|
||||
await client.request(deleteUserMutation, deleteUserVariables)
|
||||
const postQueryVariablesByContent = {
|
||||
content: 'Post by user u343',
|
||||
}
|
||||
const { Post } = await client.request(postQuery, postQueryVariablesByContent)
|
||||
expect(Post).toEqual([])
|
||||
})
|
||||
|
||||
it('comments on request', async () => {
|
||||
deleteUserVariables = { id: 'u343', comments: true }
|
||||
deleteUserVariables = { id: 'u343', resource: ['Comment'] }
|
||||
await client.request(deleteUserMutation, deleteUserVariables)
|
||||
const commentQueryVariablesByContent = {
|
||||
content: 'Comment by user u343',
|
||||
@ -219,14 +229,19 @@ describe('users', () => {
|
||||
expect(Comment).toEqual([])
|
||||
})
|
||||
|
||||
it('posts on request', async () => {
|
||||
deleteUserVariables = { id: 'u343', posts: true }
|
||||
it('posts and comments on request', async () => {
|
||||
deleteUserVariables = { id: 'u343', resource: ['Post', 'Comment'] }
|
||||
await client.request(deleteUserMutation, deleteUserVariables)
|
||||
const postQueryVariablesByContent = {
|
||||
content: 'Post by user u343',
|
||||
}
|
||||
const commentQueryVariablesByContent = {
|
||||
content: 'Comment by user u343',
|
||||
}
|
||||
const { Post } = await client.request(postQuery, postQueryVariablesByContent)
|
||||
const { Comment } = await client.request(commentQuery, commentQueryVariablesByContent)
|
||||
expect(Post).toEqual([])
|
||||
expect(Comment).toEqual([])
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@ -38,7 +38,7 @@ type Mutation {
|
||||
follow(id: ID!, type: FollowTypeEnum): Boolean!
|
||||
# Unfollow the given Type and ID
|
||||
unfollow(id: ID!, type: FollowTypeEnum): Boolean!
|
||||
DeleteUser(id: ID!, comments: Boolean, posts: Boolean): User
|
||||
DeleteUser(id: ID!, resource: [String]): User
|
||||
}
|
||||
|
||||
type Statistics {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user