mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
52 lines
1.4 KiB
JavaScript
52 lines
1.4 KiB
JavaScript
export default {
|
|
Mutation: {
|
|
shout: async (_object, params, context, _resolveInfo) => {
|
|
const { id, type } = params
|
|
|
|
const session = context.driver.session()
|
|
const transactionRes = await session.run(
|
|
`MATCH (node {id: $id})<-[:WROTE]-(userWritten:User), (user:User {id: $userId})
|
|
WHERE $type IN labels(node) AND NOT userWritten.id = $userId
|
|
MERGE (user)-[relation:SHOUTED{createdAt:toString(datetime())}]->(node)
|
|
RETURN COUNT(relation) > 0 as isShouted`,
|
|
{
|
|
id,
|
|
type,
|
|
userId: context.user.id,
|
|
},
|
|
)
|
|
|
|
const [isShouted] = transactionRes.records.map(record => {
|
|
return record.get('isShouted')
|
|
})
|
|
|
|
session.close()
|
|
|
|
return isShouted
|
|
},
|
|
|
|
unshout: async (_object, params, context, _resolveInfo) => {
|
|
const { id, type } = params
|
|
const session = context.driver.session()
|
|
|
|
const transactionRes = await session.run(
|
|
`MATCH (user:User {id: $userId})-[relation:SHOUTED]->(node {id: $id})
|
|
WHERE $type IN labels(node)
|
|
DELETE relation
|
|
RETURN COUNT(relation) > 0 as isShouted`,
|
|
{
|
|
id,
|
|
type,
|
|
userId: context.user.id,
|
|
},
|
|
)
|
|
const [isShouted] = transactionRes.records.map(record => {
|
|
return record.get('isShouted')
|
|
})
|
|
session.close()
|
|
|
|
return isShouted
|
|
},
|
|
},
|
|
}
|