diff --git a/graphql-contracts b/graphql-contracts index 09de97f..1526ffc 160000 --- a/graphql-contracts +++ b/graphql-contracts @@ -1 +1 @@ -Subproject commit 09de97f9fa7ec727474f982121dbd72bddd3fa0a +Subproject commit 1526ffc3b94547ae9d792528ad1a4e2aac0b1bc4 diff --git a/prisma/migrations/5_remove_country_currency_policy/migration.sql b/prisma/migrations/5_remove_country_currency_policy/migration.sql new file mode 100644 index 0000000..0111350 --- /dev/null +++ b/prisma/migrations/5_remove_country_currency_policy/migration.sql @@ -0,0 +1,2 @@ +-- DropTable +DROP TABLE "exchange_pricing_currency_policies"; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index d69913d..67c781d 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -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") -} diff --git a/src/m2m-schema.ts b/src/m2m-schema.ts index 49e2831..41d0603 100644 --- a/src/m2m-schema.ts +++ b/src/m2m-schema.ts @@ -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,