Skip to main content

Admin Products Module

The Admin Products module provides product catalog retrieval functionality for buyer-seller relationships within the DashClicks marketplace. This is a simple module with a single service method focused on retrieving available products based on buyer-seller account relationships.

🎯 Overview

This module handles product catalog queries for administrative purposes, specifically retrieving managed subscriptions that are available between buyer and seller accounts in the marketplace.

🔧 Service Method

getProducts()

Retrieves available products based on buyer-seller account relationships with comprehensive filtering and pagination.

Key Features:

  • Buyer-Seller Filtering: Filters products based on buyer and seller account relationships
  • Managed Subscriptions: Focuses on managed subscription products only
  • Order Validation: Excludes products that already have associated orders
  • Active Products: Only returns active products from the catalog
  • Pagination Support: Includes pagination for efficient data handling

API Endpoint: GET /v1/admin/products

Parameters:

  • buyer - Buyer account ID for product filtering
  • seller - Seller account ID for product filtering
  • page - Page number for pagination
  • limit - Number of products per page

Response Format:

{
"success": true,
"message": "SUCCESS",
"data": [...], // Array of product objects
"pagination": {
"page": 1,
"limit": 20,
"total": 150,
"totalPages": 8
}
}

🏗️ Technical Architecture

Database Operations

MongoDB Aggregation Pipeline:

The service uses a complex aggregation pipeline that:

  1. Matches Subscriptions: Filters by buyer account, seller account, and managed subscription types
  2. Order Lookup: Joins with orders collection to identify available products
  3. Excludes Ordered Products: Filters out products that already have orders
  4. Price Lookup: Retrieves pricing information for products
  5. Product Lookup: Gets product details and metadata
  6. Active Filter: Only includes active products
  7. Pagination: Implements skip/limit for efficient data retrieval

Collections Used:

  • _store.subscriptions - Core subscription data
  • _store.orders - Order information for filtering
  • _store.prices - Product pricing data
  • _store.products - Product catalog information

Business Logic

Product Filtering Logic:

  • Managed Subscriptions Only: Uses MANAGED_SUBSCRIPTIONS constant for filtering
  • Account Relationships: Enforces buyer-seller account relationships
  • Availability Check: Ensures products are available (no existing orders)
  • Active Status: Only returns products marked as active

Data Processing:

  • Faceted Aggregation: Uses MongoDB $facet for simultaneous data and count retrieval
  • Pagination: Implements skip/limit with total count calculation
  • Response Formatting: Standardized response with success status and pagination metadata

🔐 Authorization Framework

Access Control

Route Protection:

  • Rate Limiting: validateLimit middleware for API rate limiting
  • Administrative Access: Route accessible through admin routing structure
  • Account Validation: Buyer and seller account parameters required

Permission Requirements

  • Admin Access: Requires administrative authentication through admin routes
  • Marketplace Access: Access to buyer-seller product relationships
  • Product Visibility: Ability to view marketplace product catalog

📊 Product Data Structure

Response Data

Each product in the response includes:

  • Subscription Information: Core subscription metadata and configuration
  • Pricing Details: Product pricing information from linked price records
  • Product Metadata: Product details including name, description, and type
  • Account Context: Buyer and seller account relationship information
  • Availability Status: Product availability and order status

Query Parameters

Required Parameters:

  • buyer - Buyer account ObjectId for relationship filtering
  • seller - Seller account ObjectId for relationship filtering

Optional Parameters:

  • page - Page number for pagination (defaults to 0)
  • limit - Results per page for pagination control

🔄 Integration Points

Internal Systems

Store System Integration:

  • Subscription Management: Integrates with store subscription system
  • Order Processing: Coordinates with order management system
  • Product Catalog: Connects to product and pricing systems
  • Account Management: Validates buyer-seller account relationships

Data Dependencies

Collection Dependencies:

  • Store subscriptions for core product data
  • Orders for availability filtering
  • Prices for product pricing information
  • Products for catalog details and active status

📈 Usage Examples

Basic Product Retrieval

// Get products for buyer-seller relationship
const products = await getProducts({
buyerAccount: '64f1a2b3c4d5e6f7g8h9i0j1',
sellerAccount: '74f1a2b3c4d5e6f7g8h9i0j2',
page: 1,
limit: 20,
skip: 0,
});

API Endpoint Usage

GET /v1/admin/products?buyer=64f1a2b3c4d5e6f7g8h9i0j1&seller=74f1a2b3c4d5e6f7g8h9i0j2&page=1&limit=20

⚠️ Important Notes

  • Account Relationships: Both buyer and seller account IDs are required for proper filtering
  • Managed Subscriptions: Only returns products with managed subscription types
  • Order Filtering: Automatically excludes products that already have associated orders
  • Active Products: Only returns products marked as active in the catalog
  • Pagination: Supports pagination with efficient skip/limit implementation
  • Rate Limiting: API endpoint includes rate limiting for performance protection
  • ObjectId Validation: Account parameters must be valid MongoDB ObjectIds
💬

Documentation Assistant

Ask me anything about the docs

Hi! I'm your documentation assistant. Ask me anything about the docs!

I can help you with:
- Code examples
- Configuration details
- Troubleshooting
- Best practices

Try asking: How do I configure the API?
09:31 AM