mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
42 lines
1.2 KiB
JavaScript
42 lines
1.2 KiB
JavaScript
export default {
|
|
Mutation: {
|
|
disable: async (object, params, { user, driver }) => {
|
|
const { id } = params
|
|
const { id: userId } = user
|
|
const cypher = `
|
|
MATCH (u:User {id: $userId})
|
|
MATCH (resource {id: $id})
|
|
WHERE resource:User OR resource:Comment OR resource:Post
|
|
SET resource.disabled = true
|
|
MERGE (resource)<-[:DISABLED]-(u)
|
|
RETURN resource {.id}
|
|
`
|
|
const session = driver.session()
|
|
const res = await session.run(cypher, { id, userId })
|
|
session.close()
|
|
const [resource] = res.records.map(record => {
|
|
return record.get('resource')
|
|
})
|
|
if (!resource) return null
|
|
return resource.id
|
|
},
|
|
enable: async (object, params, { user, driver }) => {
|
|
const { id } = params
|
|
const cypher = `
|
|
MATCH (resource {id: $id})<-[d:DISABLED]-()
|
|
SET resource.disabled = false
|
|
DELETE d
|
|
RETURN resource {.id}
|
|
`
|
|
const session = driver.session()
|
|
const res = await session.run(cypher, { id })
|
|
session.close()
|
|
const [resource] = res.records.map(record => {
|
|
return record.get('resource')
|
|
})
|
|
if (!resource) return null
|
|
return resource.id
|
|
},
|
|
},
|
|
}
|