Implement disabling of comments+users+posts

This commit is contained in:
Robert Schäfer 2019-03-06 17:12:30 +01:00
parent 1c34f10f96
commit f40a67b7a8
2 changed files with 10 additions and 8 deletions

View File

@ -1,28 +1,28 @@
export default {
Mutation: {
disable: async (object, params, { user, driver }) => {
const { resource: { id: postId } } = params
const { resource: { id } } = params
const { id: userId } = user
const cypher = `
MATCH (u:User {id: $userId})
MATCH (p:Post {id: $postId})
SET p.disabled = true
MERGE (p)<-[:DISABLED]-(u)
MATCH (r {id: $id})
SET r.disabled = true
MERGE (r)<-[:DISABLED]-(u)
`
const session = driver.session()
const res = await session.run(cypher, { postId, userId })
const res = await session.run(cypher, { id, userId })
session.close()
return Boolean(res)
},
enable: async (object, params, { user, driver }) => {
const { resource: { id: postId } } = params
const { resource: { id } } = params
const cypher = `
MATCH (p:Post {id: $postId})<-[d:DISABLED]-()
MATCH (p {id: $id})<-[d:DISABLED]-()
SET p.disabled = false
DELETE d
`
const session = driver.session()
const res = await session.run(cypher, { postId })
const res = await session.run(cypher, { id })
session.close()
return Boolean(res)
}

View File

@ -76,6 +76,7 @@ type User {
avatar: String
deleted: Boolean
disabled: Boolean
disabledBy: User @relation(name: "DISABLED", direction: "IN")
role: UserGroupEnum
location: Location @cypher(statement: "MATCH (this)-[:IS_IN]->(l:Location) RETURN l")
@ -165,6 +166,7 @@ type Comment {
updatedAt: String
deleted: Boolean
disabled: Boolean
disabledBy: User @relation(name: "DISABLED", direction: "IN")
}
type Report {