import { _mock } from './_mock'; import { _tags } from './assets'; import { PrismaClient, ProductReview } from '@prisma/client'; import { _productsReview } from './productReview'; const prisma = new PrismaClient(); const COLORS = [ '#FF4842', '#1890FF', '#FFC0CB', '#00AB55', '#FFC107', '#7F00FF', '#000000', '#FFFFFF' ]; const DESCRIPTION = `
Category | Mobile |
Manufacturer | Apple |
Warranty | 12 Months |
Serial number | 358607726380311 |
Ships from | United States |
The foam sockliner feels soft and comfortable
Pull tab
Not intended for use as Personal Protective Equipment
Colour Shown: White/Black/Oxygen Purple/Action Grape
Style: 921826-109
Country/Region of Origin: China
Mesh and synthetic materials on the upper keep the fluid look of the OG while adding comfort
and durability.Originally designed for performance running, the full-length Max Air unit adds soft, comfortable cushio
ning underfoot.The foam midsole feels springy and soft.
The rubber outsole adds traction and durability.
Your order of $200 or more gets free standard delivery.
Standard delivered 4-5 Business Days
Express delivered 2-4 Business Days
Orders are processed and delivered Monday-Friday (excluding public holidays)
`; const getColorSliceForIndex = (index: number) => { if (index === 0) return COLORS.slice(0, 2); if (index === 1) return COLORS.slice(1, 3); if (index === 2) return COLORS.slice(2, 4); if (index === 3) return COLORS.slice(3, 6); if (index === 4 || index === 16 || index === 19) return COLORS.slice(4, 6); if (index === 5 || index === 17) return COLORS.slice(5, 6); if (index === 6 || index === 18) return COLORS.slice(0, 2); if (index === 7) return COLORS.slice(4, 6); if (index === 8) return COLORS.slice(2, 4); if (index === 9 || index === 11) return COLORS.slice(2, 6); if (index === 10) return COLORS.slice(3, 6); if (index === 12) return COLORS.slice(2, 7); if (index === 13) return COLORS.slice(4, 7); if (index === 14) return COLORS.slice(0, 2); if (index === 15) return COLORS.slice(5, 8); return COLORS.slice(2, 6); // Default case }; const generateAttachments = () => Array.from({ length: 20 }, (_, index) => _mock.image.product(index)); const generateReviews = () => { const attachments = generateAttachments(); }; const generateRatings = () => Array.from({ length: 5 }, (_, index) => ({ name: `${index + 1} Star`, starCount: _mock.number.nativeL(index), reviewCount: _mock.number.nativeL(index + 1) })); const generateImages = () => Array.from({ length: 8 }, (_, index) => _mock.image.product(index)); const _products = () => Array.from({ length: 20 }, (_, index) => { const reviews = generateReviews(); const images = generateImages(); const ratings = generateRatings(); // const publish = index % 3 ? 'published' : 'draft'; const category = (index % 2 && 'Shose') || (index % 3 && 'Apparel') || 'Accessories'; const gender = (index % 2 && ['Men']) || (index % 3 && ['Women', 'Kids']) || ['Kids']; const available = (index % 2 && 72) || (index % 3 && 10) || 0; const inventoryType = (index % 2 && 'in stock') || (index % 3 && 'low stock') || 'out of stock'; const priceSale = index % 3 ? undefined : _mock.number.price(index); return { id: _mock.id(index), sku: `WW75K521${index}YW/SV`, name: _mock.productName(index), gender, images, reviews, publish, ratings, category, available, priceSale, taxes: 10, quantity: 80, inventoryType, tags: _tags.slice(0, 5), code: `38BEE27${index}`, description: DESCRIPTION, createdAt: _mock.time(index), price: _mock.number.price(index), coverUrl: _mock.image.product(index), colors: getColorSliceForIndex(index), totalRatings: _mock.number.rating(index), totalSold: _mock.number.nativeM(index + 1), totalReviews: _mock.number.nativeL(index + 1), newLabel: { enabled: [1, 2, 3].includes(index), content: 'NEW' }, saleLabel: { enabled: [4, 5].includes(index), content: 'SALE' }, sizes: ['6', '7', '8', '8.5', '9', '9.5', '10', '10.5', '11', '11.5', '12', '13'], subDescription: 'Featuring the original ripple design inspired by Japanese bullet trains, the Nike Air Max 97 lets you push your style full-speed ahead.' }; }); async function productItem() { const temp_products = _products(); for (let i = 0; i < temp_products.length; i++) { // console.log(i); const temp_pr = _productsReview(); const temp = await prisma.productItem.upsert({ where: { id: i }, update: {}, create: { name: temp_products[i].name, code: temp_products[i].code, price: temp_products[i].price, taxes: temp_products[i].taxes, tags: temp_products[i].tags, sizes: temp_products[i].sizes, publish: temp_products[i].publish, gender: temp_products[i].gender, coverUrl: temp_products[i].coverUrl, images: temp_products[i].images, colors: temp_products[i].colors, quantity: temp_products[i].quantity, category: temp_products[i].category, available: temp_products[i].available, totalSold: temp_products[i].totalSold, description: temp_products[i].description, totalRatings: temp_products[i].totalRatings, totalReviews: temp_products[i].totalReviews, inventoryType: temp_products[i].inventoryType, subDescription: temp_products[i].subDescription, priceSale: temp_products[i].priceSale, newLabel: temp_products[i].newLabel, saleLabel: temp_products[i].saleLabel, ratings: temp_products[i].ratings, // review: { create: temp_pr }, reviews: { create: temp_pr }, testing: { create: [{ hello: 'world' }] }, sku: temp_products[i].sku } }); } console.log('seed productItem done'); } const ProductItem = productItem() .then(async () => { await prisma.$disconnect(); }) .catch(async (e) => { console.error(e); await prisma.$disconnect(); process.exit(1); }); export { ProductItem };