Make demo tariffs usable in route search
Build and deploy Docker image / build (push) Successful in 2m31s
Build and deploy Docker image / build (push) Successful in 2m31s
This commit is contained in:
+12
-4
@@ -117,11 +117,9 @@ export async function ensureDemoWorkspaceData(access: DemoWorkspaceAccess): Prom
|
|||||||
])
|
])
|
||||||
const needsCalculations = quotationCount === 0
|
const needsCalculations = quotationCount === 0
|
||||||
const needsOrders = orderCount === 0
|
const needsOrders = orderCount === 0
|
||||||
if (!needsCalculations && !needsOrders) return
|
|
||||||
|
|
||||||
for (const [index, route] of demoRoutes.entries()) {
|
for (const [index, route] of demoRoutes.entries()) {
|
||||||
const createsOrder = index < 2
|
const createsOrder = index < 2
|
||||||
if (!needsCalculations && !(needsOrders && createsOrder)) continue
|
|
||||||
|
|
||||||
const tariffUuid = stableUuid(access.teamUuid, 'demo-tariff', index)
|
const tariffUuid = stableUuid(access.teamUuid, 'demo-tariff', index)
|
||||||
const tariff = await prisma.tariffReference.upsert({
|
const tariff = await prisma.tariffReference.upsert({
|
||||||
@@ -132,8 +130,6 @@ export async function ensureDemoWorkspaceData(access: DemoWorkspaceAccess): Prom
|
|||||||
createdByUserId: access.userId,
|
createdByUserId: access.userId,
|
||||||
name: route.title,
|
name: route.title,
|
||||||
status: 'active',
|
status: 'active',
|
||||||
operationCode: 'IMPORT',
|
|
||||||
transportTypeCode: route.transportTypeCode,
|
|
||||||
sourceCountryCode: route.sourceCountryCode,
|
sourceCountryCode: route.sourceCountryCode,
|
||||||
destinationCountryCode: route.destinationCountryCode,
|
destinationCountryCode: route.destinationCountryCode,
|
||||||
amountUsd: new Prisma.Decimal(route.amountUsd),
|
amountUsd: new Prisma.Decimal(route.amountUsd),
|
||||||
@@ -146,13 +142,25 @@ export async function ensureDemoWorkspaceData(access: DemoWorkspaceAccess): Prom
|
|||||||
update: {
|
update: {
|
||||||
teamUuid: access.teamUuid,
|
teamUuid: access.teamUuid,
|
||||||
createdByUserId: access.userId,
|
createdByUserId: access.userId,
|
||||||
|
name: route.title,
|
||||||
|
status: 'active',
|
||||||
|
operationCode: null,
|
||||||
|
incotermsCode: null,
|
||||||
|
transportTypeCode: null,
|
||||||
|
tareTypeCode: null,
|
||||||
|
sourceCountryCode: route.sourceCountryCode,
|
||||||
|
destinationCountryCode: route.destinationCountryCode,
|
||||||
amountUsd: new Prisma.Decimal(route.amountUsd),
|
amountUsd: new Prisma.Decimal(route.amountUsd),
|
||||||
minPriceUsd: new Prisma.Decimal(route.amountUsd),
|
minPriceUsd: new Prisma.Decimal(route.amountUsd),
|
||||||
etaDays: route.etaDays,
|
etaDays: route.etaDays,
|
||||||
|
priority: 50 + index,
|
||||||
|
currency: 'USD',
|
||||||
notes: demoNote,
|
notes: demoNote,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if (!needsCalculations && !(needsOrders && createsOrder)) continue
|
||||||
|
|
||||||
const quotationUuid = stableUuid(access.teamUuid, 'demo-quotation', index)
|
const quotationUuid = stableUuid(access.teamUuid, 'demo-quotation', index)
|
||||||
const quotation = await prisma.quotation.upsert({
|
const quotation = await prisma.quotation.upsert({
|
||||||
where: { uuid: quotationUuid },
|
where: { uuid: quotationUuid },
|
||||||
|
|||||||
@@ -1115,6 +1115,7 @@ export const teamResolvers = {
|
|||||||
|
|
||||||
createQuotation: async (_: unknown, args: { input: CreateQuotationInput }, ctx: AuthContext) => {
|
createQuotation: async (_: unknown, args: { input: CreateQuotationInput }, ctx: AuthContext) => {
|
||||||
const access = assertScopedTeamAccess(ctx)
|
const access = assertScopedTeamAccess(ctx)
|
||||||
|
await ensureDemoWorkspaceData(access)
|
||||||
const actor = { userId: access.userId, label: actorLabel(access) }
|
const actor = { userId: access.userId, label: actorLabel(access) }
|
||||||
const created = await prisma.quotation.create({
|
const created = await prisma.quotation.create({
|
||||||
data: buildCreateQuotationData(args.input, access),
|
data: buildCreateQuotationData(args.input, access),
|
||||||
|
|||||||
Reference in New Issue
Block a user