From cbcba8f08d74833ee6babf868daf33231cfd4355 Mon Sep 17 00:00:00 2001 From: roschaefer Date: Fri, 30 Aug 2019 12:46:36 +0200 Subject: [PATCH] Follow @Tirokk's suggestion --- .../middleware/notifications/notificationsMiddleware.js | 8 ++++---- .../notifications/notificationsMiddleware.spec.js | 2 +- backend/src/schema/resolvers/notifications.js | 8 ++++---- backend/src/schema/types/enum/ReasonNotification.gql | 4 ++-- backend/src/schema/types/type/NOTIFIED.gql | 2 +- .../notifications/Notification/Notification.spec.js | 4 ++-- webapp/locales/de.json | 2 +- webapp/locales/en.json | 2 +- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/backend/src/middleware/notifications/notificationsMiddleware.js b/backend/src/middleware/notifications/notificationsMiddleware.js index 054519289..64386800d 100644 --- a/backend/src/middleware/notifications/notificationsMiddleware.js +++ b/backend/src/middleware/notifications/notificationsMiddleware.js @@ -4,13 +4,13 @@ const notifyUsers = async (label, id, idsOfUsers, reason, context) => { if (!idsOfUsers.length) return // Checked here, because it does not go through GraphQL checks at all in this file. - const reasonsAllowed = ['mentioned_in_post', 'mentioned_in_comment', 'comment_on_post'] + const reasonsAllowed = ['mentioned_in_post', 'mentioned_in_comment', 'commented_on_post'] if (!reasonsAllowed.includes(reason)) { throw new Error('Notification reason is not allowed!') } if ( (label === 'Post' && reason !== 'mentioned_in_post') || - (label === 'Comment' && !['mentioned_in_comment', 'comment_on_post'].includes(reason)) + (label === 'Comment' && !['mentioned_in_comment', 'commented_on_post'].includes(reason)) ) { throw new Error('Notification does not fit the reason!') } @@ -44,7 +44,7 @@ const notifyUsers = async (label, id, idsOfUsers, reason, context) => { ` break } - case 'comment_on_post': { + case 'commented_on_post': { cypher = ` MATCH (postAuthor: User)-[:WROTE]->(post: Post)<-[:COMMENTS]-(comment: Comment { id: $id })<-[:WROTE]-(author: User) MATCH (user: User) @@ -108,7 +108,7 @@ const handleCreateComment = async (resolve, root, args, context, resolveInfo) => return record.get('user') }) if (context.user.id !== postAuthor.id) { - await notifyUsers('Comment', comment.id, [postAuthor.id], 'comment_on_post', context) + await notifyUsers('Comment', comment.id, [postAuthor.id], 'commented_on_post', context) } } diff --git a/backend/src/middleware/notifications/notificationsMiddleware.spec.js b/backend/src/middleware/notifications/notificationsMiddleware.spec.js index 66d86c645..acdb6afe8 100644 --- a/backend/src/middleware/notifications/notificationsMiddleware.spec.js +++ b/backend/src/middleware/notifications/notificationsMiddleware.spec.js @@ -162,7 +162,7 @@ describe('notifications', () => { { read: false, createdAt: expect.any(String), - reason: 'comment_on_post', + reason: 'commented_on_post', from: { __typename: 'Comment', id: 'c47', diff --git a/backend/src/schema/resolvers/notifications.js b/backend/src/schema/resolvers/notifications.js index 2385c4b1a..65c92b4be 100644 --- a/backend/src/schema/resolvers/notifications.js +++ b/backend/src/schema/resolvers/notifications.js @@ -16,7 +16,7 @@ const transformReturnType = record => { export default { Query: { notifications: async (parent, args, context, resolveInfo) => { - const { user } = context + const { user: currentUser } = context const session = context.driver.session() let notifications let whereClause @@ -49,7 +49,7 @@ export default { RETURN resource, notification, user ${orderByClause} ` - const result = await session.run(cypher, { id: user.id }) + const result = await session.run(cypher, { id: currentUser.id }) notifications = await result.records.map(transformReturnType) } finally { session.close() @@ -59,7 +59,7 @@ export default { }, Mutation: { markAsRead: async (parent, args, context, resolveInfo) => { - const { user } = context + const { user: currentUser } = context const session = context.driver.session() let notification try { @@ -68,7 +68,7 @@ export default { SET notification.read = TRUE RETURN resource, notification, user ` - const result = await session.run(cypher, { resourceId: args.id, id: user.id }) + const result = await session.run(cypher, { resourceId: args.id, id: currentUser.id }) const notifications = await result.records.map(transformReturnType) notification = notifications[0] } finally { diff --git a/backend/src/schema/types/enum/ReasonNotification.gql b/backend/src/schema/types/enum/ReasonNotification.gql index a66c446be..e870e01dc 100644 --- a/backend/src/schema/types/enum/ReasonNotification.gql +++ b/backend/src/schema/types/enum/ReasonNotification.gql @@ -1,5 +1,5 @@ enum ReasonNotification { mentioned_in_post mentioned_in_comment - comment_on_post -} \ No newline at end of file + commented_on_post +} diff --git a/backend/src/schema/types/type/NOTIFIED.gql b/backend/src/schema/types/type/NOTIFIED.gql index 965ee56d6..b90e30598 100644 --- a/backend/src/schema/types/type/NOTIFIED.gql +++ b/backend/src/schema/types/type/NOTIFIED.gql @@ -16,7 +16,7 @@ enum NotificationOrdering { enum NotificationReason { mentioned_in_post mentioned_in_comment - comment_on_post + commented_on_post } type Query { diff --git a/webapp/components/notifications/Notification/Notification.spec.js b/webapp/components/notifications/Notification/Notification.spec.js index 6ba38e53a..9e5586fc2 100644 --- a/webapp/components/notifications/Notification/Notification.spec.js +++ b/webapp/components/notifications/Notification/Notification.spec.js @@ -37,7 +37,7 @@ describe('Notification', () => { describe('given a notification about a comment on a post', () => { beforeEach(() => { propsData.notification = { - reason: 'comment_on_post', + reason: 'commented_on_post', from: { __typename: 'Comment', id: 'comment-1', @@ -56,7 +56,7 @@ describe('Notification', () => { it('renders reason', () => { wrapper = Wrapper() expect(wrapper.find('.reason-text-for-test').text()).toEqual( - 'notifications.menu.comment_on_post', + 'notifications.menu.commented_on_post', ) }) it('renders title', () => { diff --git a/webapp/locales/de.json b/webapp/locales/de.json index bb70ed36e..aa8ff433e 100644 --- a/webapp/locales/de.json +++ b/webapp/locales/de.json @@ -134,7 +134,7 @@ "menu": { "mentioned_in_post": "Hat dich in einem Beitrag erwähnt …", "mentioned_in_comment": "Hat dich in einem Kommentar erwähnt …", - "comment_on_post": "Hat deinen Beitrag kommentiert …" + "commented_on_post": "Hat deinen Beitrag kommentiert …" } }, "search": { diff --git a/webapp/locales/en.json b/webapp/locales/en.json index 94451fa88..f0053f1a1 100644 --- a/webapp/locales/en.json +++ b/webapp/locales/en.json @@ -134,7 +134,7 @@ "menu": { "mentioned_in_post": "Mentioned you in a post …", "mentioned_in_comment": "Mentioned you in a comment …", - "comment_on_post": "Commented on your post …" + "commented_on_post": "Commented on your post …" } }, "search": {