93 lines
2.5 KiB
JavaScript
93 lines
2.5 KiB
JavaScript
const mongoose = require('mongoose');
|
|
const Coupon = require('../models/Coupon');
|
|
require('dotenv').config();
|
|
|
|
const sampleCoupons = [
|
|
{
|
|
code: 'AN6810',
|
|
discountType: 'percentage',
|
|
discountValue: 10,
|
|
minOrderValue: 200,
|
|
maxDiscount: null,
|
|
expiryDate: new Date('2025-12-31'),
|
|
usageLimit: null,
|
|
usedCount: 0,
|
|
isActive: true
|
|
},
|
|
{
|
|
code: 'AN6815',
|
|
discountType: 'percentage',
|
|
discountValue: 15,
|
|
minOrderValue: 300,
|
|
maxDiscount: null,
|
|
expiryDate: new Date('2025-12-31'),
|
|
usageLimit: null,
|
|
usedCount: 0,
|
|
isActive: true
|
|
},
|
|
{
|
|
code: 'AN6820',
|
|
discountType: 'percentage',
|
|
discountValue: 20,
|
|
minOrderValue: 400,
|
|
maxDiscount: 100,
|
|
expiryDate: new Date('2025-12-31'),
|
|
usageLimit: 100,
|
|
usedCount: 0,
|
|
isActive: true
|
|
},
|
|
{
|
|
code: 'WELCOME10',
|
|
discountType: 'fixed',
|
|
discountValue: 10,
|
|
minOrderValue: 50,
|
|
maxDiscount: null,
|
|
expiryDate: new Date('2025-12-31'),
|
|
usageLimit: null,
|
|
usedCount: 0,
|
|
isActive: true
|
|
},
|
|
{
|
|
code: 'FREESHIP',
|
|
discountType: 'fixed',
|
|
discountValue: 30,
|
|
minOrderValue: 150,
|
|
maxDiscount: null,
|
|
expiryDate: new Date('2025-12-31'),
|
|
usageLimit: null,
|
|
usedCount: 0,
|
|
isActive: true
|
|
}
|
|
];
|
|
|
|
const seedCoupons = async () => {
|
|
try {
|
|
// Connect to MongoDB
|
|
await mongoose.connect(process.env.MONGODB_URI, {
|
|
useNewUrlParser: true,
|
|
useUnifiedTopology: true
|
|
});
|
|
console.log('✅ MongoDB Connected');
|
|
|
|
// Clear existing coupons (optional - comment out if you want to keep existing)
|
|
await Coupon.deleteMany({});
|
|
console.log('🗑️ Cleared existing coupons');
|
|
|
|
// Insert sample coupons
|
|
const createdCoupons = await Coupon.insertMany(sampleCoupons);
|
|
console.log(`✅ Created ${createdCoupons.length} sample coupons:`);
|
|
|
|
createdCoupons.forEach(coupon => {
|
|
console.log(` - ${coupon.code}: ${coupon.discountValue}${coupon.discountType === 'percentage' ? '%' : '$'} off (Min order: $${coupon.minOrderValue})`);
|
|
});
|
|
|
|
console.log('\n🎉 Coupon seeding completed successfully!');
|
|
process.exit(0);
|
|
} catch (error) {
|
|
console.error('❌ Error seeding coupons:', error);
|
|
process.exit(1);
|
|
}
|
|
};
|
|
|
|
seedCoupons();
|