diff --git a/scripts/seed-demo.ts b/scripts/seed-demo.ts index 87f5777..3f52509 100644 --- a/scripts/seed-demo.ts +++ b/scripts/seed-demo.ts @@ -60,6 +60,10 @@ const suppliers = [ }, ] +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 }, @@ -77,14 +81,20 @@ for (const supplier of suppliers) { } 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')}` + 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-3', + 'logistics-demo-hub-2', + ][Math.floor(index / products.length) % suppliers.length] await prisma.quote.upsert({ - where: { uuid: quoteUuid }, + where: { uuid: quoteUuid(index) }, create: { - uuid: quoteUuid, + uuid: quoteUuid(index), supplierId: supplier.id, productId: product.id, status: 'active', @@ -93,7 +103,7 @@ for (let index = 0; index < 24; index += 1) { pricePerUnit: new Prisma.Decimal(900 + (index % 8) * 55), currency: 'USD', incotermsCode: index % 2 === 0 ? 'FOB' : 'DAP', - originPointUuid: `logistics-demo-hub-${(index % 4) + 1}`, + originPointUuid, originName: supplier.name, validUntil: new Date('2027-12-31'), notes: 'Demo seed quote', @@ -102,8 +112,15 @@ for (let index = 0; index < 24; index += 1) { 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', }, }) }