From ecc56fa112b8aa4658cd08c0f75ad6b6a223f057 Mon Sep 17 00:00:00 2001 From: Frank Date: Thu, 27 Jun 2024 17:49:39 +0200 Subject: [PATCH] fix: rwa document query --- .../graphql/server/generated/drive/nexus.ts | 12 +- .../server/generated/drive/schema.graphql | 4 +- api/src/modules/real-world-assets/utils.ts | 153 ++++++++++++------ 3 files changed, 118 insertions(+), 51 deletions(-) diff --git a/api/src/graphql/server/generated/drive/nexus.ts b/api/src/graphql/server/generated/drive/nexus.ts index 64ccd240..8318c835 100644 --- a/api/src/graphql/server/generated/drive/nexus.ts +++ b/api/src/graphql/server/generated/drive/nexus.ts @@ -298,7 +298,7 @@ export interface NexusGenObjects { FixedIncome: { // root type CUSIP?: string | null; // String ISIN?: string | null; // String - annualizedYield?: number | null; // Float + assetProceeds?: number | null; // Float coupon?: number | null; // Float fixedIncomeType?: NexusGenRootTypes['FixedIncomeType'] | null; // FixedIncomeType fixedIncomeTypeId?: string | null; // ID @@ -310,9 +310,11 @@ export interface NexusGenObjects { purchasePrice?: number | null; // Float purchaseProceeds?: number | null; // Float realizedSurplus?: number | null; // Float + salesProceeds?: number | null; // Float spv?: NexusGenRootTypes['Spv'] | null; // Spv spvId?: string | null; // ID totalDiscount?: number | null; // Float + type: NexusGenEnums['AssetType']; // AssetType! } FixedIncomeType: { // root type id: string; // ID! @@ -785,7 +787,7 @@ export interface NexusGenFieldTypes { FixedIncome: { // field return type CUSIP: string | null; // String ISIN: string | null; // String - annualizedYield: number | null; // Float + assetProceeds: number | null; // Float coupon: number | null; // Float fixedIncomeType: NexusGenRootTypes['FixedIncomeType'] | null; // FixedIncomeType fixedIncomeTypeId: string | null; // ID @@ -797,9 +799,11 @@ export interface NexusGenFieldTypes { purchasePrice: number | null; // Float purchaseProceeds: number | null; // Float realizedSurplus: number | null; // Float + salesProceeds: number | null; // Float spv: NexusGenRootTypes['Spv'] | null; // Spv spvId: string | null; // ID totalDiscount: number | null; // Float + type: NexusGenEnums['AssetType']; // AssetType! } FixedIncomeType: { // field return type id: string; // ID! @@ -1308,7 +1312,7 @@ export interface NexusGenFieldTypeNames { FixedIncome: { // field return type name CUSIP: 'String' ISIN: 'String' - annualizedYield: 'Float' + assetProceeds: 'Float' coupon: 'Float' fixedIncomeType: 'FixedIncomeType' fixedIncomeTypeId: 'ID' @@ -1320,9 +1324,11 @@ export interface NexusGenFieldTypeNames { purchasePrice: 'Float' purchaseProceeds: 'Float' realizedSurplus: 'Float' + salesProceeds: 'Float' spv: 'Spv' spvId: 'ID' totalDiscount: 'Float' + type: 'AssetType' } FixedIncomeType: { // field return type name id: 'ID' diff --git a/api/src/graphql/server/generated/drive/schema.graphql b/api/src/graphql/server/generated/drive/schema.graphql index 093e7b45..bb0067bf 100644 --- a/api/src/graphql/server/generated/drive/schema.graphql +++ b/api/src/graphql/server/generated/drive/schema.graphql @@ -212,7 +212,7 @@ union ElementComponents = ArticleComponent | CoreComponent | ScopeComponent | Se type FixedIncome { CUSIP: String ISIN: String - annualizedYield: Float + assetProceeds: Float coupon: Float fixedIncomeType: FixedIncomeType fixedIncomeTypeId: ID @@ -224,9 +224,11 @@ type FixedIncome { purchasePrice: Float purchaseProceeds: Float realizedSurplus: Float + salesProceeds: Float spv: Spv spvId: ID totalDiscount: Float + type: AssetType! } type FixedIncomeType { diff --git a/api/src/modules/real-world-assets/utils.ts b/api/src/modules/real-world-assets/utils.ts index f8b20ed7..954edeb5 100644 --- a/api/src/modules/real-world-assets/utils.ts +++ b/api/src/modules/real-world-assets/utils.ts @@ -1,54 +1,113 @@ import { Prisma, RWAPortfolio } from "@prisma/client"; export function transformPortfolioToState(portfolios: Prisma.RWAPortfolioGetPayload<{ - include: { - accounts: { - include: { - account: true - } + include: { + accounts: { + include: { + account: true + } + }, + feeTypes: { + include: { + spv: true + } + }, + fixedIncomeTypes: { + include: { + fixedIncome: true + } + }, + portfolio: { + include: { + fixedIncomeType: { + select: { + id: true, + name: true + } + } + } + }, + spvs: { + include: { + spv: true + } + }, + RWAGroupTransaction: { + include: { + cashTransaction: true, + feeTransactions: { + include: { + baseTransaction: true + } }, - feeTypes: { - include: { - spv: true - } - }, - fixedIncomeTypes: { - include: { - fixedIncome: true - } - }, - portfolio: { - include: { - fixedIncomeType: { - select: { - id: true, - name: true - } - } - } - }, - spvs: { - include: { - spv: true - } - }, - RWAGroupTransaction: { - include: { - cashTransaction: true, - feeTransactions: { - include: { - baseTransaction: true - } - }, - fixedIncomeTransaction: true, - fees: true, - } - }, - RWAPortfolioServiceProviderFeeType: true - } + fixedIncomeTransaction: true, + fees: true, + } + }, + RWAPortfolioServiceProviderFeeType: true + } }>[]) { - return portfolios.map(portfolio => ({ - // id: portfolio.documentId, - principalLenderAccountId: portfolio.principalLenderAccountId, + return portfolios.map(portfolio => ({ + id: portfolio.documentId, + principalLenderAccountId: portfolio.principalLenderAccountId, + spvs: portfolio.spvs.map(spv => ({ + id: spv.spv.id, + name: spv.spv.name + })), + feeTypes: portfolio.feeTypes.map(feeType => ({ + id: feeType.spv.id, + name: feeType.spv.name + })), + portfolio: portfolio.portfolio.map(asset => { + const spv = portfolio.spvs.map(spv => ({ + id: spv.spv.id, + name: spv.spv.name + })).find(e => e.id === asset.spvId) + + const fixedIncomeType = portfolio.fixedIncomeTypes.map(fixedIncomeType => ({ + id: fixedIncomeType.fixedIncome.id, + name: fixedIncomeType.fixedIncome.name + })).find(e => e.id == asset.fixedIncomeTypeId); + + return { + ...asset, + id: asset.id, + purchasePrice: asset.purchasePrice, + purchaseDate: asset.purchaseDate, + name: asset.name, + salesProceeds: asset.salesProceeds, + fixedIncomeType: fixedIncomeType, + spv: spv, + spvId: asset.spvId, + fixedIncomeTypeId: asset.fixedIncomeTypeId + } + }), + serviceProviderFeeTypes: portfolio.RWAPortfolioServiceProviderFeeType.map(serviceProviderFeeType => ({ + ...serviceProviderFeeType + })), + fixedIncomeTypes: portfolio.fixedIncomeTypes.map(fixedIncomeType => ({ + id: fixedIncomeType.fixedIncome.id, + name: fixedIncomeType.fixedIncome.name + })), + accounts: portfolio.accounts.map(account => ({ + ...account.account + })), + transactions: portfolio.RWAGroupTransaction.map(transaction => ({ + id: transaction.id, + type: transaction.type, + cashTransaction: transaction.cashTransaction, + entryTime: transaction.entryTime, + cashBalanceChange: transaction.cashBalanceChange, + feeTransactions: transaction.feeTransactions.map(feeTransaction => ({ + id: feeTransaction.baseTransaction.id, + amount: feeTransaction.baseTransaction.amount, + })), + fixedIncomeTransaction: transaction.fixedIncomeTransaction, + fees: transaction.fees.map(fee => ({ + id: fee.id, + serviceProviderFeeTypeId: fee.serviceProviderFeeTypeId, + amount: fee.amount + })) })) + })); }