Class: Api::Dashboard::NotificationsController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/api/dashboard/notifications_controller.rb

Instance Method Summary collapse

Methods inherited from BaseController

#current_user, #identity_cache_memoization, #restaurants, #set_options

Methods included from LogrageCustomLogger

#append_info_to_payload

Methods included from ControllerHelpers

#check_boolean_param, #get_banners, #inventory_params, #reservation_params

Methods included from ResponseCacheConcern

#my_response_cache

Instance Method Details

#indexObject



4
5
6
7
8
9
10
11
12
13
# File 'app/controllers/api/dashboard/notifications_controller.rb', line 4

def index
  unread_only = params.fetch(:unread_only, false).to_s
  notifs = if unread_only == 'true'
             TransactionNotif.unread_by(current_staff).where(restaurant_id: restaurant_ids_param).includes(reservation: :restaurant)
           else
             TransactionNotif.where(restaurant_id: restaurant_ids_param).includes(reservation: :restaurant)
           end
  pagy, notifs = pagy(notifs.order(created_at: :desc))
  render json: ::Api::Dashboard::TransactionNotifSerializer.new(notifs, set_options(pagy)).as_json
end

#mark_as_readObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/api/dashboard/notifications_controller.rb', line 15

def mark_as_read
  is_all = params.fetch(:all, 'false').to_s
  notification_ids = Array.wrap(params.fetch(:ids, []))

  if is_all == 'true'
    TransactionNotif.unread_by(current_staff).where(restaurant_id: restaurant_ids_param).find_each do |notif|
      notif.mark_as_read! for: current_staff
    end
  else
    TransactionNotif.where(id: notification_ids).where(restaurant_id: restaurant_ids_param).find_each do |notif|
      notif.mark_as_read! for: current_staff
    end
  end

  render json: { data: [], message: 'Notification marked as read successfully', success: true }
end