Use explicit currency for locked prices
Build and deploy Docker image / build (push) Successful in 1m20s

This commit is contained in:
Ruslan Bakiev
2026-08-24 21:10:09 +07:00
parent ca0e70d723
commit fe883afde2
4 changed files with 11 additions and 41 deletions
@@ -0,0 +1,2 @@
-- DropTable
DROP TABLE "exchange_pricing_currency_policies";
-9
View File
@@ -99,12 +99,3 @@ model CurrencyRate {
@@index([quoteCurrency])
@@map("exchange_currency_rates")
}
model PricingCurrencyPolicy {
countryCode String @id @map("country_code") @db.VarChar(2)
currencyCode String @map("currency_code") @db.VarChar(3)
updatedAt DateTime @updatedAt @map("updated_at")
@@index([currencyCode])
@@map("exchange_pricing_currency_policies")
}
+8 -31
View File
@@ -10,6 +10,7 @@ import { prisma } from './db.js'
type LockCurrencyPriceInput = {
sourceAmount: number
sourceCurrency: string
clientCurrency: string
pricingCountryCode: string
rateDate?: string | null
}
@@ -18,6 +19,7 @@ export const m2mTypeDefs = `#graphql
input LockCurrencyPriceInput {
sourceAmount: Float!
sourceCurrency: String!
clientCurrency: String!
pricingCountryCode: String!
rateDate: String
}
@@ -37,13 +39,8 @@ export const m2mTypeDefs = `#graphql
pricingCountryCode: String!
}
type PricingCurrencyPolicy {
countryCode: String!
currencyCode: String!
}
type Query {
pricingCurrencyForCountry(countryCode: String!): PricingCurrencyPolicy
health: String!
}
type Mutation {
@@ -70,18 +67,6 @@ function historicalDate(value: string): Date {
return result
}
async function pricingCurrencyForCountryValue(rawCountryCode: unknown) {
const normalizedCountryCode = countryCode(rawCountryCode)
const policy = await prisma.pricingCurrencyPolicy.findUnique({
where: { countryCode: normalizedCountryCode },
})
if (policy === null) return null
return {
countryCode: policy.countryCode,
currencyCode: policy.currencyCode,
}
}
async function lockCurrencyPrice(
_: unknown,
args: { input: LockCurrencyPriceInput },
@@ -92,13 +77,8 @@ async function lockCurrencyPrice(
throw new GraphQLError('sourceAmount must be a non-negative finite number')
}
const sourceCurrency = currencyCode(args.input.sourceCurrency)
const policy = await pricingCurrencyForCountryValue(args.input.pricingCountryCode)
if (policy === null) {
throw new GraphQLError(
`Pricing currency policy is missing for country ${countryCode(args.input.pricingCountryCode)}`,
)
}
const clientCurrency = currencyCode(policy.currencyCode)
const clientCurrency = currencyCode(args.input.clientCurrency)
const pricingCountryCode = countryCode(args.input.pricingCountryCode)
if (sourceCurrency === clientCurrency) {
const effectiveDate = args.input.rateDate
? historicalDate(args.input.rateDate)
@@ -115,7 +95,7 @@ async function lockCurrencyPrice(
rateLockedAt: lockedAt.toISOString(),
provider: 'identity',
attributionUrl: null,
pricingCountryCode: policy.countryCode,
pricingCountryCode,
}
}
const snapshot = args.input.rateDate
@@ -134,16 +114,13 @@ async function lockCurrencyPrice(
rateLockedAt: lockedAt.toISOString(),
provider: snapshot.provider,
attributionUrl: snapshot.attributionUrl,
pricingCountryCode: policy.countryCode,
pricingCountryCode,
}
}
export const m2mResolvers = {
Query: {
pricingCurrencyForCountry: (
_: unknown,
args: { countryCode: string },
) => pricingCurrencyForCountryValue(args.countryCode),
health: () => 'ok',
},
Mutation: {
lockCurrencyPrice,