All files / src/lib/api-docs/endpoints/admin pricing.ts

100% Statements 157/157
100% Branches 0/0
100% Functions 0/0
100% Lines 157/157

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 1581x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x  
/**
 * Admin Pricing Endpoints
 * Dynamic pricing rules and price management
 */
 
import type { ApiEndpoint } from '@/types/api-docs';
 
export const adminPricingEndpoints: ApiEndpoint[] = [
  {
    id: 'admin-pricing-rules-list',
    method: 'GET',
    path: '/api/admin/pricing/rules',
    summary: 'List pricing rules',
    description: 'Returns all dynamic pricing rules',
    category: 'admin-pricing',
    requiresAuth: true,
    adminOnly: true,
    parameters: [
      { name: 'page', type: 'number', required: false, location: 'query', description: 'Page number' },
      { name: 'limit', type: 'number', required: false, location: 'query', description: 'Items per page' },
      { name: 'isActive', type: 'boolean', required: false, location: 'query', description: 'Filter by active status' },
      { name: 'type', type: 'string', required: false, location: 'query', description: 'Filter by rule type' },
    ],
    responses: [
      {
        status: 200,
        description: 'List of pricing rules',
        example: {
          success: true,
          data: {
            rules: [
              { id: 1, name: 'Weekend Surge', type: 'time_based', adjustment: 10, isActive: true },
            ],
            pagination: { page: 1, limit: 20, total: 10, totalPages: 1 },
          },
        },
      },
      { status: 403, description: 'Admin access required' },
    ],
  },
  {
    id: 'admin-pricing-rules-create',
    method: 'POST',
    path: '/api/admin/pricing/rules',
    summary: 'Create pricing rule',
    description: 'Creates a new dynamic pricing rule',
    category: 'admin-pricing',
    requiresAuth: true,
    adminOnly: true,
    requestBody: {
      contentType: 'application/json',
      fields: [
        { name: 'name', type: 'string', required: true, description: 'Rule name' },
        { name: 'type', type: 'string', required: true, description: 'Rule type', enum: ['time_based', 'demand_based', 'inventory_based', 'segment_based'] },
        { name: 'adjustment', type: 'number', required: true, description: 'Price adjustment percentage' },
        { name: 'conditions', type: 'object', required: true, description: 'Rule conditions' },
        { name: 'applicableProducts', type: 'array', required: false, description: 'Product IDs (empty = all)' },
        { name: 'applicableCategories', type: 'array', required: false, description: 'Category IDs' },
        { name: 'priority', type: 'number', required: false, description: 'Rule priority (higher = more important)' },
        { name: 'isActive', type: 'boolean', required: false, description: 'Whether rule is active' },
      ],
      example: {
        name: 'Weekend Surge',
        type: 'time_based',
        adjustment: 10,
        conditions: { daysOfWeek: ['saturday', 'sunday'] },
        priority: 5,
      },
    },
    responses: [
      { status: 201, description: 'Pricing rule created' },
      { status: 400, description: 'Validation failed' },
    ],
  },
  {
    id: 'admin-pricing-rules-get',
    method: 'GET',
    path: '/api/admin/pricing/rules/{id}',
    summary: 'Get pricing rule',
    description: 'Returns a single pricing rule with usage stats',
    category: 'admin-pricing',
    requiresAuth: true,
    adminOnly: true,
    parameters: [
      { name: 'id', type: 'number', required: true, location: 'path', description: 'Rule ID' },
    ],
    responses: [
      { status: 200, description: 'Pricing rule details' },
      { status: 404, description: 'Rule not found' },
    ],
  },
  {
    id: 'admin-pricing-rules-update',
    method: 'PUT',
    path: '/api/admin/pricing/rules/{id}',
    summary: 'Update pricing rule',
    description: 'Updates an existing pricing rule',
    category: 'admin-pricing',
    requiresAuth: true,
    adminOnly: true,
    parameters: [
      { name: 'id', type: 'number', required: true, location: 'path', description: 'Rule ID' },
    ],
    responses: [
      { status: 200, description: 'Pricing rule updated' },
      { status: 404, description: 'Rule not found' },
    ],
  },
  {
    id: 'admin-pricing-rules-delete',
    method: 'DELETE',
    path: '/api/admin/pricing/rules/{id}',
    summary: 'Delete pricing rule',
    description: 'Deletes a pricing rule',
    category: 'admin-pricing',
    requiresAuth: true,
    adminOnly: true,
    parameters: [
      { name: 'id', type: 'number', required: true, location: 'path', description: 'Rule ID' },
    ],
    responses: [
      { status: 200, description: 'Pricing rule deleted' },
      { status: 404, description: 'Rule not found' },
    ],
  },
  {
    id: 'admin-pricing-simulate',
    method: 'POST',
    path: '/api/admin/pricing/simulate',
    summary: 'Simulate pricing',
    description: 'Simulates pricing rules for given products and conditions',
    category: 'admin-pricing',
    requiresAuth: true,
    adminOnly: true,
    requestBody: {
      contentType: 'application/json',
      fields: [
        { name: 'productIds', type: 'array', required: true, description: 'Product IDs to simulate' },
        { name: 'conditions', type: 'object', required: false, description: 'Simulation conditions' },
      ],
    },
    responses: [
      {
        status: 200,
        description: 'Simulation results',
        example: {
          success: true,
          data: {
            products: [
              { id: 1, originalPrice: 100, adjustedPrice: 110, appliedRules: ['Weekend Surge'] },
            ],
          },
        },
      },
    ],
  },
];