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

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

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 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 2581x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 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 Affiliates Endpoints
 * Affiliate program management, payouts, and analytics
 */
 
import type { ApiEndpoint } from '@/types/api-docs';
 
export const adminAffiliatesEndpoints: ApiEndpoint[] = [
  {
    id: 'admin-affiliates-list',
    method: 'GET',
    path: '/api/admin/affiliates',
    summary: 'List all affiliates',
    description: 'Returns paginated list of all affiliate accounts',
    category: 'admin-affiliates',
    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: 'status', type: 'string', required: false, location: 'query', description: 'Filter by status', enum: ['pending', 'active', 'suspended', 'rejected'] },
      { name: 'search', type: 'string', required: false, location: 'query', description: 'Search by name or email' },
    ],
    responses: [
      {
        status: 200,
        description: 'List of affiliates',
        example: {
          success: true,
          data: {
            affiliates: [
              { id: 1, code: 'JOHN123', user: { name: 'John Doe', email: 'john@example.com' }, status: 'active', totalSales: 5000, totalCommission: 500 },
            ],
            pagination: { page: 1, limit: 20, total: 100, totalPages: 5 },
          },
        },
      },
      { status: 403, description: 'Admin access required' },
    ],
  },
  {
    id: 'admin-affiliates-get',
    method: 'GET',
    path: '/api/admin/affiliates/{id}',
    summary: 'Get affiliate details',
    description: 'Returns full affiliate account details with sales and payout history',
    category: 'admin-affiliates',
    requiresAuth: true,
    adminOnly: true,
    parameters: [
      { name: 'id', type: 'number', required: true, location: 'path', description: 'Affiliate ID' },
    ],
    responses: [
      {
        status: 200,
        description: 'Affiliate details',
        example: {
          success: true,
          data: {
            id: 1,
            code: 'JOHN123',
            user: { id: 101, name: 'John Doe', email: 'john@example.com' },
            status: 'active',
            commissionRate: 10,
            totalSales: 5000,
            totalCommission: 500,
            pendingCommission: 50,
            recentSales: [],
            payoutHistory: [],
          },
        },
      },
      { status: 404, description: 'Affiliate not found' },
    ],
  },
  {
    id: 'admin-affiliates-update',
    method: 'PATCH',
    path: '/api/admin/affiliates/{id}',
    summary: 'Update affiliate',
    description: 'Updates affiliate status, commission rate, or notes',
    category: 'admin-affiliates',
    requiresAuth: true,
    adminOnly: true,
    parameters: [
      { name: 'id', type: 'number', required: true, location: 'path', description: 'Affiliate ID' },
    ],
    requestBody: {
      contentType: 'application/json',
      fields: [
        { name: 'status', type: 'string', required: false, description: 'Affiliate status', enum: ['active', 'suspended', 'rejected'] },
        { name: 'commissionRate', type: 'number', required: false, description: 'Commission percentage' },
        { name: 'notes', type: 'string', required: false, description: 'Admin notes' },
      ],
    },
    responses: [
      { status: 200, description: 'Affiliate updated' },
      { status: 404, description: 'Affiliate not found' },
    ],
  },
  {
    id: 'admin-affiliates-approve',
    method: 'POST',
    path: '/api/admin/affiliates/{id}/approve',
    summary: 'Approve affiliate',
    description: 'Approves a pending affiliate application',
    category: 'admin-affiliates',
    requiresAuth: true,
    adminOnly: true,
    parameters: [
      { name: 'id', type: 'number', required: true, location: 'path', description: 'Affiliate ID' },
    ],
    requestBody: {
      contentType: 'application/json',
      fields: [
        { name: 'commissionRate', type: 'number', required: false, description: 'Initial commission rate' },
      ],
    },
    responses: [
      { status: 200, description: 'Affiliate approved' },
      { status: 400, description: 'Affiliate not pending' },
      { status: 404, description: 'Affiliate not found' },
    ],
  },
  {
    id: 'admin-affiliates-reject',
    method: 'POST',
    path: '/api/admin/affiliates/{id}/reject',
    summary: 'Reject affiliate',
    description: 'Rejects a pending affiliate application',
    category: 'admin-affiliates',
    requiresAuth: true,
    adminOnly: true,
    parameters: [
      { name: 'id', type: 'number', required: true, location: 'path', description: 'Affiliate ID' },
    ],
    requestBody: {
      contentType: 'application/json',
      fields: [
        { name: 'reason', type: 'string', required: false, description: 'Rejection reason' },
      ],
    },
    responses: [
      { status: 200, description: 'Affiliate rejected' },
      { status: 400, description: 'Affiliate not pending' },
      { status: 404, description: 'Affiliate not found' },
    ],
  },
  // Payouts
  {
    id: 'admin-affiliates-payouts-list',
    method: 'GET',
    path: '/api/admin/affiliates/payouts',
    summary: 'List payout requests',
    description: 'Returns paginated list of affiliate payout requests',
    category: 'admin-affiliates',
    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: 'status', type: 'string', required: false, location: 'query', description: 'Filter by status', enum: ['pending', 'approved', 'paid', 'rejected'] },
    ],
    responses: [
      { status: 200, description: 'List of payout requests' },
    ],
  },
  {
    id: 'admin-affiliates-payouts-process',
    method: 'POST',
    path: '/api/admin/affiliates/payouts/{id}/process',
    summary: 'Process payout',
    description: 'Approves and processes an affiliate payout request',
    category: 'admin-affiliates',
    requiresAuth: true,
    adminOnly: true,
    parameters: [
      { name: 'id', type: 'number', required: true, location: 'path', description: 'Payout request ID' },
    ],
    requestBody: {
      contentType: 'application/json',
      fields: [
        { name: 'action', type: 'string', required: true, description: 'Action to take', enum: ['approve', 'reject', 'mark_paid'] },
        { name: 'notes', type: 'string', required: false, description: 'Admin notes' },
        { name: 'transactionId', type: 'string', required: false, description: 'Payment transaction ID' },
      ],
    },
    responses: [
      { status: 200, description: 'Payout processed' },
      { status: 400, description: 'Invalid action or payout state' },
      { status: 404, description: 'Payout not found' },
    ],
  },
  // Sales
  {
    id: 'admin-affiliates-sales',
    method: 'GET',
    path: '/api/admin/affiliates/sales',
    summary: 'List affiliate sales',
    description: 'Returns paginated list of all sales attributed to affiliates',
    category: 'admin-affiliates',
    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: 'affiliateId', type: 'number', required: false, location: 'query', description: 'Filter by affiliate ID' },
      { name: 'startDate', type: 'string', required: false, location: 'query', description: 'Start date filter' },
      { name: 'endDate', type: 'string', required: false, location: 'query', description: 'End date filter' },
    ],
    responses: [
      {
        status: 200,
        description: 'List of affiliate sales',
        example: {
          success: true,
          data: {
            sales: [{ id: 1, orderId: 123, affiliateId: 5, amount: 100, commission: 10, createdAt: '2024-01-01T00:00:00Z' }],
            pagination: { page: 1, limit: 20, total: 100 },
          },
        },
      },
    ],
  },
  // Analytics
  {
    id: 'admin-affiliates-analytics',
    method: 'GET',
    path: '/api/admin/affiliates/analytics',
    summary: 'Get affiliate analytics',
    description: 'Returns aggregated affiliate program metrics',
    category: 'admin-affiliates',
    requiresAuth: true,
    adminOnly: true,
    parameters: [
      { name: 'startDate', type: 'string', required: false, location: 'query', description: 'Start date' },
      { name: 'endDate', type: 'string', required: false, location: 'query', description: 'End date' },
    ],
    responses: [
      {
        status: 200,
        description: 'Affiliate analytics data',
        example: {
          success: true,
          data: {
            totalAffiliates: 100,
            activeAffiliates: 75,
            totalSales: 50000,
            totalCommissions: 5000,
            pendingPayouts: 1500,
            topAffiliates: [],
          },
        },
      },
    ],
  },
];