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

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

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 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 1931x 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 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 Segments Endpoints
 * Customer segmentation and targeting management
 */
 
import type { ApiEndpoint } from '@/types/api-docs';
 
export const adminSegmentsEndpoints: ApiEndpoint[] = [
  {
    id: 'admin-segments-list',
    method: 'GET',
    path: '/api/admin/segments',
    summary: 'List customer segments',
    description: 'Returns all customer segments with member counts',
    category: 'admin-segments',
    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: 'type', type: 'string', required: false, location: 'query', description: 'Filter by segment type', enum: ['static', 'dynamic'] },
    ],
    responses: [
      {
        status: 200,
        description: 'List of segments',
        example: {
          success: true,
          data: {
            segments: [
              { id: 1, name: 'VIP Customers', type: 'dynamic', memberCount: 150, conditions: {} },
            ],
            pagination: { page: 1, limit: 20, total: 10, totalPages: 1 },
          },
        },
      },
      { status: 403, description: 'Admin access required' },
    ],
  },
  {
    id: 'admin-segments-create',
    method: 'POST',
    path: '/api/admin/segments',
    summary: 'Create segment',
    description: 'Creates a new customer segment',
    category: 'admin-segments',
    requiresAuth: true,
    adminOnly: true,
    requestBody: {
      contentType: 'application/json',
      fields: [
        { name: 'name', type: 'string', required: true, description: 'Segment name' },
        { name: 'description', type: 'string', required: false, description: 'Segment description' },
        { name: 'type', type: 'string', required: true, description: 'Segment type', enum: ['static', 'dynamic'] },
        { name: 'conditions', type: 'object', required: false, description: 'Dynamic segment conditions' },
        { name: 'userIds', type: 'array', required: false, description: 'Static segment user IDs' },
      ],
      example: {
        name: 'VIP Customers',
        type: 'dynamic',
        conditions: { totalSpent: { operator: 'gte', value: 1000 } },
      },
    },
    responses: [
      { status: 201, description: 'Segment created' },
      { status: 400, description: 'Validation failed' },
    ],
  },
  {
    id: 'admin-segments-get',
    method: 'GET',
    path: '/api/admin/segments/{id}',
    summary: 'Get segment details',
    description: 'Returns segment details with member list',
    category: 'admin-segments',
    requiresAuth: true,
    adminOnly: true,
    parameters: [
      { name: 'id', type: 'number', required: true, location: 'path', description: 'Segment ID' },
    ],
    responses: [
      { status: 200, description: 'Segment details' },
      { status: 404, description: 'Segment not found' },
    ],
  },
  {
    id: 'admin-segments-update',
    method: 'PUT',
    path: '/api/admin/segments/{id}',
    summary: 'Update segment',
    description: 'Updates an existing segment',
    category: 'admin-segments',
    requiresAuth: true,
    adminOnly: true,
    parameters: [
      { name: 'id', type: 'number', required: true, location: 'path', description: 'Segment ID' },
    ],
    responses: [
      { status: 200, description: 'Segment updated' },
      { status: 404, description: 'Segment not found' },
    ],
  },
  {
    id: 'admin-segments-delete',
    method: 'DELETE',
    path: '/api/admin/segments/{id}',
    summary: 'Delete segment',
    description: 'Deletes a customer segment',
    category: 'admin-segments',
    requiresAuth: true,
    adminOnly: true,
    parameters: [
      { name: 'id', type: 'number', required: true, location: 'path', description: 'Segment ID' },
    ],
    responses: [
      { status: 200, description: 'Segment deleted' },
      { status: 404, description: 'Segment not found' },
    ],
  },
  {
    id: 'admin-segments-members',
    method: 'GET',
    path: '/api/admin/segments/{id}/members',
    summary: 'Get segment members',
    description: 'Returns paginated list of customers in the segment',
    category: 'admin-segments',
    requiresAuth: true,
    adminOnly: true,
    parameters: [
      { name: 'id', type: 'number', required: true, location: 'path', description: 'Segment ID' },
      { name: 'page', type: 'number', required: false, location: 'query', description: 'Page number' },
      { name: 'limit', type: 'number', required: false, location: 'query', description: 'Items per page' },
    ],
    responses: [
      { status: 200, description: 'Segment members' },
      { status: 404, description: 'Segment not found' },
    ],
  },
  {
    id: 'admin-segments-refresh',
    method: 'POST',
    path: '/api/admin/segments/{id}/refresh',
    summary: 'Refresh dynamic segment',
    description: 'Recalculates membership for a dynamic segment',
    category: 'admin-segments',
    requiresAuth: true,
    adminOnly: true,
    parameters: [
      { name: 'id', type: 'number', required: true, location: 'path', description: 'Segment ID' },
    ],
    responses: [
      { status: 200, description: 'Segment refreshed', example: { success: true, data: { memberCount: 175, added: 30, removed: 5 } } },
      { status: 400, description: 'Not a dynamic segment' },
      { status: 404, description: 'Segment not found' },
    ],
  },
  {
    id: 'admin-segments-preview',
    method: 'POST',
    path: '/api/admin/segments/preview',
    summary: 'Preview segment',
    description: 'Previews which customers would match segment conditions without saving',
    category: 'admin-segments',
    requiresAuth: true,
    adminOnly: true,
    requestBody: {
      contentType: 'application/json',
      fields: [
        { name: 'conditions', type: 'object', required: true, description: 'Segment conditions to preview' },
        { name: 'limit', type: 'number', required: false, description: 'Max results to return' },
      ],
      example: {
        conditions: { totalSpent: { operator: 'gte', value: 1000 } },
        limit: 10,
      },
    },
    responses: [
      {
        status: 200,
        description: 'Preview results',
        example: {
          success: true,
          data: {
            estimatedCount: 150,
            sampleMembers: [{ id: 1, email: 'user@example.com', name: 'John Doe' }],
          },
        },
      },
      { status: 400, description: 'Invalid conditions' },
    ],
  },
];