Skip to main content
Version: 0.6.0 (Latest)

🔍 Order Schema Blocks

Order schema blocks provide JSON Schema definitions for order data validation in Nodeblocks applications. These schemas ensure data integrity and provide clear contracts for order-related API endpoints.


🎯 Overview

Order schema blocks are designed to:

  • Validate order data before processing
  • Support complex order structures with line items and pricing
  • Handle multiple currencies and tax calculations
  • Track order status through various lifecycle states
  • Enable order search and filtering capabilities
  • Support organization and user association

📋 Order Schema Types

Base Order Schemas

Core order structures used as foundations for other schemas.

Order Creation Schemas

Schemas for order creation with required field validation.

Order Update Schemas

Schemas for order modifications with optional field validation.

Order Query Schemas

Schemas for order filtering and pagination parameters.


🔧 Available Order Schemas

orderSchema

Base order schema defining the structure for order data.

Purpose: Defines the structure for order data with line items

Schema Details:

  • Type: object
  • Required Fields: None (base schema)
  • Additional Properties: false (strict validation)
  • Properties:
    • currency?: string - Order currency
    • items?: Array<{productId: string, quantity: number, price: number}> - Order line items
    • organizationId?: string - Organization ID (UUID format)
    • status?: string - Order status
    • subtotal?: number - Order subtotal (minimum 0)
    • tax?: number - Tax amount (minimum 0)
    • total?: number - Total amount (minimum 0)
    • identityId?: string - Identity ID (UUID format)

Usage:

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

const { orderSchema } = schemas;

const validate = ajv.compile(orderSchema as SchemaDefinition);
const isValid = validate({
currency: 'USD',
items: [{ productId: '123e4567-e89b-12d3-a456-426614174000', quantity: 2, price: 29.99 }],
total: 59.98
});

createOrderSchema

Order creation schema with required fields for new orders.

Purpose: Validates order data during creation

Schema Details:

  • Type: object
  • Required Fields: identityId, items, total
  • Optional Fields: currency, organizationId, status, subtotal, tax
  • Additional Properties: false (strict validation)
  • Content-Type: application/json
  • Request Body: required

Usage:

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

const { createOrderSchema } = schemas;

const orderSchema = createOrderSchema({});
const validate = ajv.compile(orderSchema.schemas as SchemaDefinition);
const isValid = validate({
items: [{ productId: '123e4567-e89b-12d3-a456-426614174000', quantity: 2, price: 29.99 }],
total: 59.98,
currency: 'USD'
});

updateOrderSchema

Order update schema with optional fields for order modifications.

Purpose: Validates partial order data updates

Schema Details:

  • Type: object
  • Required Fields: None (all fields optional)
  • Additional Properties: false (strict validation)
  • Content-Type: application/json
  • Parameters: orderId (path parameter)
  • Request Body: required

Usage:

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

const { updateOrderSchema } = schemas;

const orderSchema = updateOrderSchema({});
const validate = ajv.compile(orderSchema.schemas as SchemaDefinition);
const isValid = validate({
status: 'shipped',
total: 65.98
});

getOrderSchema

Order retrieval schema for getting single orders.

Purpose: Validates requests for retrieving specific orders

Schema Details:

  • Parameters: orderId (path parameter)
  • Purpose: Validates requests for retrieving specific orders

Usage:

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

const { getOrderSchema } = schemas;

const orderSchema = getOrderSchema({});
const validate = ajv.compile(orderSchema.schemas as SchemaDefinition);
const isValid = validate({
orderId: 'order123'
});

deleteOrderSchema

Order deletion schema for removing orders.

Purpose: Validates requests for deleting specific orders

Schema Details:

  • Parameters: orderId (path parameter)
  • Purpose: Validates requests for deleting specific orders

Usage:

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

const { deleteOrderSchema } = schemas;

const orderSchema = deleteOrderSchema({});
const validate = ajv.compile(orderSchema.schemas as SchemaDefinition);
const isValid = validate({
orderId: 'order123'
});

findOrdersSchema

Orders search schema for finding orders with filtering and pagination.

Purpose: Validates requests for searching and paginating orders

Schema Details:

  • Query Parameters:
    • currency?: string - Filter by currency
    • organizationId?: string - Filter by organization
    • status?: string - Filter by status
    • subtotal?: number - Filter by subtotal (minimum 0)
    • tax?: number - Filter by tax amount (minimum 0)
    • total?: number - Filter by total amount (minimum 0)
    • identityId?: string - Filter by identity
    • page?: number - Pagination page number
    • limit?: number - Pagination limit
  • Purpose: Validates requests for searching and paginating orders

Usage:

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

const { findOrdersSchema } = schemas;

const ordersSchema = findOrdersSchema({});
const validate = ajv.compile(ordersSchema.schemas as SchemaDefinition);
const isValid = validate({
status: 'pending',
currency: 'USD',
page: 1,
limit: 10
});