import { _mock } from './_mock'; import { _tags } from './assets'; import { PrismaClient } from '@prisma/client'; const prisma = new PrismaClient(); const COLORS = ['#FF4842', '#1890FF', '#FFC0CB', '#00AB55', '#FFC107', '#7F00FF', '#000000', '#FFFFFF']; const DESCRIPTION = `
Specifications
Category Mobile
Manufacturer Apple
Warranty 12 Months
Serial number 358607726380311
Ships from United States
Product details
Benefits
Delivery and returns

Your order of $200 or more gets free standard delivery.

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(); return Array.from({ length: 8 }, (_, index) => ({ // id: _mock.id(index), name: _mock.fullName(index), postedAt: _mock.time(index), comment: _mock.sentence(index), isPurchased: _mock.boolean(index), rating: _mock.number.rating(index), avatarUrl: _mock.image.avatar(index), helpful: _mock.number.nativeL(index), attachments: (index === 1 && attachments.slice(0, 1)) || (index === 3 && attachments.slice(2, 4)) || (index === 5 && attachments.slice(5, 8)) || [], })); }; 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)); export const _productsReview = () => { return generateReviews(); }; async function productReview() { const temp_pr = _productsReview(); for (let i = 0; i < temp_pr.length; i++) { const temp = await prisma.productReview.upsert({ where: { id: i }, update: {}, create: { name: temp_pr[i].name, rating: temp_pr[i].rating, comment: temp_pr[i].comment, helpful: temp_pr[i].helpful, avatarUrl: temp_pr[i].avatarUrl, isPurchased: temp_pr[i].isPurchased, attachments: temp_pr[i].attachments, postedAt: temp_pr[i].postedAt, }, }); } console.log('seed productReview done'); } const ProductReview = productReview() .then(async () => { await prisma.$disconnect(); }) .catch(async (e) => { console.error(e); await prisma.$disconnect(); process.exit(1); }); export { ProductReview };