mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
Finish refactor of notifications resolver
This commit is contained in:
parent
79d23cc6de
commit
760fd01715
@ -76,16 +76,21 @@ export default {
|
|||||||
markAsRead: async (parent, args, context, resolveInfo) => {
|
markAsRead: async (parent, args, context, resolveInfo) => {
|
||||||
const { user: currentUser } = context
|
const { user: currentUser } = context
|
||||||
const session = context.driver.session()
|
const session = context.driver.session()
|
||||||
|
const writeTxResultPromise = session.writeTransaction(async transaction => {
|
||||||
|
const markNotificationAsReadTransactionResponse = await transaction.run(
|
||||||
|
`
|
||||||
|
MATCH (resource {id: $resourceId})-[notification:NOTIFIED {read: FALSE}]->(user:User {id:$id})
|
||||||
|
SET notification.read = TRUE
|
||||||
|
RETURN resource, notification, user
|
||||||
|
`,
|
||||||
|
{ resourceId: args.id, id: currentUser.id },
|
||||||
|
)
|
||||||
|
log(markNotificationAsReadTransactionResponse)
|
||||||
|
return markNotificationAsReadTransactionResponse.records.map(transformReturnType)
|
||||||
|
})
|
||||||
try {
|
try {
|
||||||
const cypher = `
|
const [notifications] = await writeTxResultPromise
|
||||||
MATCH (resource {id: $resourceId})-[notification:NOTIFIED {read: FALSE}]->(user:User {id:$id})
|
return notifications
|
||||||
SET notification.read = TRUE
|
|
||||||
RETURN resource, notification, user
|
|
||||||
`
|
|
||||||
const result = await session.run(cypher, { resourceId: args.id, id: currentUser.id })
|
|
||||||
log(result)
|
|
||||||
const notifications = await result.records.map(transformReturnType)
|
|
||||||
return notifications[0]
|
|
||||||
} finally {
|
} finally {
|
||||||
session.close()
|
session.close()
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user