Spaces:
Sleeping
Sleeping
| // backend/scripts/seed.js | |
| require('dotenv').config(); | |
| const mongoose = require('mongoose'); | |
| const bcrypt = require('bcryptjs'); | |
| // โ ุงุณุชูุฑุฏ ุงูู ูุฏููุงุช ู ู server.js | |
| const { User, Product, Customer, Coupon, ShippingRate } = require('../server'); | |
| if (!process.env.MONGODB_URI) { | |
| console.error('โ MONGODB_URI is not defined'); | |
| process.exit(1); | |
| } | |
| const MONGODB_URI = process.env.MONGODB_URI; | |
| // ุงูู ูุชุฌุงุช (ุจุฏูู slug - ููุถููู ูู ุงูููุฏ) | |
| const products = [ | |
| { | |
| name: "ุณุฌุงุฏ ุตูู ูุงุฎุฑ - ุจูุฌ", | |
| slug: "ุณุฌุงุฏ-ุตูู-ูุงุฎุฑ-ุจูุฌ", | |
| category: "carpet", | |
| subcategory: "wool", | |
| material: "ุตูู ุทุจูุนู 100%", | |
| size: "200x300 ุณู ", | |
| color: "ุจูุฌ ูุงุชุญ", | |
| price: 2500, | |
| oldPrice: 3500, | |
| quantity: 50, | |
| imageUrl: "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcR47nEBR3-0a8nroyXdIhqcI_BJ-LPINhAPDw&s", | |
| description: "ุณุฌุงุฏ ุตูู ุทุจูุนู ูุงุฎุฑ ู ุตููุน ูุฏููุงู", | |
| features: ["ุตูู ุทุจูุนู 100%", "ู ูุงูู ููุจูุน", "ุณูู ุงูุชูุธูู"], | |
| tags: ["ุณุฌุงุฏ", "ุตูู", "ูุงุฎุฑ", "ุจูุฌ"], | |
| isFeatured: true, | |
| isNew: true, | |
| discount: 28, | |
| inStock: true, | |
| rating: 4.8, | |
| reviewCount: 15 | |
| }, | |
| { | |
| name: "ุณุฌุงุฏ ุญุฑูุฑ - ุฑู ุงุฏู ุบุงู ู", | |
| slug: "ุณุฌุงุฏ-ุญุฑูุฑ-ุฑู ุงุฏู-ุบุงู ู", | |
| category: "carpet", | |
| subcategory: "silk", | |
| material: "ุญุฑูุฑ ุทุจูุนู", | |
| size: "160x230 ุณู ", | |
| color: "ุฑู ุงุฏู ุบุงู ู", | |
| price: 4500, | |
| oldPrice: 6000, | |
| quantity: 30, | |
| imageUrl: "https://cdn.arabsstock.com/uploads/images/336092/saudi-design-for-colorful-authentic-thumbnail-336092.webp", | |
| description: "ุณุฌุงุฏ ุญุฑูุฑ ูุงุฎุฑ ุจุชุตู ูู ุนุตุฑู", | |
| features: ["ุญุฑูุฑ ุทุจูุนู", "ุชุตู ูู ุนุตุฑู", "ูู ุนุฉ ุทุจูุนูุฉ"], | |
| tags: ["ุณุฌุงุฏ", "ุญุฑูุฑ", "ุฑู ุงุฏู", "ูุงุฎุฑ"], | |
| isFeatured: true, | |
| isNew: false, | |
| discount: 25, | |
| inStock: true, | |
| rating: 4.9, | |
| reviewCount: 23 | |
| }, | |
| { | |
| name: "ู ูููุช ูุทููุฉ - ุจูุฌ ูุงุชุญ", | |
| slug: "ู ูููุช-ูุทููุฉ-ุจูุฌ-ูุงุชุญ", | |
| category: "carpet", | |
| subcategory: "velvet", | |
| material: "ูุทููุฉ", | |
| size: "250x350 ุณู ", | |
| color: "ุจูุฌ ูุงุชุญ", | |
| price: 1800, | |
| oldPrice: 2200, | |
| quantity: 100, | |
| imageUrl: "https://cdn.arabsstock.com/uploads/images/255073/the-popular-saudi-heritage-of-thumbnail-255073.webp", | |
| description: "ู ูููุช ูุทููุฉ ูุงุนู ุฌุฏุงู", | |
| features: ["ูุทููุฉ ุนุงููุฉ ุงูุฌูุฏุฉ", "ูุงุนู ุฌุฏุงู", "ู ุถุงุฏ ููุญุณุงุณูุฉ"], | |
| tags: ["ู ูููุช", "ูุทููุฉ", "ุจูุฌ", "ุบุฑูุฉ ููู "], | |
| isFeatured: false, | |
| isNew: true, | |
| discount: 18, | |
| inStock: true, | |
| rating: 4.5, | |
| reviewCount: 8 | |
| }, | |
| { | |
| name: "ุณุฌุงุฏ ุนุฑุจู ุชูููุฏู - ุฃุญู ุฑ", | |
| slug: "ุณุฌุงุฏ-ุนุฑุจู-ุชูููุฏู-ุฃุญู ุฑ", | |
| category: "carpet", | |
| subcategory: "traditional", | |
| material: "ุตูู + ูุทู", | |
| size: "300x400 ุณู ", | |
| color: "ุฃุญู ุฑ", | |
| price: 5800, | |
| oldPrice: 7500, | |
| quantity: 15, | |
| imageUrl: "https://cdn.arabsstock.com/uploads/images/255057/traditional-handicraft-heritage-art-popular-thumbnail-255057.webp", | |
| description: "ุณุฌุงุฏ ุนุฑุจู ุชูููุฏู ู ุตููุน ูุฏููุงู", | |
| features: ["ุตูุงุนุฉ ูุฏููุฉ", "ูููุด ุฃุซุฑูุฉ", "ุฃููุงู ุทุจูุนูุฉ"], | |
| tags: ["ุณุฌุงุฏ", "ุนุฑุจู", "ุชูููุฏู", "ุฃุญู ุฑ"], | |
| isFeatured: true, | |
| isNew: false, | |
| discount: 22, | |
| inStock: true, | |
| rating: 4.7, | |
| reviewCount: 12 | |
| }, | |
| { | |
| name: "ูู ุงุด ุณุชุงุฆุฑ - ูุชุงูู ุจูุฌ", | |
| slug: "ูู ุงุด-ุณุชุงุฆุฑ-ูุชุงูู-ุจูุฌ", | |
| category: "textile", | |
| subcategory: "linen", | |
| material: "ูุชุงู ุทุจูุนู", | |
| size: "140 ุณู ุนุฑุถ", | |
| color: "ุจูุฌ ุทุจูุนู", | |
| price: 350, | |
| oldPrice: 500, | |
| quantity: 200, | |
| imageUrl: "https://cdn.arabsstock.com/uploads/images/255046/the-popular-saudi-heritage-of-preview-255046.jpg", | |
| description: "ูู ุงุด ุณุชุงุฆุฑ ูุชุงูู ุทุจูุนู", | |
| features: ["ูุชุงู ุทุจูุนู", "ูุงุจู ููุชููุณ", "ู ุถุงุฏ ููุจูุชูุฑูุง"], | |
| tags: ["ูู ุงุด", "ุณุชุงุฆุฑ", "ูุชุงู", "ุจูุฌ"], | |
| isFeatured: false, | |
| isNew: true, | |
| discount: 30, | |
| inStock: true, | |
| rating: 4.6, | |
| reviewCount: 7 | |
| }, | |
| { | |
| name: "ูู ุงุด ุชูุฌูุฏ - ู ุฎู ู ุฃุฒุฑู", | |
| slug: "ูู ุงุด-ุชูุฌูุฏ-ู ุฎู ู-ุฃุฒุฑู", | |
| category: "textile", | |
| subcategory: "velvet", | |
| material: "ู ุฎู ู", | |
| size: "150 ุณู ุนุฑุถ", | |
| color: "ุฃุฒุฑู ุฏุงูู", | |
| price: 450, | |
| oldPrice: 650, | |
| quantity: 150, | |
| imageUrl: "https://cdn.arabsstock.com/uploads/images/255050/popular-designs-for-colorful-authentic-preview-255050.jpg", | |
| description: "ูู ุงุด ุชูุฌูุฏ ู ุฎู ู ูุงุฎุฑ", | |
| features: ["ู ุฎู ู ุนุงูู ุงูุฌูุฏุฉ", "ูู ุนุฉ ุทุจูุนูุฉ", "ู ูุงูู ููุงูุชุฑุงุก"], | |
| tags: ["ูู ุงุด", "ุชูุฌูุฏ", "ู ุฎู ู", "ุฃุฒุฑู"], | |
| isFeatured: true, | |
| isNew: false, | |
| discount: 30, | |
| inStock: true, | |
| rating: 4.8, | |
| reviewCount: 11 | |
| }, | |
| { | |
| name: "ุณุฌุงุฏ ุตูู - ุจูุฌ ุบุงู ู", | |
| slug: "ุณุฌุงุฏ-ุตูู-ุจูุฌ-ุบุงู ู", | |
| category: "carpet", | |
| subcategory: "wool", | |
| material: "ุตูู ุทุจูุนู", | |
| size: "180x270 ุณู ", | |
| color: "ุจูุฌ ุบุงู ู", | |
| price: 2200, | |
| oldPrice: 3000, | |
| quantity: 40, | |
| imageUrl: "https://cdn.arabsstock.com/uploads/images/255042/traditional-handicraft-heritage-art-popular-designs-colorful.jpg", | |
| description: "ุณุฌุงุฏ ุตูู ุทุจูุนู ุจุชุตู ูู ููุงุณููู", | |
| features: ["ุตูู ุทุจูุนู", "ุชุตู ูู ููุงุณููู", "ู ุชูู"], | |
| tags: ["ุณุฌุงุฏ", "ุตูู", "ููุงุณููู", "ุจูุฌ"], | |
| isFeatured: false, | |
| isNew: false, | |
| discount: 26, | |
| inStock: true, | |
| rating: 4.4, | |
| reviewCount: 9 | |
| }, | |
| { | |
| name: "ูู ุงุด ุชูุฌูุฏ - ูุทููุฉ ูุฑุฏู", | |
| slug: "ูู ุงุด-ุชูุฌูุฏ-ูุทููุฉ-ูุฑุฏู", | |
| category: "textile", | |
| subcategory: "velvet", | |
| material: "ูุทููุฉ", | |
| size: "140 ุณู ุนุฑุถ", | |
| color: "ูุฑุฏู ูุงุชุญ", | |
| price: 380, | |
| oldPrice: 550, | |
| quantity: 120, | |
| imageUrl: "https://cdn.arabsstock.com/uploads/images/336062/traditional-craft-art-saudi-design-authentic-colorful-arabic.jpg", | |
| description: "ูู ุงุด ุชูุฌูุฏ ูุทููุฉ ูุงุนู ", | |
| features: ["ูุทููุฉ ูุงุนู ุฉ", "ุฃููุงู ุนุตุฑูุฉ", "ู ูุงูู ููุจูุน"], | |
| tags: ["ูู ุงุด", "ุชูุฌูุฏ", "ูุทููุฉ", "ูุฑุฏู"], | |
| isFeatured: false, | |
| isNew: true, | |
| discount: 30, | |
| inStock: true, | |
| rating: 4.7, | |
| reviewCount: 6 | |
| } | |
| ]; | |
| // ุงูุนู ูุงุก (30 ุนู ูู) | |
| const customers = []; | |
| const firstNames = ['ุฃุญู ุฏ', 'ู ุญู ุฏ', 'ุนูู', 'ุญุณู', 'ุญุณูู', 'ู ุญู ูุฏ', 'ุฅุจุฑุงููู ', 'ููุณู', 'ุนู ุฑ', 'ุฎุงูุฏ', 'ู ุตุทูู', 'ุนุจุฏุงููู', 'ูุฑูู ', 'ุทุงุฑู', 'ุณุงู ู']; | |
| const lastNames = ['ุญุณู', 'ุนูู', 'ู ุญู ูุฏ', 'ุฅุจุฑุงููู ', 'ููุณู', 'ุนู ุฑ', 'ุฎุงูุฏ', 'ู ุตุทูู', 'ุนุจุฏุงููู', 'ูุฑูู ', 'ุทุงุฑู', 'ุณุงู ู', 'ูุงุฑูู', 'ู ู ุฏูุญ', 'ุนุงุทู']; | |
| const cities = ['Cairo', 'Alexandria', 'Giza', 'Mansoura', 'Tanta', 'Port Said', 'Suez', 'Luxor', 'Aswan', 'Ismailia']; | |
| for (let i = 0; i < 30; i++) { | |
| const firstName = firstNames[Math.floor(Math.random() * firstNames.length)]; | |
| const lastName = lastNames[Math.floor(Math.random() * lastNames.length)]; | |
| customers.push({ | |
| name: `${firstName} ${lastName}`, | |
| phone: `010${Math.floor(Math.random() * 90000000) + 10000000}`, | |
| address: `${Math.floor(Math.random() * 200) + 1} ุดุงุฑุน ${firstName}ุ ${cities[Math.floor(Math.random() * cities.length)]}`, | |
| email: `${firstName}.${lastName}${Math.floor(Math.random() * 1000)}@example.com`, | |
| registeredAt: new Date(Date.now() - Math.random() * 365 * 24 * 60 * 60 * 1000) | |
| }); | |
| } | |
| // ููุจููุงุช ุฎุตู | |
| const coupons = [ | |
| { code: 'WELCOME10', discountType: 'percentage', discountValue: 10, minOrderAmount: 200, maxDiscount: 500, validFrom: new Date(), validTo: new Date(Date.now() + 365 * 24 * 60 * 60 * 1000), usageLimit: 100, isActive: true }, | |
| { code: 'SAVE20', discountType: 'percentage', discountValue: 20, minOrderAmount: 500, maxDiscount: 1000, validFrom: new Date(), validTo: new Date(Date.now() + 180 * 24 * 60 * 60 * 1000), usageLimit: 50, isActive: true }, | |
| { code: 'FLAT100', discountType: 'fixed', discountValue: 100, minOrderAmount: 1000, maxDiscount: 100, validFrom: new Date(), validTo: new Date(Date.now() + 90 * 24 * 60 * 60 * 1000), usageLimit: 30, isActive: true }, | |
| { code: 'FREESHIP', discountType: 'percentage', discountValue: 0, minOrderAmount: 1000, maxDiscount: 0, validFrom: new Date(), validTo: new Date(Date.now() + 60 * 24 * 60 * 60 * 1000), usageLimit: 200, isActive: true }, | |
| { code: 'SUMMER25', discountType: 'percentage', discountValue: 25, minOrderAmount: 800, maxDiscount: 1500, validFrom: new Date(), validTo: new Date(Date.now() + 120 * 24 * 60 * 60 * 1000), usageLimit: 40, isActive: true } | |
| ]; | |
| // ุฃุณุนุงุฑ ุงูุดุญู | |
| const shippingRates = [ | |
| { city: 'Cairo', cost: 50, estimatedDays: 2 }, | |
| { city: 'Alexandria', cost: 60, estimatedDays: 3 }, | |
| { city: 'Giza', cost: 50, estimatedDays: 2 }, | |
| { city: 'Mansoura', cost: 55, estimatedDays: 3 }, | |
| { city: 'Tanta', cost: 55, estimatedDays: 3 }, | |
| { city: 'Port Said', cost: 65, estimatedDays: 4 }, | |
| { city: 'Suez', cost: 65, estimatedDays: 4 }, | |
| { city: 'Luxor', cost: 80, estimatedDays: 5 }, | |
| { city: 'Aswan', cost: 85, estimatedDays: 5 }, | |
| { city: 'Ismailia', cost: 60, estimatedDays: 3 }, | |
| { city: 'Other', cost: 100, estimatedDays: 7 } | |
| ]; | |
| async function seedDatabase() { | |
| try { | |
| console.log('๐ Connecting to MongoDB...'); | |
| await mongoose.connect(MONGODB_URI); | |
| console.log('โ Connected to MongoDB'); | |
| console.log('๐๏ธ Clearing existing data...'); | |
| await Product.deleteMany({}); | |
| await Customer.deleteMany({}); | |
| await Coupon.deleteMany({}); | |
| await ShippingRate.deleteMany({}); | |
| await User.deleteMany({}); | |
| console.log('โ Cleared old data'); | |
| console.log('๐ Creating admin user...'); | |
| const hashedPassword = await bcrypt.hash('admin123', 10); | |
| await User.create({ | |
| username: 'admin', | |
| email: 'admin@naseej.com', | |
| password: hashedPassword, | |
| role: 'admin', | |
| phone: '01000000000' | |
| }); | |
| console.log('โ Admin created (admin@naseej.com / admin123)'); | |
| console.log('๐ฅ Creating customers...'); | |
| const createdCustomers = []; | |
| for (const customer of customers) { | |
| const hashedUserPassword = await bcrypt.hash('customer123', 10); | |
| const user = await User.create({ | |
| username: customer.email.split('@')[0], | |
| email: customer.email, | |
| password: hashedUserPassword, | |
| role: 'customer', | |
| phone: customer.phone | |
| }); | |
| const newCustomer = await Customer.create({ | |
| ...customer, | |
| userId: user._id | |
| }); | |
| createdCustomers.push(newCustomer); | |
| } | |
| console.log(`โ ${createdCustomers.length} customers created`); | |
| console.log('๐ฆ Creating products...'); | |
| const createdProducts = await Product.insertMany(products); // โ ุฃุณูู ุจูุชูุฑ! | |
| console.log(`โ ${createdProducts.length} products created`); | |
| console.log('๐ซ Creating coupons...'); | |
| const createdCoupons = await Coupon.insertMany(coupons); | |
| console.log(`โ ${createdCoupons.length} coupons created`); | |
| console.log('๐ Creating shipping rates...'); | |
| const createdShippingRates = await ShippingRate.insertMany(shippingRates); | |
| console.log(`โ ${createdShippingRates.length} shipping rates created`); | |
| console.log('\n๐ Seeding completed successfully!'); | |
| console.log('===================================='); | |
| console.log(` - Admin: admin@naseej.com / admin123`); | |
| console.log(` - Customers: ${createdCustomers.length} (password: customer123)`); | |
| console.log(` - Products: ${createdProducts.length}`); | |
| console.log(` - Coupons: ${createdCoupons.length}`); | |
| console.log(` - Shipping Rates: ${createdShippingRates.length}`); | |
| console.log('===================================='); | |
| } catch (error) { | |
| console.error('โ Seeding error:', error); | |
| } finally { | |
| await mongoose.disconnect(); | |
| console.log('๐ Disconnected from MongoDB'); | |
| } | |
| } | |
| seedDatabase(); |