Sha256: d5d1b835e357a069be1bdd39e517d01e50174ed48fe1d7d909d8bb5c21878a80
Contents?: true
Size: 932 Bytes
Versions: 13
Compression:
Stored size: 932 Bytes
Contents
module Ecom module Core class MenuService def fetch_menu(user) role_ids = user.user_roles.map(&:id) join_sql = <<-SQL INNER JOIN ecom_core_menus_user_roles MUR ON MUR.menu_id = ecom_core_menus.id INNER JOIN ecom_core_user_roles UR ON MUR.user_role_id = UR.id SQL menu = Menu.joins(join_sql).where('UR.id IN (?)', role_ids).order(:id).distinct menu_list = menu.select { |m| m.parent.nil? }.each_with_object([]) do |item, list| list << { id: item.id, label: item.label, icon: item.icon, items: [] } end menu_list.each do |ml| ml[:items] = menu.reject { |m| m.parent.nil? }.each_with_object([]) do |item, list| list << { id: item.id, label: item.label, icon: item.icon, url: item.route } if item.parent_id == ml[:id] end end { success: true, data: menu_list } end end end end
Version data entries
13 entries across 13 versions & 1 rubygems