subscription-plans.seed.ts60 lines, 1.8 KB
| 1 | import { SubscriptionPlan } from "../entities/subscription-plan.entity"; |
| 2 | import { AppDataSource } from "../config/database"; |
| 3 | import logger from "../utils/logger"; |
| 4 | |
| 5 | export const seedSubscriptionPlans = async () => { |
| 6 | const planRepository = AppDataSource.getRepository(SubscriptionPlan); |
| 7 | |
| 8 | // check if there are any plans in the database |
| 9 | const existingPlans = await planRepository.find(); |
| 10 | if (existingPlans.length > 0) { |
| 11 | logger.info("Subscription plans already exist, skipping seed"); |
| 12 | return; |
| 13 | } |
| 14 | |
| 15 | // define the plans |
| 16 | const plans = [ |
| 17 | { |
| 18 | name: "Basic", |
| 19 | description: "Basic plan with limited features", |
| 20 | price: 9.99, |
| 21 | currency: "USD", |
| 22 | billingInterval: "monthly", |
| 23 | stripePriceId: "price_1R5UVvEQ2mRbD5x9EDytbaSA", // Replace with actual Stripe price IDs |
| 24 | videoLimit: 10, |
| 25 | minutesLimit: 60, |
| 26 | isActive: true, |
| 27 | }, |
| 28 | { |
| 29 | name: "Premium", |
| 30 | description: "Premium plan with more features", |
| 31 | price: 19.99, |
| 32 | currency: "USD", |
| 33 | billingInterval: "monthly", |
| 34 | stripePriceId: "price_1R5UX1EQ2mRbD5x9N3uIQpcl", // Replace with actual Stripe price IDs |
| 35 | videoLimit: 30, |
| 36 | minutesLimit: 180, |
| 37 | isActive: true, |
| 38 | }, |
| 39 | { |
| 40 | name: "Pro", |
| 41 | description: "Professional plan with all features", |
| 42 | price: 49.99, |
| 43 | currency: "USD", |
| 44 | billingInterval: "monthly", |
| 45 | stripePriceId: "price_1R5UXYEQ2mRbD5x9jBWxB52l", // Replace with actual Stripe price IDs |
| 46 | videoLimit: -1, // Unlimited |
| 47 | minutesLimit: -1, // Unlimited |
| 48 | isActive: true, |
| 49 | }, |
| 50 | ]; |
| 51 | |
| 52 | // create the plans |
| 53 | for (const planData of plans) { |
| 54 | const plan = new SubscriptionPlan(); |
| 55 | Object.assign(plan, planData); |
| 56 | await planRepository.save(plan); |
| 57 | } |
| 58 | |
| 59 | logger.info("Subscription plans seeded"); |
| 60 | }; |