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 filteringseller- Seller account ID for product filteringpage- Page number for paginationlimit- 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:
- Matches Subscriptions: Filters by buyer account, seller account, and managed subscription types
- Order Lookup: Joins with orders collection to identify available products
- Excludes Ordered Products: Filters out products that already have orders
- Price Lookup: Retrieves pricing information for products
- Product Lookup: Gets product details and metadata
- Active Filter: Only includes active products
- 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_SUBSCRIPTIONSconstant 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
$facetfor 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:
validateLimitmiddleware 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 filteringseller- 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