From 7b5c44876c232c9405bb60b91afa815e151e59cd Mon Sep 17 00:00:00 2001 From: Ruslan Bakiev <572431+veikab@users.noreply.github.com> Date: Sun, 7 Jun 2026 11:17:57 +0700 Subject: [PATCH] Limit demo orders --- scripts/seed-demo.ts | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/scripts/seed-demo.ts b/scripts/seed-demo.ts index 046cab1..4a44a9e 100644 --- a/scripts/seed-demo.ts +++ b/scripts/seed-demo.ts @@ -2,7 +2,7 @@ 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 DEMO_ORDER_COUNT = Number(process.env.DEMO_ORDER_COUNT ?? '120') +const DEMO_ORDER_COUNT = Number(process.env.DEMO_ORDER_COUNT ?? '20') function requiredEnv(name: string): string { const value = process.env[name]?.trim() @@ -29,6 +29,12 @@ function location(index: number, side: 'source' | 'destination') { } const userId = requiredEnv('DEMO_LOGTO_USER_ID') +const quotationUuids = Array.from({ length: DEMO_ORDER_COUNT }, (_, index) => ( + `33333333-4444-4${String(index).padStart(3, '0').slice(-3)}-8${String(index).padStart(3, '0').slice(-3)}-333333${String(index).padStart(6, '0')}` +)) +const orderUuids = Array.from({ length: DEMO_ORDER_COUNT }, (_, index) => ( + `44444444-5555-4${String(index).padStart(3, '0').slice(-3)}-8${String(index).padStart(3, '0').slice(-3)}-444444${String(index).padStart(6, '0')}` +)) const tariffs = [ { @@ -77,13 +83,29 @@ for (const tariff of tariffs) { }) } +await prisma.order.deleteMany({ + where: { + teamUuid: DEMO_TEAM_UUID, + notes: 'Demo seed order', + uuid: { notIn: orderUuids }, + }, +}) + +await prisma.quotation.deleteMany({ + where: { + teamUuid: DEMO_TEAM_UUID, + notes: 'Demo seed quotation', + uuid: { notIn: quotationUuids }, + }, +}) + for (let index = 0; index < DEMO_ORDER_COUNT; index += 1) { const source = location(index, 'source') const destination = location(index, 'destination') const tariff = tariffs[index % tariffs.length] const totalAmount = new Prisma.Decimal(1500 + (index % 17) * 125) - const quotationUuid = `33333333-4444-4${String(index).padStart(3, '0').slice(-3)}-8${String(index).padStart(3, '0').slice(-3)}-333333${String(index).padStart(6, '0')}` - const orderUuid = `44444444-5555-4${String(index).padStart(3, '0').slice(-3)}-8${String(index).padStart(3, '0').slice(-3)}-444444${String(index).padStart(6, '0')}` + const quotationUuid = quotationUuids[index] + const orderUuid = orderUuids[index] const selectedTariff = await prisma.tariffReference.findUniqueOrThrow({ where: { uuid: tariff.uuid } }) const quotation = await prisma.quotation.upsert({