114 lines
3.2 KiB
TypeScript
114 lines
3.2 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-COPPER-CATHODE',
|
|
name: 'Copper cathode',
|
|
categoryName: 'Metals',
|
|
unit: 'ton',
|
|
description: 'Demo exchange product',
|
|
},
|
|
{
|
|
uuid: '55555555-1111-4111-8111-222222222222',
|
|
sku: 'DEMO-ALUMINUM-INGOT',
|
|
name: 'Aluminum ingot',
|
|
categoryName: 'Metals',
|
|
unit: 'ton',
|
|
description: 'Demo exchange product',
|
|
},
|
|
{
|
|
uuid: '55555555-1111-4111-8111-333333333333',
|
|
sku: 'DEMO-WHEAT',
|
|
name: 'Wheat',
|
|
categoryName: 'Agriculture',
|
|
unit: 'ton',
|
|
description: 'Demo exchange product',
|
|
},
|
|
]
|
|
|
|
const suppliers = [
|
|
{
|
|
uuid: '66666666-2222-4111-8111-111111111111',
|
|
teamUuid: DEMO_TEAM_UUID,
|
|
name: 'Demo Supplier Almaty',
|
|
description: 'Demo supplier tied to the seeded client team',
|
|
country: 'Kazakhstan',
|
|
countryCode: 'KZ',
|
|
isVerified: true,
|
|
},
|
|
{
|
|
uuid: '66666666-2222-4111-8111-222222222222',
|
|
teamUuid: null,
|
|
name: 'Demo Supplier Urumqi',
|
|
description: 'Demo supplier for catalog testing',
|
|
country: 'China',
|
|
countryCode: 'CN',
|
|
isVerified: true,
|
|
},
|
|
{
|
|
uuid: '66666666-2222-4111-8111-333333333333',
|
|
teamUuid: null,
|
|
name: 'Demo Supplier Moscow',
|
|
description: 'Demo supplier for catalog testing',
|
|
country: 'Russia',
|
|
countryCode: 'RU',
|
|
isVerified: true,
|
|
},
|
|
]
|
|
|
|
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 product = await prisma.product.findUniqueOrThrow({ where: { uuid: products[index % products.length].uuid } })
|
|
const supplier = await prisma.supplier.findUniqueOrThrow({ where: { uuid: suppliers[index % suppliers.length].uuid } })
|
|
const quoteUuid = `77777777-3333-4${String(index).padStart(3, '0')}-8${String(index).padStart(3, '0')}-777777${String(index).padStart(6, '0')}`
|
|
|
|
await prisma.quote.upsert({
|
|
where: { uuid: quoteUuid },
|
|
create: {
|
|
uuid: quoteUuid,
|
|
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: `logistics-demo-hub-${(index % 4) + 1}`,
|
|
originName: supplier.name,
|
|
validUntil: new Date('2027-12-31'),
|
|
notes: 'Demo seed quote',
|
|
},
|
|
update: {
|
|
supplierId: supplier.id,
|
|
productId: product.id,
|
|
status: 'active',
|
|
unit: product.unit,
|
|
currency: 'USD',
|
|
},
|
|
})
|
|
}
|
|
|
|
console.log(`Seeded exchange demo data: products ${products.length}, suppliers ${suppliers.length}, quotes 24`)
|
|
|
|
await prisma.$disconnect()
|