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

52 lines
1.4 KiB
Ruby
Raw Normal View History

2017-10-13 16:22:05 +00:00
# frozen_string_literal: true
2017-11-25 19:23:47 +00:00
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,
2017-09-23 15:20:02 +00:00
data: {
object: notification.notified_object
}
2017-09-22 22:38:38 +00:00
}
case notification.notification_code
2017-10-13 16:22:05 +00:00
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
}
result[:data][:topic2] = {
id: topic2&.id,
name: topic2&.name
}
2017-09-22 22:38:38 +00:00
end
result
end
end
end