Class: Api::Dashboard::BaseController
- Inherits:
-
ActionController::API
- Object
- ActionController::API
- Api::Dashboard::BaseController
- Includes:
- ControllerHelpers, ElasticApmContext, Knock::Authenticable, LogrageCustomLogger, Pagy::Backend, Pundit::Authorization, ResponseCacheConcern
- Defined in:
- app/controllers/api/dashboard/base_controller.rb
Direct Known Subclasses
AccountsController, AnalyticsController, CuisinesController, DashboardsController, FaqController, InventoriesController, NotificationsController, OwnerReviewsController, ReportsController, ReservationsController, RestaurantsController, ReviewsController, StaffsController, V2::BaseController
Defined Under Namespace
Classes: NotAuthorized
Instance Method Summary collapse
- #current_user ⇒ Object
- #identity_cache_memoization(&block) ⇒ Object
-
#restaurants ⇒ Object
def authenticate_roles current_user.roles.pluck(:restaurant_id).include?() end.
- #set_options(pagy = {}) ⇒ Object
Methods included from LogrageCustomLogger
Methods included from ControllerHelpers
#check_boolean_param, #get_banners, #inventory_params, #reservation_params
Methods included from ResponseCacheConcern
Instance Method Details
#current_user ⇒ Object
76 77 78 |
# File 'app/controllers/api/dashboard/base_controller.rb', line 76 def current_user @current_user ||= current_staff end |
#identity_cache_memoization(&block) ⇒ Object
30 31 32 |
# File 'app/controllers/api/dashboard/base_controller.rb', line 30 def identity_cache_memoization(&block) IdentityCache.cache.with_memoization(&block) end |
#restaurants ⇒ Object
def authenticate_roles
current_user.roles.pluck(:restaurant_id).include?()
end
41 42 43 44 45 46 47 |
# File 'app/controllers/api/dashboard/base_controller.rb', line 41 def restaurants @restaurants ||= if params[:restaurant_id].present? current_staff.restaurants.where(id: params[:restaurant_id]) else current_staff.restaurants end end |
#set_options(pagy = {}) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'app/controllers/api/dashboard/base_controller.rb', line 49 def (pagy = {}) Pagy::VARS[:items] = params.fetch('per_page', 15) = {} if pagy.present? [:meta] = { total: (pagy).fetch(:count), page: (pagy).fetch(:page), total_page: (pagy).fetch(:pages), default_page: 1, } [:links] = { self: (pagy).fetch(:page_url), first: (pagy).fetch(:first_url), next: (pagy).fetch(:next_url), prev: (pagy).fetch(:prev_url), last: (pagy).fetch(:last_url), } end [:include] = params.fetch(:include, '').split(',') || [] [:fields] = params.fetch(:fields, {}).to_unsafe_hash.map do |rel, fields| { rel => fields.split(',').map(&:to_sym) } end.reduce({}, :merge) || {} [:params] = { current_staff: current_staff } () end |