148 lines
4.8 KiB
TypeScript
148 lines
4.8 KiB
TypeScript
import { Prisma } from '@prisma/client'
|
|
import { prisma } from '../dist/db.js'
|
|
|
|
const DEMO_TEAM_UUID = process.env.DEMO_TEAM_UUID ?? '11111111-1111-4111-8111-111111111111'
|
|
|
|
const products = [
|
|
{
|
|
uuid: '55555555-1111-4111-8111-111111111111',
|
|
sku: 'DEMO-SOLAR-PANELS',
|
|
name: 'Solar panels',
|
|
categoryName: 'Equipment',
|
|
unit: 'pallet',
|
|
imageUrl: 'https://images.unsplash.com/photo-1509391366360-2e959784a276?auto=format&fit=crop&w=900&q=80',
|
|
description: 'Demo exchange product',
|
|
},
|
|
{
|
|
uuid: '55555555-1111-4111-8111-222222222222',
|
|
sku: 'DEMO-INDUSTRIAL-PUMPS',
|
|
name: 'Industrial pumps',
|
|
categoryName: 'Equipment',
|
|
unit: 'unit',
|
|
imageUrl: 'https://images.unsplash.com/photo-1581092160607-ee22621dd758?auto=format&fit=crop&w=900&q=80',
|
|
description: 'Demo exchange product',
|
|
},
|
|
{
|
|
uuid: '55555555-1111-4111-8111-333333333333',
|
|
sku: 'DEMO-SOYBEAN-MEAL',
|
|
name: 'Soybean meal',
|
|
categoryName: 'Agriculture',
|
|
unit: 'ton',
|
|
imageUrl: 'https://images.unsplash.com/photo-1625246333195-78d9c38ad449?auto=format&fit=crop&w=900&q=80',
|
|
description: 'Demo exchange product',
|
|
},
|
|
]
|
|
|
|
const suppliers = [
|
|
{
|
|
uuid: '66666666-2222-4111-8111-111111111111',
|
|
teamUuid: DEMO_TEAM_UUID,
|
|
name: 'Guangzhou Solar Factory',
|
|
description: 'Demo solar panel supplier near Guangzhou rail terminal',
|
|
country: 'China',
|
|
countryCode: 'CN',
|
|
logoUrl: 'https://ui-avatars.com/api/?name=Guangzhou+Solar+Factory&background=0B6BFF&color=fff&bold=true',
|
|
isVerified: true,
|
|
},
|
|
{
|
|
uuid: '66666666-2222-4111-8111-222222222222',
|
|
teamUuid: null,
|
|
name: 'Shenzhen Pump Works',
|
|
description: 'Demo industrial supplier near Yantian sea port',
|
|
country: 'China',
|
|
countryCode: 'CN',
|
|
logoUrl: 'https://ui-avatars.com/api/?name=Shenzhen+Pump+Works&background=9F1239&color=fff&bold=true',
|
|
isVerified: true,
|
|
},
|
|
{
|
|
uuid: '66666666-2222-4111-8111-333333333333',
|
|
teamUuid: null,
|
|
name: 'Harbin Agro Export',
|
|
description: 'Demo agriculture supplier near rail export hub',
|
|
country: 'China',
|
|
countryCode: 'CN',
|
|
logoUrl: 'https://ui-avatars.com/api/?name=Harbin+Agro+Export&background=0F8A6A&color=fff&bold=true',
|
|
isVerified: true,
|
|
},
|
|
{
|
|
uuid: '66666666-2222-4111-8111-444444444444',
|
|
teamUuid: null,
|
|
name: 'Vladivostok Timber Terminal',
|
|
description: 'Demo Russian supplier near Far East port and rail',
|
|
country: 'Russia',
|
|
countryCode: 'RU',
|
|
logoUrl: 'https://ui-avatars.com/api/?name=Vladivostok+Timber+Terminal&background=C45125&color=fff&bold=true',
|
|
isVerified: true,
|
|
},
|
|
]
|
|
|
|
function quoteUuid(index: number) {
|
|
return `77777777-3333-4${String(index).padStart(3, '0')}-8${String(index).padStart(3, '0')}-777777${String(index).padStart(6, '0')}`
|
|
}
|
|
|
|
for (const product of products) {
|
|
await prisma.product.upsert({
|
|
where: { uuid: product.uuid },
|
|
create: { ...product, isActive: true },
|
|
update: { ...product, isActive: true },
|
|
})
|
|
}
|
|
|
|
for (const supplier of suppliers) {
|
|
await prisma.supplier.upsert({
|
|
where: { uuid: supplier.uuid },
|
|
create: { ...supplier, isActive: true },
|
|
update: { ...supplier, isActive: true },
|
|
})
|
|
}
|
|
|
|
for (let index = 0; index < 24; index += 1) {
|
|
const productSeed = products[index % products.length]
|
|
const supplierSeed = suppliers[Math.floor(index / products.length) % suppliers.length]
|
|
const product = await prisma.product.findUniqueOrThrow({ where: { uuid: productSeed.uuid } })
|
|
const supplier = await prisma.supplier.findUniqueOrThrow({ where: { uuid: supplierSeed.uuid } })
|
|
const originPointUuid = [
|
|
'logistics-demo-hub-1',
|
|
'logistics-demo-hub-2',
|
|
'logistics-demo-hub-3',
|
|
'logistics-demo-hub-4',
|
|
][Math.floor(index / products.length) % suppliers.length]
|
|
|
|
await prisma.quote.upsert({
|
|
where: { uuid: quoteUuid(index) },
|
|
create: {
|
|
uuid: quoteUuid(index),
|
|
supplierId: supplier.id,
|
|
productId: product.id,
|
|
status: 'active',
|
|
quantity: new Prisma.Decimal(500 + index * 25),
|
|
unit: product.unit,
|
|
pricePerUnit: new Prisma.Decimal(900 + (index % 8) * 55),
|
|
currency: 'USD',
|
|
incotermsCode: index % 2 === 0 ? 'FOB' : 'DAP',
|
|
originPointUuid,
|
|
originName: supplier.name,
|
|
validUntil: new Date('2027-12-31'),
|
|
notes: 'Demo seed quote',
|
|
},
|
|
update: {
|
|
supplierId: supplier.id,
|
|
productId: product.id,
|
|
status: 'active',
|
|
quantity: new Prisma.Decimal(500 + index * 25),
|
|
unit: product.unit,
|
|
pricePerUnit: new Prisma.Decimal(900 + (index % 8) * 55),
|
|
currency: 'USD',
|
|
incotermsCode: index % 2 === 0 ? 'FOB' : 'DAP',
|
|
originPointUuid,
|
|
originName: supplier.name,
|
|
validUntil: new Date('2027-12-31'),
|
|
notes: 'Demo seed quote',
|
|
},
|
|
})
|
|
}
|
|
|
|
console.log(`Seeded exchange demo data: products ${products.length}, suppliers ${suppliers.length}, quotes 24`)
|
|
|
|
await prisma.$disconnect()
|