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

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

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 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 2971x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 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 Promotions Endpoints
 * Promotion codes, discounts, and campaign management
 */
 
import type { ApiEndpoint } from '@/types/api-docs';
 
export const adminPromotionsEndpoints: ApiEndpoint[] = [
  {
    id: 'admin-promotions-list',
    method: 'GET',
    path: '/api/admin/promotions',
    summary: 'List all promotions',
    description: 'Returns paginated list of all promotions',
    category: 'admin-promotions',
    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: ['active', 'scheduled', 'expired', 'disabled'] },
      { name: 'type', type: 'string', required: false, location: 'query', description: 'Filter by type', enum: ['percentage', 'fixed', 'free_shipping', 'bogo'] },
    ],
    responses: [
      {
        status: 200,
        description: 'List of promotions',
        example: {
          success: true,
          data: {
            promotions: [
              { id: 1, name: 'Summer Sale', code: 'SUMMER20', type: 'percentage', value: 20, usageCount: 150, isActive: true },
            ],
            pagination: { page: 1, limit: 20, total: 50, totalPages: 3 },
          },
        },
      },
      { status: 403, description: 'Admin access required' },
    ],
  },
  {
    id: 'admin-promotions-create',
    method: 'POST',
    path: '/api/admin/promotions',
    summary: 'Create promotion',
    description: 'Creates a new promotion or discount code',
    category: 'admin-promotions',
    requiresAuth: true,
    adminOnly: true,
    requestBody: {
      contentType: 'application/json',
      fields: [
        { name: 'name', type: 'string', required: true, description: 'Promotion name' },
        { name: 'code', type: 'string', required: true, description: 'Promo code (unique)' },
        { name: 'type', type: 'string', required: true, description: 'Discount type', enum: ['percentage', 'fixed', 'free_shipping', 'bogo'] },
        { name: 'value', type: 'number', required: true, description: 'Discount value' },
        { name: 'minPurchase', type: 'number', required: false, description: 'Minimum purchase amount' },
        { name: 'maxDiscount', type: 'number', required: false, description: 'Maximum discount amount' },
        { name: 'usageLimit', type: 'number', required: false, description: 'Total usage limit' },
        { name: 'perUserLimit', type: 'number', required: false, description: 'Per-user usage limit' },
        { name: 'startDate', type: 'string', required: false, description: 'Start date (ISO 8601)' },
        { name: 'endDate', type: 'string', required: false, description: 'End date (ISO 8601)' },
        { name: 'applicableProducts', type: 'array', required: false, description: 'Array of product IDs' },
        { name: 'applicableCategories', type: 'array', required: false, description: 'Array of category IDs' },
        { name: 'isActive', type: 'boolean', required: false, description: 'Whether promotion is active' },
      ],
      example: {
        name: 'Summer Sale',
        code: 'SUMMER20',
        type: 'percentage',
        value: 20,
        minPurchase: 50,
        startDate: '2024-06-01T00:00:00Z',
        endDate: '2024-08-31T23:59:59Z',
      },
    },
    responses: [
      { status: 201, description: 'Promotion created' },
      { status: 400, description: 'Validation failed or code already exists' },
    ],
  },
  {
    id: 'admin-promotions-get',
    method: 'GET',
    path: '/api/admin/promotions/{id}',
    summary: 'Get promotion details',
    description: 'Returns promotion details with usage statistics',
    category: 'admin-promotions',
    requiresAuth: true,
    adminOnly: true,
    parameters: [
      { name: 'id', type: 'number', required: true, location: 'path', description: 'Promotion ID' },
    ],
    responses: [
      {
        status: 200,
        description: 'Promotion details with stats',
        example: {
          success: true,
          data: {
            id: 1,
            name: 'Summer Sale',
            code: 'SUMMER20',
            type: 'percentage',
            value: 20,
            usageCount: 150,
            totalDiscount: 3000.00,
            isActive: true,
            usageHistory: [],
          },
        },
      },
      { status: 404, description: 'Promotion not found' },
    ],
  },
  {
    id: 'admin-promotions-update',
    method: 'PUT',
    path: '/api/admin/promotions/{id}',
    summary: 'Update promotion',
    description: 'Updates an existing promotion',
    category: 'admin-promotions',
    requiresAuth: true,
    adminOnly: true,
    parameters: [
      { name: 'id', type: 'number', required: true, location: 'path', description: 'Promotion ID' },
    ],
    requestBody: {
      contentType: 'application/json',
      fields: [
        { name: 'name', type: 'string', required: false, description: 'Promotion name' },
        { name: 'value', type: 'number', required: false, description: 'Discount value' },
        { name: 'minPurchase', type: 'number', required: false, description: 'Minimum purchase' },
        { name: 'maxDiscount', type: 'number', required: false, description: 'Maximum discount' },
        { name: 'usageLimit', type: 'number', required: false, description: 'Usage limit' },
        { name: 'endDate', type: 'string', required: false, description: 'End date' },
        { name: 'isActive', type: 'boolean', required: false, description: 'Active status' },
      ],
    },
    responses: [
      { status: 200, description: 'Promotion updated' },
      { status: 404, description: 'Promotion not found' },
    ],
  },
  {
    id: 'admin-promotions-delete',
    method: 'DELETE',
    path: '/api/admin/promotions/{id}',
    summary: 'Delete promotion',
    description: 'Deletes a promotion (soft delete if already used)',
    category: 'admin-promotions',
    requiresAuth: true,
    adminOnly: true,
    parameters: [
      { name: 'id', type: 'number', required: true, location: 'path', description: 'Promotion ID' },
    ],
    responses: [
      { status: 200, description: 'Promotion deleted' },
      { status: 404, description: 'Promotion not found' },
    ],
  },
  {
    id: 'admin-promotions-analytics',
    method: 'GET',
    path: '/api/admin/promotions/analytics',
    summary: 'Get promotions analytics',
    description: 'Returns aggregated promotion performance metrics',
    category: 'admin-promotions',
    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: 'Promotion analytics data',
        example: {
          success: true,
          data: {
            totalPromotions: 25,
            activePromotions: 10,
            totalUsage: 5000,
            totalDiscount: 75000.00,
            topPromotions: [],
          },
        },
      },
    ],
  },
  {
    id: 'admin-promotion-analytics',
    method: 'GET',
    path: '/api/admin/promotions/{id}/analytics',
    summary: 'Get single promotion analytics',
    description: 'Returns detailed analytics for a specific promotion',
    category: 'admin-promotions',
    requiresAuth: true,
    adminOnly: true,
    parameters: [
      { name: 'id', type: 'number', required: true, location: 'path', description: 'Promotion ID' },
      { 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: 'Promotion analytics',
        example: {
          success: true,
          data: {
            usageCount: 150,
            totalDiscount: 3000.00,
            averageOrderValue: 75.00,
            usageTrend: [],
          },
        },
      },
      { status: 404, description: 'Promotion not found' },
    ],
  },
  {
    id: 'admin-promotion-codes',
    method: 'GET',
    path: '/api/admin/promotions/{id}/codes',
    summary: 'Get promotion codes',
    description: 'Returns generated codes for a promotion (for bulk code promotions)',
    category: 'admin-promotions',
    requiresAuth: true,
    adminOnly: true,
    parameters: [
      { name: 'id', type: 'number', required: true, location: 'path', description: 'Promotion ID' },
      { name: 'page', type: 'number', required: false, location: 'query', description: 'Page number' },
      { name: 'status', type: 'string', required: false, location: 'query', description: 'Filter by status', enum: ['used', 'unused', 'expired'] },
    ],
    responses: [
      {
        status: 200,
        description: 'List of codes',
        example: {
          success: true,
          data: {
            codes: [{ code: 'PROMO-ABC123', used: false, usedAt: null }],
            pagination: { page: 1, limit: 50, total: 100 },
          },
        },
      },
    ],
  },
  {
    id: 'admin-promotion-codes-generate',
    method: 'POST',
    path: '/api/admin/promotions/{id}/codes',
    summary: 'Generate promotion codes',
    description: 'Generates bulk unique codes for a promotion',
    category: 'admin-promotions',
    requiresAuth: true,
    adminOnly: true,
    parameters: [
      { name: 'id', type: 'number', required: true, location: 'path', description: 'Promotion ID' },
    ],
    requestBody: {
      contentType: 'application/json',
      fields: [
        { name: 'count', type: 'number', required: true, description: 'Number of codes to generate' },
        { name: 'prefix', type: 'string', required: false, description: 'Code prefix' },
      ],
    },
    responses: [
      { status: 201, description: 'Codes generated' },
      { status: 400, description: 'Invalid count' },
    ],
  },
  {
    id: 'admin-promotion-toggle',
    method: 'POST',
    path: '/api/admin/promotions/{id}/toggle',
    summary: 'Toggle promotion status',
    description: 'Enables or disables a promotion',
    category: 'admin-promotions',
    requiresAuth: true,
    adminOnly: true,
    parameters: [
      { name: 'id', type: 'number', required: true, location: 'path', description: 'Promotion ID' },
    ],
    responses: [
      {
        status: 200,
        description: 'Promotion status toggled',
        example: { success: true, data: { isActive: true } },
      },
      { status: 404, description: 'Promotion not found' },
    ],
  },
];