🛍️ Product Blocks
Product blocks provide comprehensive functionality for product management in Nodeblocks applications. These blocks handle product lifecycle operations including creation, catalog management, and inventory tracking.
🎯 Overview
Product blocks are designed to:
- Manage product catalog with full CRUD operations
- Handle product variants for inventory and customization management
- Handle product images with metadata and automatic entity generation
- Normalize product data with signed URLs for images in API responses
- Handle product attributes and variations
- Provide product validation and business rules
- Support inventory management and tracking
- Enable product administration with comprehensive controls
📦 Block Types
🔍 Schemas
JSON Schema definitions for product data validation:
- productSchema: Base product entity structure
- productImageSchema: Product image metadata structure
- createProductImageSchema: Product image creation validation
- deleteProductImageSchema: Product image deletion validation
- imageIdPathParameter: Path parameter for image ID
- ProductImage: TypeScript type for product image data
- NormalizedProductImage: TypeScript type for normalized product image with URL
- createProductSchema: Product creation validation with images
- updateProductSchema: Product update validation
- createProductBatchSchema: Batch creation validation with images
- updateProductBatchSchema: Batch update validation
- deleteProductBatchSchema: Batch deletion validation
- copyProductBatchSchema: Batch copy validation
- getProductSchema: Single product retrieval validation
- deleteProductSchema: Product deletion validation
- copyProductSchema: Product copy validation
- findProductsSchema: Product search with filtering and pagination
- createProductVariantBulkSchema: Product variant bulk creation with array validation
- updateProductVariantBulkSchema: Product variant bulk update with bulk operation validation
- deleteProductVariantBulkSchema: Product variant bulk deletion with variant ID array validation
- createProductVariantSchema: Product variant creation with required title validation
- getProductVariantSchema: Product variant retrieval with path parameters
- updateProductVariantSchema: Product variant update with optional fields
- deleteProductVariantSchema: Product variant deletion with path parameters
- findProductVariantsSchema: Product variant listing with pagination validation
- getProductLikersSchema: Product likers retrieval validation
🧱 Block Functions
Pure functions for product operations and data transformation:
Product Retrieval:
- getProductById: Retrieves a product by ID from the products collection
- findProducts: Retrieves products from database collection based on filter criteria
Product Variant Management:
- createProductVariant: Creates a new product variant for an existing product
- createProductVariantBulk: Creates multiple product variants in bulk within single database operation
- updateProductVariant: Updates a single product variant
- updateProductVariantBulk: Updates multiple product variants in bulk via database collection update operation
- deleteProductVariant: Deletes a single product variant
- deleteProductVariantBulk: Deletes multiple product variants in bulk from MongoDB collection
- getProductVariantById: Retrieves a product variant by ID with optional product scoping
- findProductVariants: Finds product variants for a specific product
- buildFilterToGetProductVariantsByProductId: Builds database filter to retrieve product variants by product ID
- buildFilterToGetProductVariantsByIds: Builds database filter to retrieve product variants by their IDs
Product Normalization:
- normalizeProduct: Normalizes a single product by removing _id field
- normalizeProducts: Normalizes multiple products by removing _id fields
Product Image Normalization:
- normalizeProductImage: Normalizes a single product image by generating signed download URL
- normalizeImagesOfProduct: Normalizes images for a single product with signed URLs
- normalizeImagesOfProducts: Normalizes images for multiple products with signed URLs
Product Image Management:
- generateProductImageUploadUrl: Generates signed URL for product image upload
- createProductImage: Creates a new product image and adds it to the product's images array
- getProductImageById: Retrieves a specific product image by its ID
- deleteProductImage: Deletes a specific product image from a product
- deleteImagesOfProduct: Deletes all images associated with a product from file storage
Query Builder Blocks:
- findProductResources: Finds product resources with flexible filtering
- buildProductLikersByLikeProductIdQuery: Builds MongoDB query for product likers
Error Classes:
- ProductBlockError: Base error class for product-related block operations
- ProductNotFoundBlockError: Product not found error
- ProductUnexpectedDBError: Unexpected database error for products
- ProductImageNotFoundBlockError: Product image not found error
- ProductDbError: Product database operation error
- ProductVariantError: Base error class for product variant operations
- ProductVariantDbError: Product variant database operation error
- ProductVariantNotFoundError: Product variant not found error
View Product Block Functions →
⚙️ Handlers
Core business logic for product operations:
- createProduct: Product creation
- createProductBatch: Batch product creation
- getProductById: Product data retrieval (deprecated - use block function instead)
- getProductsByIds: Retrieve multiple products by IDs
- updateProduct: Product updates
- updateProductBatch: Batch product updates
- deleteProduct: Product deletion
- deleteProductBatch: Batch product deletion
- copyProduct: Product copying
- copyProductBatch: Batch product copying
- findProducts: Product search and filtering (deprecated - use block function instead)
- normalizeProductTerminator: Normalize single product response
- normalizeProductsListTerminator: Normalize products list response
- deleteProductTerminator: Format 204 response for product deletion
- deleteBatchProductsTerminator: Format 204 response for batch product deletion
🛣️ Routes
HTTP endpoint definitions for product operations:
- createProductRoute: POST
/productswith creation handler - createProductBatchRoute: POST
/products/batchwith batch creation handler - createProductVariantRoute: POST
/products/:productId/variantsfor creating product variants - createProductVariantBulkRoute: POST
/product/:productId/variants/bulkfor bulk creating product variants - updateProductVariantBulkRoute: PATCH
/product/:productId/variants/bulkfor bulk updating product variants - deleteProductVariantBulkRoute: POST
/product/:productId/variants/bulk-deletefor bulk deleting product variants - findProductVariantsRoute: GET
/products/:productId/variantsfor listing product variants with pagination - getProductVariantRoute: GET
/products/:productId/variants/:productVariantIdfor retrieving product variants - updateProductVariantRoute: PATCH
/products/:productId/variants/:productVariantIdfor updating product variants - deleteProductVariantRoute: DELETE
/products/:productId/variants/:productVariantIdfor deleting product variants - getProductRoute: GET
/products/:productIdwith retrieval handler - findProductsRoute: GET
/productswith search and pagination - getProductImageUploadUrlRoute: GET
/products/:productId/image-upload-urlfor signed upload URLs - createProductImageRoute: POST
/products/:productId/imagesfor adding images to products - deleteProductImageRoute: DELETE
/products/:productId/images/:imageIdfor removing images from products - updateProductRoute: PATCH
/products/:productIdwith update handler - updateProductBatchRoute: PATCH
/products/batchwith batch update handler - deleteProductRoute: DELETE
/products/:productIdwith deletion handler - deleteProductBatchRoute: DELETE
/products/batchwith batch deletion handler - copyProductRoute: POST
/products/:productId/copywith copy handler - copyProductBatchRoute: POST
/products/batch/copywith batch copy handler - findProductsByOrganizationIdRoute: GET
/products/organizations/:organizationIdwith organization-scoped product retrieval - getProductLikersRoute: GET
/products/:productId/likerswith product likers retrieval and pagination
🚀 Features
Complete product management features combining schemas, routes, and handlers:
- createProductFeature: Product creation with schema validation and routing
- createProductBatchFeature: Batch product creation with schema validation and routing
- createProductVariantFeature: Product variant creation with schema validation and routing
- createProductVariantBulkFeature: Product variant bulk creation with schema validation and routing
- updateProductVariantBulkFeature: Product variant bulk update with schema validation and routing
- deleteProductVariantBulkFeature: Product variant bulk deletion with schema validation and routing
- findProductVariantsFeature: Product variant listing with pagination, schema validation and routing
- getProductVariantFeature: Product variant retrieval with schema validation and routing
- updateProductVariantFeature: Product variant update with schema validation and routing
- deleteProductVariantFeature: Product variant deletion with schema validation and routing
- getProductFeatures: Product retrieval for getting individual product data
- findProductsFeatures: Product search with filtering and pagination
- editProductFeatures: Product update with schema validation and routing
- editProductBatchFeatures: Batch product update with schema validation and routing
- deleteProductFeatures: Product deletion with routing
- deleteProductBatchFeatures: Batch product deletion with schema validation and routing
- copyProductFeatures: Product copying with routing
- copyProductBatchFeatures: Batch product copying with schema validation and routing
- getProductImageUploadUrlFeature: Product image upload URL generation
- createProductImageFeature: Product image creation with schema validation and routing
- deleteProductImageFeature: Product image deletion with schema validation and file storage cleanup
- findProductsByOrganizationIdFeature: Organization-scoped product retrieval with pagination
- getProductLikersFeature: Product likers retrieval with pagination and avatar normalization
🔗 Related Documentation
- Product Schemas - Product data validation and contracts
- Product Handlers - Product business logic functions
- Product Routes - HTTP endpoint definitions
- Product Features - Complete product management features