diff --git a/backend/src/middleware/notifications/notificationsMiddleware.js b/backend/src/middleware/notifications/notificationsMiddleware.js index b55f798f1..effb7f4d0 100644 --- a/backend/src/middleware/notifications/notificationsMiddleware.js +++ b/backend/src/middleware/notifications/notificationsMiddleware.js @@ -27,7 +27,10 @@ const notifyUsers = async (label, id, idsOfUsers, reason, context) => { MERGE (post)-[notification:NOTIFIED {reason: $reason}]->(user) SET notification.read = FALSE SET notification.updatedAt = toString(datetime()) - SET notification.createdAt = toString(datetime()) + SET ( + CASE + WHEN notification.createdAt IS NULL + THEN notification END ).createdAt = toString(datetime()) ` break } @@ -41,7 +44,10 @@ const notifyUsers = async (label, id, idsOfUsers, reason, context) => { MERGE (comment)-[notification:NOTIFIED {reason: $reason}]->(user) SET notification.read = FALSE SET notification.updatedAt = toString(datetime()) - SET notification.createdAt = toString(datetime()) + SET ( + CASE + WHEN notification.createdAt IS NULL + THEN notification END ).createdAt = toString(datetime()) ` break } @@ -55,7 +61,10 @@ const notifyUsers = async (label, id, idsOfUsers, reason, context) => { MERGE (comment)-[notification:NOTIFIED {reason: $reason}]->(user) SET notification.read = FALSE SET notification.updatedAt = toString(datetime()) - SET notification.createdAt = toString(datetime()) + SET ( + CASE + WHEN notification.createdAt IS NULL + THEN notification END ).createdAt = toString(datetime()) ` break } diff --git a/backend/src/middleware/notifications/notificationsMiddleware.spec.js b/backend/src/middleware/notifications/notificationsMiddleware.spec.js index b737768f2..94fb18668 100644 --- a/backend/src/middleware/notifications/notificationsMiddleware.spec.js +++ b/backend/src/middleware/notifications/notificationsMiddleware.spec.js @@ -391,7 +391,7 @@ describe('notifications', () => { expect(Date.parse(createdAtBefore)).toEqual(expect.any(Number)) expect(createdAtAfter).toBeTruthy() expect(Date.parse(createdAtAfter)).toEqual(expect.any(Number)) - expect(createdAtBefore).not.toEqual(createdAtAfter) + expect(createdAtBefore).toEqual(createdAtAfter) }) }) }) diff --git a/backend/src/schema/resolvers/comments.js b/backend/src/schema/resolvers/comments.js index 7310b7af8..f507897c5 100644 --- a/backend/src/schema/resolvers/comments.js +++ b/backend/src/schema/resolvers/comments.js @@ -21,7 +21,7 @@ export default { SET comment.createdAt = toString(datetime()) SET comment.updatedAt = toString(datetime()) MERGE (post)<-[:COMMENTS]-(comment)<-[:WROTE]-(author) - RETURN comment, author + RETURN comment ` const transactionRes = await session.run(createCommentCypher, { userId: context.user.id, @@ -30,12 +30,7 @@ export default { }) session.close() - const [response] = transactionRes.records.map(record => { - return { - ...record.get('comment').properties, - author: record.get('author').properties, - } - }) + const [response] = transactionRes.records.map(record => record.get('comment').properties) return response },