const API_BASE = 'http://localhost:7860'; // New categories to add const newCategories = [ { name: "Sports & Fitness", icon: "dumbbell" }, { name: "Books & Media", icon: "book" }, { name: "Toys & Games", icon: "gamepad2" }, { name: "Beauty & Personal Care", icon: "heart" }, { name: "Automotive", icon: "car" }, { name: "Pet Supplies", icon: "heart" } ]; // New sellers to add const newSellers = [ { username: "techstore", password: "password123", plainTextPassword: "password123" }, { username: "fashionhub", password: "password123", plainTextPassword: "password123" }, { username: "homecenter", password: "password123", plainTextPassword: "password123" } ]; // Store information for new sellers const newStores = [ { name: "Tech Store Pro", description: "Your one-stop shop for the latest technology and electronics", bannerImage: "https://images.unsplash.com/photo-1560472354-b33ff0c44a43?w=800&h=300&fit=crop", faceImage: "https://images.unsplash.com/photo-1507003211169-0a1dd7228f2d?w=150&h=150&fit=crop&crop=face" }, { name: "Fashion Hub Central", description: "Trendy fashion and accessories for modern lifestyle", bannerImage: "https://images.unsplash.com/photo-1441986300917-64674bd600d8?w=800&h=300&fit=crop", faceImage: "https://images.unsplash.com/photo-1494790108755-2616b612b3b0?w=150&h=150&fit=crop&crop=face" }, { name: "Home Center Plus", description: "Everything you need to make your house a home", bannerImage: "https://images.unsplash.com/photo-1586023492125-27b2c045efd7?w=800&h=300&fit=crop", faceImage: "https://images.unsplash.com/photo-1472099645785-5658abf4ff4e?w=150&h=150&fit=crop&crop=face" } ]; // Additional products for new categories and sellers const newProducts = [ // Sports & Fitness { title: "Professional Yoga Mat", description: "Non-slip premium yoga mat for all levels", price: "45.99", originalPrice: "59.99", stock: 25, category: "Sports & Fitness" }, { title: "Adjustable Dumbbells Set", description: "Space-saving adjustable weight set", price: "129.99", originalPrice: "159.99", stock: 15, category: "Sports & Fitness" }, { title: "Resistance Bands Kit", description: "Complete resistance training system", price: "29.99", originalPrice: "39.99", stock: 30, category: "Sports & Fitness" }, // Books & Media { title: "Best Selling Novel Collection", description: "Set of 5 bestselling fiction novels", price: "49.99", originalPrice: "74.99", stock: 20, category: "Books & Media" }, { title: "Premium Bluetooth Headphones", description: "Noise-cancelling wireless headphones", price: "199.99", originalPrice: "249.99", stock: 12, category: "Books & Media" }, { title: "E-Reader with Backlight", description: "6-inch HD display e-reader", price: "129.99", originalPrice: "149.99", stock: 18, category: "Books & Media" }, // Toys & Games { title: "Educational Building Blocks", description: "STEM learning blocks for kids", price: "39.99", originalPrice: "49.99", stock: 35, category: "Toys & Games" }, { title: "Board Game Collection", description: "Family-friendly strategy games", price: "69.99", originalPrice: "89.99", stock: 22, category: "Toys & Games" }, { title: "Remote Control Drone", description: "HD camera drone for beginners", price: "99.99", originalPrice: "129.99", stock: 8, category: "Toys & Games" }, // Beauty & Personal Care { title: "Skincare Routine Set", description: "Complete 4-step skincare system", price: "79.99", originalPrice: "99.99", stock: 28, category: "Beauty & Personal Care" }, { title: "Hair Styling Tool Kit", description: "Professional hair styling collection", price: "149.99", originalPrice: "199.99", stock: 14, category: "Beauty & Personal Care" }, { title: "Organic Makeup Collection", description: "Natural and cruelty-free cosmetics", price: "89.99", originalPrice: "119.99", stock: 19, category: "Beauty & Personal Care" }, // Automotive { title: "Car Phone Mount", description: "Universal smartphone car holder", price: "24.99", originalPrice: "34.99", stock: 40, category: "Automotive" }, { title: "Dash Camera HD", description: "1080p car dashboard camera", price: "89.99", originalPrice: "109.99", stock: 16, category: "Automotive" }, { title: "Car Care Kit", description: "Complete car cleaning and maintenance set", price: "59.99", originalPrice: "79.99", stock: 24, category: "Automotive" }, // Pet Supplies { title: "Premium Dog Food", description: "High-quality nutrition for adult dogs", price: "54.99", originalPrice: "69.99", stock: 32, category: "Pet Supplies" }, { title: "Cat Interactive Toy Set", description: "Engaging toys for indoor cats", price: "34.99", originalPrice: "44.99", stock: 26, category: "Pet Supplies" }, { title: "Pet Grooming Kit", description: "Professional grooming tools for pets", price: "79.99", originalPrice: "99.99", stock: 18, category: "Pet Supplies" } ]; async function createCategories() { console.log('Creating new categories...'); for (const category of newCategories) { try { const response = await fetch(`${API_BASE}/api/admin/categories`, { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify(category) }); if (response.ok) { const created = await response.json(); console.log(`✓ Created category: ${created.name}`); } else { console.log(`✗ Category "${category.name}" might already exist`); } } catch (error) { console.error(`Error creating category ${category.name}:`, error.message); } } } async function createSellers() { console.log('\\nCreating new sellers...'); const createdSellers = []; for (let i = 0; i < newSellers.length; i++) { const seller = newSellers[i]; try { const response = await fetch(`${API_BASE}/api/admin/sellers`, { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify(seller) }); if (response.ok) { const created = await response.json(); console.log(`✓ Created seller: ${created.username}`); // Create store for this seller const storeData = { ...newStores[i], sellerId: created.id }; const storeResponse = await fetch(`${API_BASE}/api/admin/stores`, { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify(storeData) }); if (storeResponse.ok) { const createdStore = await storeResponse.json(); console.log(`✓ Created store: ${createdStore.name}`); } createdSellers.push(created); } else { console.log(`✗ Seller "${seller.username}" might already exist`); } } catch (error) { console.error(`Error creating seller ${seller.username}:`, error.message); } } return createdSellers; } async function createProducts(sellers) { console.log('\\nCreating new products...'); // Get all categories to map names to IDs const categoriesResponse = await fetch(`${API_BASE}/api/categories`); const categories = await categoriesResponse.json(); // Get all sellers to distribute products const sellersResponse = await fetch(`${API_BASE}/api/admin/sellers`); const allSellers = await sellersResponse.json(); for (let i = 0; i < newProducts.length; i++) { const product = newProducts[i]; // Find category ID const category = categories.find(c => c.name === product.category); if (!category) { console.log(`✗ Category "${product.category}" not found for product "${product.title}"`); continue; } // Assign seller in round-robin fashion const seller = allSellers[i % allSellers.length]; const productData = { title: product.title, description: product.description, price: product.price, originalPrice: product.originalPrice, stock: product.stock, sellerId: seller.id, categoryId: category.id, images: [ `https://images.unsplash.com/photo-${1786000000000 + Math.floor(Math.random() * 100000000)}?w=400&h=400&fit=crop`, `https://images.unsplash.com/photo-${1786000000000 + Math.floor(Math.random() * 100000000)}?w=400&h=400&fit=crop`, `https://images.unsplash.com/photo-${1786000000000 + Math.floor(Math.random() * 100000000)}?w=400&h=400&fit=crop` ], isActive: true }; try { const response = await fetch(`${API_BASE}/api/admin/products`, { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify(productData) }); if (response.ok) { const created = await response.json(); console.log(`✓ Created product: ${created.title}`); } else { const error = await response.text(); console.log(`✗ Failed to create product "${product.title}": ${error}`); } } catch (error) { console.error(`Error creating product ${product.title}:`, error.message); } } } async function main() { console.log('🌱 Starting database seeding with more data...\\n'); await createCategories(); const newSellerAccounts = await createSellers(); await createProducts(newSellerAccounts); console.log('\\n✅ Finished seeding additional data!'); console.log('\\n📊 Summary:'); console.log(` • Added ${newCategories.length} new categories`); console.log(` • Added ${newSellers.length} new sellers with stores`); console.log(` • Added ${newProducts.length} new products`); } // Only run if called directly if (typeof window === 'undefined' && typeof require !== 'undefined') { main().catch(console.error); } module.exports = { main };