create-coupon.ts 630 B

123456789101112131415161718192021222324
  1. import { Database } from "../src/drizzle/index.js"
  2. import { CouponTable, CouponType } from "../src/schema/billing.sql.js"
  3. const email = process.argv[2]
  4. const type = process.argv[3] as (typeof CouponType)[number]
  5. if (!email || !type) {
  6. console.error(`Usage: bun create-coupon.ts <email> <${CouponType.join("|")}>`)
  7. process.exit(1)
  8. }
  9. if (!(CouponType as readonly string[]).includes(type)) {
  10. console.error(`Error: type must be one of ${CouponType.join(", ")}`)
  11. process.exit(1)
  12. }
  13. await Database.use((tx) =>
  14. tx.insert(CouponTable).values({
  15. email,
  16. type,
  17. }),
  18. )
  19. console.log(`Created ${type} coupon for ${email}`)