Skip to content

Commit

Permalink
fix: rwa document query
Browse files Browse the repository at this point in the history
  • Loading branch information
froid1911 committed Jun 27, 2024
1 parent 088125c commit ecc56fa
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 51 deletions.
12 changes: 9 additions & 3 deletions api/src/graphql/server/generated/drive/nexus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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!
Expand Down Expand Up @@ -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
Expand All @@ -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!
Expand Down Expand Up @@ -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'
Expand All @@ -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'
Expand Down
4 changes: 3 additions & 1 deletion api/src/graphql/server/generated/drive/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -224,9 +224,11 @@ type FixedIncome {
purchasePrice: Float
purchaseProceeds: Float
realizedSurplus: Float
salesProceeds: Float
spv: Spv
spvId: ID
totalDiscount: Float
type: AssetType!
}

type FixedIncomeType {
Expand Down
153 changes: 106 additions & 47 deletions api/src/modules/real-world-assets/utils.ts
Original file line number Diff line number Diff line change
@@ -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
}))
}))
}));
}

0 comments on commit ecc56fa

Please sign in to comment.