10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'app/graphql/has_helpers/resolvers/list_notification_alerts.rb', line 10
def resolve(limit:)
organization = context[:current_organization]
return { alertGroups: [] } unless organization
all_alerts = ::HasHelpers::NotificationAlert.
where(organization_id: organization.id).
active.
includes(:status, :alert_type).
order(created_at: :desc).
limit(limit)
grouped_alerts = all_alerts.group_by(&:alert_type)
alert_groups = grouped_alerts.map do |alert_type, type_alerts|
visible_alerts = type_alerts.select do |alert|
["Unread", "Fixed"].include?(alert.status.name)
end
{
alertType: alert_type.name,
hasAnyRecords: type_alerts.any?,
alerts: visible_alerts.map do |alert|
{
id: alert.id,
payload: alert.payload,
status: alert.status.name,
createdAt: alert.created_at
}
end
}
end
{ alertGroups: alert_groups }
end
|