From fc8ac6eef149db11a0182a45032686fe6974edb8 Mon Sep 17 00:00:00 2001 From: Connor Turland Date: Sat, 23 Sep 2017 11:20:02 -0400 Subject: [PATCH] nest inconsistent data under data key --- app/decorators/notification_decorator.rb | 60 ++++++++++++------------ 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/app/decorators/notification_decorator.rb b/app/decorators/notification_decorator.rb index bec0685c..5669fb9c 100644 --- a/app/decorators/notification_decorator.rb +++ b/app/decorators/notification_decorator.rb @@ -8,38 +8,40 @@ class NotificationDecorator is_read: receipt.is_read, created_at: notification.created_at, actor: notification.sender, - object: notification.notified_object + data: { + object: notification.notified_object + } } case notification.notification_code - when MAP_ACCESS_APPROVED, MAP_ACCESS_REQUEST, MAP_INVITE_TO_EDIT - map = notification.notified_object&.map - result[:map] = { - id: map&.id, - name: map&.name - } - when TOPIC_ADDED_TO_MAP - topic = notification.notified_object&.eventable - map = notification.notified_object&.map - result[:topic] = { - id: topic&.id, - name: topic&.name - } - result[:map] = { - id: map&.id, - name: map&.name - } - when TOPIC_CONNECTED_1, TOPIC_CONNECTED_2 - topic1 = notification.notified_object&.topic1 - topic2 = notification.notified_object&.topic2 - result[:topic1] = { - id: topic1&.id, - name: topic1&.name - } - resul[:topic2] = { - id: topic2&.id, - name: topic2&.name - } + when MAP_ACCESS_APPROVED, MAP_ACCESS_REQUEST, MAP_INVITE_TO_EDIT + map = notification.notified_object&.map + result[:data][:map] = { + id: map&.id, + name: map&.name + } + when TOPIC_ADDED_TO_MAP + topic = notification.notified_object&.eventable + map = notification.notified_object&.map + result[:data][:topic] = { + id: topic&.id, + name: topic&.name + } + result[:data][:map] = { + id: map&.id, + name: map&.name + } + when TOPIC_CONNECTED_1, TOPIC_CONNECTED_2 + topic1 = notification.notified_object&.topic1 + topic2 = notification.notified_object&.topic2 + result[:data][:topic1] = { + id: topic1&.id, + name: topic1&.name + } + resul[:data][:topic2] = { + id: topic2&.id, + name: topic2&.name + } end result end