Class: EventNotificationConfigurationsController

Inherits:
ApplicationController show all
Includes:
ApplicationHelper, TimeHelper
Defined in:
app/controllers/event_notification_configurations_controller.rb

Instance Method Summary collapse

Methods included from TimeHelper

#cron_with_zone, #destructure_seconds

Methods included from AuthentificationHelper

#accessible_company_ids_from_tenant_and_user, #application_mode_from_hostname, #current_company_id_from_accessible_company_ids, #current_tenant_from_user, #current_user_and_locale_from_token

Instance Method Details

#indexObject



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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/controllers/event_notification_configurations_controller.rb', line 17

def index
  query = params[:query] || ''
  order = params[:order] || 'desc'
  order_by = params[:orderBy] || 'event_notification_configuration_id'
  limit = params[:limit] || 100
  offset = params[:offset] || 0
  tag_ids = params[:tag_ids] || []

  event_notification_configurations = current_company.event_notification_configurations
                                                     .for_tags(tag_ids)
                                                     .includes(:tags)

  data,  = fetch_records(
    records: event_notification_configurations,
    order_by: order_by,
    order: order,
    query: query,
    limit: limit,
    offset: offset,
    fields: %i[
      event_notification_configuration_id
      event_slug
      active
      max_age
    ]
  ).values_at(:data, :metadata)

  data = data.as_json(
    methods: %i[
      name
      description
    ],
    include: [
      :tags
    ]
  )

  render json: {
    data: data,
    metadata: 
  }
end

#showObject



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'app/controllers/event_notification_configurations_controller.rb', line 60

def show
  event_notification_configuration = current_company.event_notification_configurations
                                                    .includes(:tags)
                                                    .find(params[:id])

  data = event_notification_configuration.as_json(
    methods: %i[
      name
      delivery_methods
      description
      schedule_cron
      respect_business_hours
      last_deliveries
      limit_type
      schedule_type
      dummy_email_html
    ],
    include: [
      :tags
    ]
  )

  render json: {
    data: data
  }
end

#updateObject



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'app/controllers/event_notification_configurations_controller.rb', line 87

def update
  event_notification_configuration = current_company.event_notification_configurations
                                                    .includes(:tags)
                                                    .find(params[:id])

  event_notification_configuration.update!(record_attributes)

  render json: {
    message: I18n.t('messages.event_notification_configuration_updated'),
    data: event_notification_configuration
  }
rescue ActiveRecord::RecordInvalid => e
  render json: {
    errors: e.record.errors,
    message: e.record.errors.full_messages.join(', '),
    redirect_to: "/app/notifications/types/#{e.record.id}/"
  }, status: :bad_request
end