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,
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