278 lines
8.0 KiB
TypeScript
278 lines
8.0 KiB
TypeScript
import { _mock } from './_mock';
|
|
import { _tags } from './assets';
|
|
|
|
import { PrismaClient, EventReview } from '@prisma/client';
|
|
import { _eventsReview } from './eventReview';
|
|
import { CONFIG } from './global-config';
|
|
|
|
import _ from 'lodash';
|
|
|
|
const prisma = new PrismaClient();
|
|
|
|
const COLORS = ['#FF4842', '#1890FF', '#FFC0CB', '#00AB55', '#FFC107', '#7F00FF', '#000000', '#FFFFFF'];
|
|
|
|
const DESCRIPTION = `
|
|
<h6>Specifications</h6>
|
|
<table>
|
|
<tbody>
|
|
<tr>
|
|
<td>Category</td>
|
|
<td>Mobile</td>
|
|
</tr>
|
|
<tr>
|
|
<td>Manufacturer</td>
|
|
<td>Apple</td>
|
|
</tr>
|
|
<tr>
|
|
<td>Warranty</td>
|
|
<td>12 Months</td>
|
|
</tr>
|
|
<tr>
|
|
<td>Serial number</td>
|
|
<td>358607726380311</td>
|
|
</tr>
|
|
<tr>
|
|
<td>Ships from</td>
|
|
<td>United States</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
|
|
<h6>Event details</h6>
|
|
<ul>
|
|
<li>
|
|
<p>The foam sockliner feels soft and comfortable</p>
|
|
</li>
|
|
<li>
|
|
<p>Pull tab</p>
|
|
</li>
|
|
<li>
|
|
<p>Not intended for use as Personal Protective Equipment</p>
|
|
</li>
|
|
<li>
|
|
<p>Colour Shown: White/Black/Oxygen Purple/Action Grape</p>
|
|
</li>
|
|
<li>
|
|
<p>Style: 921826-109</p>
|
|
</li>
|
|
<li>
|
|
<p>Country/Region of Origin: China</p>
|
|
</li>
|
|
</ul>
|
|
<h6>Benefits</h6>
|
|
<ul>
|
|
<li>
|
|
<p>Mesh and synthetic materials on the upper keep the fluid look of the OG while adding comfort</p>
|
|
and durability.
|
|
</li>
|
|
<li>
|
|
<p>Originally designed for performance running, the full-length Max Air unit adds soft, comfortable cushio</p>
|
|
ning underfoot.
|
|
</li>
|
|
<li>
|
|
<p>The foam midsole feels springy and soft.</p>
|
|
</li>
|
|
<li>
|
|
<p>The rubber outsole adds traction and durability.</p>
|
|
</li>
|
|
</ul>
|
|
<h6>Delivery and returns</h6>
|
|
<p>Your order of $200 or more gets free standard delivery.</p>
|
|
<ul>
|
|
<li>
|
|
<p>Standard delivered 4-5 Business Days</p>
|
|
</li>
|
|
<li>
|
|
<p>Express delivered 2-4 Business Days</p>
|
|
</li>
|
|
</ul>
|
|
<p>Orders are processed and delivered Monday-Friday (excluding public holidays)</p>
|
|
|
|
`;
|
|
|
|
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.event(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.event(index));
|
|
|
|
const _events = () =>
|
|
Array.from({ length: 2 }, (_, 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).toString(),
|
|
sku: `WW75K521${index}YW/SV`,
|
|
name: _mock.eventName(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.event(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.',
|
|
};
|
|
});
|
|
|
|
const memberList = (num_of_member: number) =>
|
|
_.shuffle([
|
|
{
|
|
email: 'tom@exampl.com',
|
|
avatar: `https://plus.unsplash.com/premium_photo-1671656349322-41de944d259b`,
|
|
sex: 'M',
|
|
},
|
|
{
|
|
email: 'may@exampl.com',
|
|
avatar: `https://images.unsplash.com/photo-1522075469751-3a6694fb2f61`,
|
|
sex: 'F',
|
|
},
|
|
{
|
|
email: 'june@exampl.com',
|
|
avatar: `https://plus.unsplash.com/premium_photo-1723867331866-e112500178a4`,
|
|
sex: 'M',
|
|
},
|
|
{
|
|
email: 'april@exampl.com',
|
|
avatar: `https://plus.unsplash.com/premium_photo-1682089894837-e01e5cb8e471`,
|
|
sex: 'F',
|
|
},
|
|
{
|
|
email: 'susan@exampl.com',
|
|
avatar: `https://images.unsplash.com/photo-1485893086445-ed75865251e0`,
|
|
sex: 'M',
|
|
},
|
|
{
|
|
email: 'peter@exampl.com',
|
|
avatar: `https://plus.unsplash.com/premium_photo-1722945763962-305a5a769cc8`,
|
|
sex: 'F',
|
|
},
|
|
]).slice(0, num_of_member);
|
|
|
|
async function eventItem() {
|
|
const temp_events = _events();
|
|
|
|
for (let i = 0; i < temp_events.length; i++) {
|
|
const temp_pr = _eventsReview();
|
|
|
|
const temp = await prisma.eventItem.upsert({
|
|
where: { id: temp_events[i].id.toString() },
|
|
update: {},
|
|
create: {
|
|
id: temp_events[i].id,
|
|
//
|
|
name: temp_events[i].name,
|
|
code: temp_events[i].code,
|
|
price: temp_events[i].price,
|
|
taxes: temp_events[i].taxes,
|
|
tags: temp_events[i].tags,
|
|
sizes: temp_events[i].sizes,
|
|
publish: temp_events[i].publish,
|
|
gender: temp_events[i].gender,
|
|
coverUrl: temp_events[i].coverUrl,
|
|
images: temp_events[i].images,
|
|
colors: temp_events[i].colors,
|
|
quantity: temp_events[i].quantity,
|
|
category: temp_events[i].category,
|
|
available: temp_events[i].available,
|
|
totalSold: temp_events[i].totalSold,
|
|
description: temp_events[i].description,
|
|
totalRatings: temp_events[i].totalRatings,
|
|
totalReviews: temp_events[i].totalReviews,
|
|
inventoryType: temp_events[i].inventoryType,
|
|
subDescription: temp_events[i].subDescription,
|
|
priceSale: temp_events[i].priceSale,
|
|
newLabel: temp_events[i].newLabel,
|
|
saleLabel: temp_events[i].saleLabel,
|
|
ratings: temp_events[i].ratings,
|
|
// review: { create: temp_pr },
|
|
reviews: { create: temp_pr },
|
|
sku: temp_events[i].sku,
|
|
//
|
|
eventDate: new Date(_mock.time(i)),
|
|
title: temp_events[i].name,
|
|
currency: 'HKD',
|
|
duration_m: 120,
|
|
ageBottom: 18,
|
|
ageTop: 60,
|
|
location: 'Hong Kong',
|
|
avatar: temp_events[i].images,
|
|
//
|
|
joinMembers: memberList(5 - i),
|
|
},
|
|
});
|
|
}
|
|
console.log('seed eventItem done');
|
|
}
|
|
|
|
const EventItem = eventItem()
|
|
.then(async () => {
|
|
await prisma.$disconnect();
|
|
})
|
|
.catch(async (e) => {
|
|
console.error(e);
|
|
await prisma.$disconnect();
|
|
process.exit(1);
|
|
});
|
|
|
|
export { EventItem as EventItemSeed };
|