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

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

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 931x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x  
/**
 * Promotions Endpoints
 * Discounts, promo codes, and sales endpoints
 */
 
import type { ApiEndpoint } from '@/types/api-docs';
 
export const promotionsEndpoints: ApiEndpoint[] = [
  {
    id: 'promotions-active',
    method: 'GET',
    path: '/api/promotions/active',
    summary: 'Get active promotions',
    description: 'Returns currently active promotions visible to customers',
    category: 'promotions',
    requiresAuth: false,
    responses: [
      {
        status: 200,
        description: 'List of active promotions',
        example: {
          success: true,
          data: {
            promotions: [
              { id: 1, name: 'Summer Sale', code: 'SUMMER20', type: 'percentage', value: 20, description: 'Get 20% off your order', minPurchase: 50.00 },
            ],
          },
        },
      },
    ],
  },
  {
    id: 'promotions-validate-code',
    method: 'POST',
    path: '/api/promotions/validate-code',
    summary: 'Validate promo code',
    description: 'Validates a promotional code and returns discount info',
    category: 'promotions',
    requiresAuth: false,
    requestBody: {
      contentType: 'application/json',
      fields: [
        { name: 'code', type: 'string', required: true, description: 'Promo code to validate' },
        { name: 'cartTotal', type: 'number', required: false, description: 'Cart total for validation' },
      ],
      example: { code: 'SUMMER20', cartTotal: 100.00 },
    },
    responses: [
      {
        status: 200,
        description: 'Valid code',
        example: {
          success: true,
          data: { valid: true, discount: 20, type: 'percentage', message: 'Code applied successfully' },
        },
      },
      {
        status: 400,
        description: 'Invalid or expired code',
        example: { success: false, error: { code: 'INVALID_CODE', message: 'Promo code is invalid or has expired' } },
      },
    ],
  },
  {
    id: 'promotions-applicable',
    method: 'GET',
    path: '/api/promotions/applicable',
    summary: 'Get applicable promotions',
    description: 'Returns promotions applicable to current cart based on items and total',
    category: 'promotions',
    requiresAuth: false,
    parameters: [
      { name: 'cartTotal', type: 'number', required: false, location: 'query', description: 'Cart total amount' },
      { name: 'productIds', type: 'string', required: false, location: 'query', description: 'Comma-separated product IDs' },
    ],
    responses: [
      {
        status: 200,
        description: 'List of applicable promotions',
        example: {
          success: true,
          data: {
            promotions: [
              { id: 1, name: 'Summer Sale', code: 'SUMMER20', type: 'percentage', value: 20, eligible: true },
              { id: 2, name: 'Free Shipping', code: 'FREESHIP', type: 'free_shipping', value: 0, eligible: true, reason: 'Order over $50' },
            ],
          },
        },
      },
    ],
  },
];