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

View File

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