This commit is contained in:
+25
-3
@@ -2,7 +2,7 @@ import { Prisma } from '@prisma/client'
|
|||||||
import { prisma } from '../dist/db.js'
|
import { prisma } from '../dist/db.js'
|
||||||
|
|
||||||
const DEMO_TEAM_UUID = process.env.DEMO_TEAM_UUID ?? '11111111-1111-4111-8111-111111111111'
|
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 {
|
function requiredEnv(name: string): string {
|
||||||
const value = process.env[name]?.trim()
|
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 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 = [
|
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) {
|
for (let index = 0; index < DEMO_ORDER_COUNT; index += 1) {
|
||||||
const source = location(index, 'source')
|
const source = location(index, 'source')
|
||||||
const destination = location(index, 'destination')
|
const destination = location(index, 'destination')
|
||||||
const tariff = tariffs[index % tariffs.length]
|
const tariff = tariffs[index % tariffs.length]
|
||||||
const totalAmount = new Prisma.Decimal(1500 + (index % 17) * 125)
|
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 quotationUuid = quotationUuids[index]
|
||||||
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 orderUuid = orderUuids[index]
|
||||||
const selectedTariff = await prisma.tariffReference.findUniqueOrThrow({ where: { uuid: tariff.uuid } })
|
const selectedTariff = await prisma.tariffReference.findUniqueOrThrow({ where: { uuid: tariff.uuid } })
|
||||||
|
|
||||||
const quotation = await prisma.quotation.upsert({
|
const quotation = await prisma.quotation.upsert({
|
||||||
|
|||||||
Reference in New Issue
Block a user