Class: Api::Dashboard::V2::NotificationsController

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

Instance Method Summary collapse

Methods inherited from BaseController

#set_options

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
# File 'app/controllers/api/dashboard/v2/notifications_controller.rb', line 4

def index
  notifs = TransactionNotif.by_restaurant(restaurants.ids)
                           .is_read_by(params[:is_read], current_staff)
                           .by_type(params[:types].to_s.split(',').map(&:strip))
                           .last_3_months

  pagy, notifs = pagy(notifs.order(created_at: :desc))
  render json: ::Api::Dashboard::V2::TransactionNotifSerializer.new(notifs, set_options(pagy)).as_json
end

#mark_as_readObject



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

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

  notifs = TransactionNotif.unread_by(current_staff).where(restaurant_id: restaurant_ids_param)
  notifs = notifs.where(id: notification_ids) unless ActiveModel::Type::Boolean.new.cast(is_all)

  notifs.find_each do |notif|
    notif.mark_as_read! for: current_staff
  end

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