From 7ac973f9a1d0e095d9275b0e63a762b9b26b984a Mon Sep 17 00:00:00 2001 From: mattwr18 Date: Wed, 5 Feb 2020 20:45:56 +0100 Subject: [PATCH] Refactor cypher statement to simplify - it's questionable whether this simplifies it or not, and actually adds one line of code, but now it looks more similiar to the code in the notifications query --- .../notifications/notificationsMiddleware.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/backend/src/middleware/notifications/notificationsMiddleware.js b/backend/src/middleware/notifications/notificationsMiddleware.js index 9890979e9..11337468c 100644 --- a/backend/src/middleware/notifications/notificationsMiddleware.js +++ b/backend/src/middleware/notifications/notificationsMiddleware.js @@ -53,8 +53,7 @@ const notifyUsersOfMention = async (label, id, idsOfUsers, reason, context) => { WHERE user.id in $idsOfUsers AND NOT (user)-[:BLOCKED]-(author) MERGE (post)-[notification:NOTIFIED {reason: $reason}]->(user) - WITH notification, user, - post {.*, __typename: labels(post)[0], author: properties(author) } AS finalResource + WITH post AS resource, notification, user ` break } @@ -66,14 +65,17 @@ const notifyUsersOfMention = async (label, id, idsOfUsers, reason, context) => { AND NOT (user)-[:BLOCKED]-(commenter) AND NOT (user)-[:BLOCKED]-(postAuthor) MERGE (comment)-[notification:NOTIFIED {reason: $reason}]->(user) - WITH notification, user, - comment {.*, __typename: labels(comment)[0], author: properties(commenter), post: post {.*, author: properties(postAuthor)} } AS finalResource + WITH comment AS resource, notification, user ` break } } mentionedCypher += ` - WITH notification, finalResource, user + WITH notification, user, resource, + [(resource)<-[:WROTE]-(author:User) | author {.*}] AS authors, + [(resource)-[:COMMENTS]->(post:Post)<-[:WROTE]-(author:User) | post{.*, author: properties(author)} ] AS posts + WITH resource, user, notification, authors, posts, + resource {.*, __typename: labels(resource)[0], author: authors[0], post: posts[0]} AS finalResource SET notification.read = FALSE SET notification.createdAt = COALESCE(notification.createdAt, toString(datetime())) SET notification.updatedAt = toString(datetime())