metamaps--metamaps/app/decorators/notification_decorator.rb

48 lines
1.3 KiB
Ruby
Raw Normal View History

2017-09-22 22:38:38 +00:00
class NotificationDecorator
class << self
def decorate(notification, receipt)
result = {
id: notification.id,
type: notification.notification_code,
subject: notification.subject,
is_read: receipt.is_read,
created_at: notification.created_at,
actor: notification.sender,
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
}
end
result
end
end
end