nest inconsistent data under data key

This commit is contained in:
Connor Turland 2017-09-23 11:20:02 -04:00
parent 9cc700c64d
commit fc8ac6eef1

View file

@ -8,38 +8,40 @@ class NotificationDecorator
is_read: receipt.is_read, is_read: receipt.is_read,
created_at: notification.created_at, created_at: notification.created_at,
actor: notification.sender, actor: notification.sender,
object: notification.notified_object data: {
object: notification.notified_object
}
} }
case notification.notification_code case notification.notification_code
when MAP_ACCESS_APPROVED, MAP_ACCESS_REQUEST, MAP_INVITE_TO_EDIT when MAP_ACCESS_APPROVED, MAP_ACCESS_REQUEST, MAP_INVITE_TO_EDIT
map = notification.notified_object&.map map = notification.notified_object&.map
result[:map] = { result[:data][:map] = {
id: map&.id, id: map&.id,
name: map&.name name: map&.name
} }
when TOPIC_ADDED_TO_MAP when TOPIC_ADDED_TO_MAP
topic = notification.notified_object&.eventable topic = notification.notified_object&.eventable
map = notification.notified_object&.map map = notification.notified_object&.map
result[:topic] = { result[:data][:topic] = {
id: topic&.id, id: topic&.id,
name: topic&.name name: topic&.name
} }
result[:map] = { result[:data][:map] = {
id: map&.id, id: map&.id,
name: map&.name name: map&.name
} }
when TOPIC_CONNECTED_1, TOPIC_CONNECTED_2 when TOPIC_CONNECTED_1, TOPIC_CONNECTED_2
topic1 = notification.notified_object&.topic1 topic1 = notification.notified_object&.topic1
topic2 = notification.notified_object&.topic2 topic2 = notification.notified_object&.topic2
result[:topic1] = { result[:data][:topic1] = {
id: topic1&.id, id: topic1&.id,
name: topic1&.name name: topic1&.name
} }
resul[:topic2] = { resul[:data][:topic2] = {
id: topic2&.id, id: topic2&.id,
name: topic2&.name name: topic2&.name
} }
end end
result result
end end