Class: Dscf::Marketplace::MyResourceService
- Inherits:
-
Object
- Object
- Dscf::Marketplace::MyResourceService
- Defined in:
- app/services/dscf/marketplace/my_resource_service.rb
Instance Method Summary collapse
-
#initialize(current_user) ⇒ MyResourceService
constructor
A new instance of MyResourceService.
- #listings_by_supplier(supplier_id, params = {}) ⇒ Object
- #my_listings(params = {}) ⇒ Object
- #my_orders(params = {}) ⇒ Object
- #my_products(params = {}) ⇒ Object
- #my_quotes(params = {}) ⇒ Object
- #my_retailers(params = {}) ⇒ Object
- #my_rfqs(params = {}) ⇒ Object
Constructor Details
#initialize(current_user) ⇒ MyResourceService
Returns a new instance of MyResourceService.
4 5 6 |
# File 'app/services/dscf/marketplace/my_resource_service.rb', line 4 def initialize(current_user) @current_user = current_user end |
Instance Method Details
#listings_by_supplier(supplier_id, params = {}) ⇒ Object
56 57 58 59 60 61 62 |
# File 'app/services/dscf/marketplace/my_resource_service.rb', line 56 def listings_by_supplier(supplier_id, params = {}) listings = Dscf::Marketplace::Listing.joins(:supplier_product) .where(dscf_marketplace_supplier_products: {business_id: supplier_id}) .includes(:business, :supplier_product, :order_items, supplier_product: [ :product ]) apply_filters(listings, params) end |
#my_listings(params = {}) ⇒ Object
33 34 35 36 37 38 39 |
# File 'app/services/dscf/marketplace/my_resource_service.rb', line 33 def my_listings(params = {}) listings = Dscf::Marketplace::Listing.joins(:business) .where(dscf_core_businesses: {user_id: @current_user.id}) .includes(:business, :supplier_product, :order_items, supplier_product: [ :product ]) apply_filters(listings, params) end |
#my_orders(params = {}) ⇒ Object
8 9 10 11 12 13 14 15 16 |
# File 'app/services/dscf/marketplace/my_resource_service.rb', line 8 def my_orders(params = {}) # Sub-orders are the per-business halves of a split cart — the retailer # sees only the parent (with sub_orders nested), never the children as # separate rows. orders = Dscf::Marketplace::Order.where(ordered_by: @current_user, parent_order_id: nil) .includes(:quotation, :listing, :user, :ordered_by, :ordered_to, :delivery_order, :order_items, sub_orders: :order_items) apply_filters(orders, params) end |
#my_products(params = {}) ⇒ Object
48 49 50 51 52 53 54 |
# File 'app/services/dscf/marketplace/my_resource_service.rb', line 48 def my_products(params = {}) products = Dscf::Marketplace::SupplierProduct.joins(:business) .where(dscf_core_businesses: {user_id: @current_user.id}) .includes(:business, :product, :listings) apply_filters(products, params) end |
#my_quotes(params = {}) ⇒ Object
25 26 27 28 29 30 31 |
# File 'app/services/dscf/marketplace/my_resource_service.rb', line 25 def my_quotes(params = {}) quotes = Dscf::Marketplace::Quotation.joins(:request_for_quotation) .where(dscf_marketplace_request_for_quotations: {user_id: @current_user.id}) .includes(:request_for_quotation, :business, :quotation_items, :order) apply_filters(quotes, params) end |
#my_retailers(params = {}) ⇒ Object
41 42 43 44 45 46 |
# File 'app/services/dscf/marketplace/my_resource_service.rb', line 41 def my_retailers(params = {}) agent = Dscf::Marketplace::Agent.find_by(user_id: @current_user.id) retailers = agent ? Dscf::Marketplace::Retailer.where(agent_id: agent.id) : Dscf::Marketplace::Retailer.none apply_filters(retailers, params) end |
#my_rfqs(params = {}) ⇒ Object
18 19 20 21 22 23 |
# File 'app/services/dscf/marketplace/my_resource_service.rb', line 18 def my_rfqs(params = {}) rfqs = Dscf::Marketplace::RequestForQuotation.where(user: @current_user) .includes(:user, :selected_quotation, :rfq_items, :quotations) apply_filters(rfqs, params) end |