Sha256: ed438eff3058ad52757f6e1c5b654f36f4ee937502958f716fa702d87369613f
Contents?: true
Size: 930 Bytes
Versions: 5
Compression:
Stored size: 930 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).distinct menu_list = menu.select { |m| m.parent.nil? }.each_with_object([]) do |item, list| list << { id: item.id, text: item.label, iconCss: item.icon, items: [] } end menu_list.each do |ml| ml[:items] = menu.reject { |m| m.parent.nil? }.each_with_object([]) do |item, list| if item.parent_id == ml[:id] list << { id: item.id, text: item.label, iconCss: item.icon, url: item.route } end end end menu_list end end end end
Version data entries
5 entries across 5 versions & 1 rubygems