Class: SpreeCmCommissioner::NotificationReader

Inherits:
BaseInteractor show all
Defined in:
app/interactors/spree_cm_commissioner/notification_reader.rb

Instance Method Summary collapse

Instance Method Details

#callObject



5
6
7
8
# File 'app/interactors/spree_cm_commissioner/notification_reader.rb', line 5

def call
  read_specific_notification if id.present?
  read_all_user_unread_notifications if user.present?
end

#read_all_user_unread_notificationsObject



17
18
19
# File 'app/interactors/spree_cm_commissioner/notification_reader.rb', line 17

def read_all_user_unread_notifications
  user.notifications.unread_notifications.mark_as_read!
end

#read_specific_notificationObject



10
11
12
13
14
15
# File 'app/interactors/spree_cm_commissioner/notification_reader.rb', line 10

def read_specific_notification
  notification = SpreeCmCommissioner::Notification.find_by(id: id)
  return context.fail!(error_message: 'Notification not found') if notification.nil?

  notification.mark_as_read! if notification.unread?
end