MCPcopy Index your code
hub / github.com/simstudioai/sim / formatPromoCode

Function formatPromoCode

apps/sim/app/api/v1/admin/referral-campaigns/route.ts:52–84  ·  view source on GitHub ↗
(promo: {
  id: string
  code: string
  coupon: {
    id: string
    name: string | null
    percent_off: number | null
    duration: string
    duration_in_months: number | null
    applies_to?: { products: string[] }
  }
  max_redemptions: number | null
  expires_at: number | null
  active: boolean
  times_redeemed: number
  created: number
})

Source from the content-addressed store, hash-verified

50const logger = createLogger('AdminPromoCodes')
51
52function formatPromoCode(promo: {
53 id: string
54 code: string
55 coupon: {
56 id: string
57 name: string | null
58 percent_off: number | null
59 duration: string
60 duration_in_months: number | null
61 applies_to?: { products: string[] }
62 }
63 max_redemptions: number | null
64 expires_at: number | null
65 active: boolean
66 times_redeemed: number
67 created: number
68}): AdminV1PromoCode {
69 return {
70 id: promo.id,
71 code: promo.code,
72 couponId: promo.coupon.id,
73 name: promo.coupon.name ?? '',
74 percentOff: promo.coupon.percent_off ?? 0,
75 duration: promo.coupon.duration,
76 durationInMonths: promo.coupon.duration_in_months,
77 appliesToProductIds: promo.coupon.applies_to?.products ?? null,
78 maxRedemptions: promo.max_redemptions,
79 expiresAt: promo.expires_at ? new Date(promo.expires_at * 1000).toISOString() : null,
80 active: promo.active,
81 timesRedeemed: promo.times_redeemed,
82 createdAt: new Date(promo.created * 1000).toISOString(),
83 }
84}
85
86/**
87 * Resolve appliesTo values to unique Stripe product IDs.

Callers 1

route.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected