Class: HasHelpers::Mutations::MarkIndividualAlertRead

Inherits:
Base
  • Object
show all
Defined in:
app/graphql/has_helpers/mutations/mark_individual_alert_read.rb

Instance Method Summary collapse

Methods included from HasHelpers::Middleware::ApplicationAccess

#authorized?

Instance Method Details

#resolve(alert_id:) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/graphql/has_helpers/mutations/mark_individual_alert_read.rb', line 10

def resolve(alert_id:)
  organization = context[:current_organization]
  return { success: false } unless organization

  alert = ::HasHelpers::NotificationAlert.find_by(
    id: alert_id,
    organization_id: organization.id
  )

  return { success: false } unless alert

  read_status = ::HasHelpers::NotificationAlertStatus::READ
  alert.update!(status: read_status)

  { success: true }
rescue => e
  Rails.logger.error "Error marking individual alert as read: #{e.message}"
  { success: false }
end