メインコンテンツまでスキップ
バージョン: 🚧 Canary

🚀 Order Features

Order features provide complete, pre-composed functionality for order management operations in Nodeblocks applications. These features combine schemas, routes, and handlers to create ready-to-use API endpoints for order CRUD operations, search, and lifecycle management.


🎯 Overview

Order features are designed to:

  • Provide complete order management with full CRUD operations
  • Support order lifecycle management from creation to completion
  • Include validation and routing for secure order operations
  • Support filtering and pagination for order listings
  • Handle order items and total calculations

📋 Feature Structure

Each order feature follows a consistent composition pattern:

  • Schema: Validates order input data and parameters
  • Route: Provides HTTP endpoint with order handlers
  • Composition: Combines schema and route using compose function

🔧 Available Order Features

createOrderFeature

Order creation feature with schema validation and routing.

Purpose: Handles order creation with complete validation

Composition:

Usage:

import { features } from '@nodeblocks/backend-sdk';


// With database configuration
app.use('/api', defService(partial(features.createOrderFeature, [{ dataStores: db }])));

API Endpoint: POST /api/orders


updateOrderFeature

Order update feature with schema validation and routing.

Purpose: Modifies order information with proper validation

Composition:

Usage:

import { features } from '@nodeblocks/backend-sdk';


// With database configuration
app.use('/api', defService(partial(features.updateOrderFeature, [{ dataStores: db }])));

API Endpoint: PATCH /api/orders/:orderId


getOrderFeature

Order retrieval feature for getting individual order data.

Purpose: Fetches order information with proper validation

Composition:

Usage:

import { features } from '@nodeblocks/backend-sdk';


// With database configuration
app.use('/api', defService(partial(features.getOrderFeature, [{ dataStores: db }])));

API Endpoint: GET /api/orders/:orderId


findOrdersFeature

Order search feature with filtering and pagination.

Purpose: Provides order listing with search capabilities

Composition:

Usage:

import { features } from '@nodeblocks/backend-sdk';


// With database configuration
app.use('/api', defService(partial(features.findOrdersFeature, [{ dataStores: db }])));

API Endpoint: GET /api/orders


deleteOrderFeature

Order deletion feature with routing.

Purpose: Removes orders with access control and cleanup

Composition:

Usage:

import { features } from '@nodeblocks/backend-sdk';


// With database configuration
app.use('/api', defService(partial(features.deleteOrderFeature, [{ dataStores: db }])));

API Endpoint: DELETE /api/orders/:orderId


findOrdersByOrganizationIdFeature

Order retrieval by organization ID feature with schema validation and routing.

Purpose: Lists orders scoped to a specific organization with filtering, pagination, and data normalization

Composition:

Usage:

import { features } from '@nodeblocks/backend-sdk';

// Direct usage:
app.use('/api', defService(findOrdersByOrganizationIdFeature));

// With database configuration:
app.use('/api', defService(partial(findOrdersByOrganizationIdFeature, [{ dataStores: db }])));

API Endpoint: GET /api/orders/organizations/:organizationId

Request Parameters:

  • Path Parameters:
    • organizationId (required): Target organization ID to retrieve orders for
  • Query Parameters:
    • page (optional): Page number for pagination (default: 1)
    • limit (optional): Number of orders per page (default: 10)

Response (200 - Success):

{
"data": [
{
"id": "order-123",
"organizationId": "org-456",
"currency": "USD",
"status": "confirmed",
"createdAt": "2024-01-01T00:00:00.000Z",
"updatedAt": "2024-01-01T00:00:00.000Z"
}
],
"metadata": {
"pagination": {
"hasNext": false,
"hasPrev": false,
"limit": 10,
"page": 1,
"total": 1,
"totalPages": 1
}
}
}

Authorization:

  • Requires authentication
  • Restricted to organization members with 'owner', 'admin', or 'member' roles via hasOrgRole(['owner', 'admin', 'member'])

Error Responses:

  • 401: Unauthorized - Invalid or missing authentication token
  • 403: Forbidden - User lacks organization access or insufficient role permissions
  • 500: Internal Server Error - Database or normalization error

Key Features:

  • Organization Scoping: Orders are automatically filtered by organization membership
  • Role-Based Access: Access restricted to organization owners, admins, and members
  • Pagination Support: Full pagination with metadata for large order collections
  • Data Normalization: Automatic document normalization for clean API responses