Sha256: 77d0f6daaac01d2e0724bb4eb9dbb37296ed07730557e84aca3efb63db775e00
Contents?: true
Size: 955 Bytes
Versions: 11
Compression:
Stored size: 955 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 { success: true, data: menu_list } end end end end
Version data entries
11 entries across 11 versions & 1 rubygems