Class: Api::Partner::V1::NotificationsController
- Inherits:
-
BaseController
- Object
- ActionController::API
- BaseController
- Api::Partner::V1::NotificationsController
- Defined in:
- app/controllers/api/partner/v1/notifications_controller.rb
Instance Method Summary collapse
Methods inherited from BaseController
#default_restaurant, #identity_cache_memoization, #render_unauthorize_action, #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 |
# File 'app/controllers/api/partner/v1/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::Partner::TransactionNotifSerializer.new(notifs, (pagy)).as_json end |
#mark_as_read ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'app/controllers/api/partner/v1/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: restaurants.ids) 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: I18n.t('notifications.mark_as_read.success'), success: true } end |