Class: Api::Dashboard::NotificationsController
- Inherits:
-
BaseController
- Object
- ActionController::API
- BaseController
- Api::Dashboard::NotificationsController
- 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
Methods included from ControllerHelpers
#check_boolean_param, #get_banners, #inventory_params, #reservation_params
Methods included from ResponseCacheConcern
Instance Method Details
#index ⇒ Object
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, (pagy)).as_json end |
#mark_as_read ⇒ Object
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 |