Seed pricing context for demo orders
Build and deploy Docker image / build (push) Successful in 1m38s
Build and deploy Docker image / build (push) Successful in 1m38s
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import { createHash } from 'node:crypto'
|
import { createHash } from 'node:crypto'
|
||||||
import { Prisma } from '@prisma/client'
|
import { Prisma } from '@prisma/client'
|
||||||
import { prisma } from './db.js'
|
import { prisma } from './db.js'
|
||||||
import { lockCurrencyPrice, resolveKycPricingContext } from './pricing-context.js'
|
import { ensureDemoKycPricingContext, lockCurrencyPrice } from './pricing-context.js'
|
||||||
|
|
||||||
interface DemoWorkspaceAccess {
|
interface DemoWorkspaceAccess {
|
||||||
teamUuid: string
|
teamUuid: string
|
||||||
@@ -98,6 +98,7 @@ const demoRoutes: DemoRoute[] = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
const demoNote = JSON.stringify({ seed: 'empty-team-workspace' })
|
const demoNote = JSON.stringify({ seed: 'empty-team-workspace' })
|
||||||
|
const demoPricingCountryCode = process.env.DEMO_PRICING_COUNTRY_CODE ?? 'RU'
|
||||||
|
|
||||||
function stableUuid(teamUuid: string, entity: string, index: number): string {
|
function stableUuid(teamUuid: string, entity: string, index: number): string {
|
||||||
const hex = createHash('sha256')
|
const hex = createHash('sha256')
|
||||||
@@ -126,7 +127,10 @@ export async function ensureDemoWorkspaceData(access: DemoWorkspaceAccess): Prom
|
|||||||
const needsOrders = orderCount === 0
|
const needsOrders = orderCount === 0
|
||||||
const needsPricingBackfill = demoQuotationPricingCount > 0 || demoOrderPricingCount > 0
|
const needsPricingBackfill = demoQuotationPricingCount > 0 || demoOrderPricingCount > 0
|
||||||
const kyc = needsCalculations || needsOrders || needsPricingBackfill
|
const kyc = needsCalculations || needsOrders || needsPricingBackfill
|
||||||
? await resolveKycPricingContext(access.userId)
|
? await ensureDemoKycPricingContext({
|
||||||
|
userId: access.userId,
|
||||||
|
countryCode: demoPricingCountryCode,
|
||||||
|
})
|
||||||
: null
|
: null
|
||||||
|
|
||||||
for (const [index, route] of demoRoutes.entries()) {
|
for (const [index, route] of demoRoutes.entries()) {
|
||||||
|
|||||||
@@ -78,6 +78,27 @@ export async function resolveKycPricingContext(
|
|||||||
return data.pricingContextForUser
|
return data.pricingContextForUser
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function ensureDemoKycPricingContext(input: {
|
||||||
|
userId: string
|
||||||
|
countryCode: string
|
||||||
|
}): Promise<KycPricingContext> {
|
||||||
|
const data = await requestGraphql<{
|
||||||
|
ensureDemoPricingContextForUser: KycPricingContext
|
||||||
|
}>(
|
||||||
|
kycM2mEndpoint,
|
||||||
|
`mutation OrdersEnsureDemoKycPricingContext($userId: String!, $countryCode: String!) {
|
||||||
|
ensureDemoPricingContextForUser(userId: $userId, countryCode: $countryCode) {
|
||||||
|
userId
|
||||||
|
profileUuid
|
||||||
|
countryCode
|
||||||
|
resolvedAt
|
||||||
|
}
|
||||||
|
}`,
|
||||||
|
input,
|
||||||
|
)
|
||||||
|
return data.ensureDemoPricingContextForUser
|
||||||
|
}
|
||||||
|
|
||||||
export async function lockCurrencyPrice(input: {
|
export async function lockCurrencyPrice(input: {
|
||||||
sourceAmount: number
|
sourceAmount: number
|
||||||
sourceCurrency: string
|
sourceCurrency: string
|
||||||
|
|||||||
Reference in New Issue
Block a user