diff --git a/graphql-contracts b/graphql-contracts index 7b6c8ce..1932411 160000 --- a/graphql-contracts +++ b/graphql-contracts @@ -1 +1 @@ -Subproject commit 7b6c8ce5093fee795e70f9ef24d2728f54f43610 +Subproject commit 1932411ebf923a196f1f9bcf51cea40d8b7f76f1 diff --git a/src/schemas/m2m.ts b/src/schemas/m2m.ts index a7c23f0..ec943b9 100644 --- a/src/schemas/m2m.ts +++ b/src/schemas/m2m.ts @@ -1,6 +1,13 @@ import { prisma } from '../db.js' export const m2mTypeDefs = `#graphql + type KycPricingContext { + userId: String! + profileUuid: String! + countryCode: String! + resolvedAt: String! + } + type CreateKycProfileResult { success: Boolean! profileUuid: String @@ -9,6 +16,7 @@ export const m2mTypeDefs = `#graphql type Query { health: String! + pricingContextForUser(userId: String!): KycPricingContext } type Mutation { @@ -59,9 +67,34 @@ async function createProfile(_: unknown, args: { kycApplicationId: string }) { } } +async function pricingContextForUser(_: unknown, args: { userId: string }) { + const profile = await prisma.kYCProfile.findFirst({ + where: { + userId: args.userId, + workflowStatus: { + in: ['active', 'approved'], + }, + }, + orderBy: { + updatedAt: 'desc', + }, + }) + if (profile === null) return null + if (profile.countryCode.length !== 2) { + throw new Error(`Active KYC profile ${profile.uuid} has no valid country code`) + } + return { + userId: profile.userId, + profileUuid: profile.uuid, + countryCode: profile.countryCode.toUpperCase(), + resolvedAt: profile.updatedAt.toISOString(), + } +} + export const m2mResolvers = { Query: { health: () => 'ok', + pricingContextForUser, }, Mutation: { createKycProfile: createProfile,