diff --git a/api/prisma/schema.prisma b/api/prisma/schema.prisma index 29414311..39c3ebc0 100644 --- a/api/prisma/schema.prisma +++ b/api/prisma/schema.prisma @@ -168,7 +168,7 @@ model RWAPortfolioAsset { fixedIncomeTypeId String? fixedIncomeType RWAPortfolioFixedIncomeType? @relation(fields: [fixedIncomeTypeId, portfolioId], references: [id, portfolioId]) name String? - spvId String + spvId String? maturity String? purchaseDate String? notional Float? diff --git a/api/src/modules/document/listenerManager.ts b/api/src/modules/document/listenerManager.ts index 6446ba9a..55c08aa0 100644 --- a/api/src/modules/document/listenerManager.ts +++ b/api/src/modules/document/listenerManager.ts @@ -6,12 +6,12 @@ import { Document, OperationScope } from "document-model/document" import { Prisma } from '@prisma/client'; import { getChildLogger } from '../../logger'; -const logger = getChildLogger({ msgPrefix: 'Listener Manager' }); +const logger = getChildLogger({ msgPrefix: 'Listener Manager' }, { module: 'Listener Manager' }); const listeners: Promise[] = []; function loadModules(startPath: string, filter: string): Promise[] { if (!fs.existsSync(startPath)) { - console.log("no dir ", startPath); + logger.error(`Directory not found: ${startPath}`); return []; } diff --git a/api/src/modules/real-world-assets/listener.ts b/api/src/modules/real-world-assets/listener.ts index a8c254a3..880761c5 100644 --- a/api/src/modules/real-world-assets/listener.ts +++ b/api/src/modules/real-world-assets/listener.ts @@ -62,15 +62,9 @@ async function doSurgicalDriveUpdate(strand: InternalTransmitterUpdate Promise> = { "CREATE_FIXED_INCOME_ASSET": async (input: CreateFixedIncomeAssetInput, portfolio: RWAPortfolio, prisma: Prisma.TransactionClient) => { + logger.debug({ msg: "Creating fixed income asset", input }); await prisma.rWAPortfolioAsset.create({ data: { ...input, @@ -225,8 +218,22 @@ const surgicalOperations: Record { + logger.debug({ msg: "Editing fixed income asset", input }); + await prisma.rWAPortfolioAsset.update({ + where: { + assetRefId_portfolioId: { + assetRefId: input.id, + portfolioId: portfolio.id + } + }, + data: { + ...input, + } + }); + } } async function handleRwaDocumentStrand(strand: InternalTransmitterUpdate, prisma: Prisma.TransactionClient) { @@ -238,7 +245,6 @@ async function handleRwaDocumentStrand(strand: InternalTransmitterUpdate { - console.log(args); const doc = await ctx.prisma.rWAPortfolio.findRWAPortfolios({ driveId: ctx.driveId }); return doc; }, diff --git a/api/src/modules/real-world-assets/utils.ts b/api/src/modules/real-world-assets/utils.ts index e6438854..6b523389 100644 --- a/api/src/modules/real-world-assets/utils.ts +++ b/api/src/modules/real-world-assets/utils.ts @@ -1,18 +1,49 @@ -import { RWAPortfolio } from "@prisma/client"; +import { Prisma, RWAPortfolio } from "@prisma/client"; -export function transformPortfolioToState(portfolios: RWAPortfolio[]) { - console.log(portfolios); +export function transformPortfolioToState(portfolios: Prisma.RWAPortfolioGetPayload<{ + 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 + } + } + } +}>[]) { return portfolios.map(portfolio => ({ id: portfolio.id, - name: portfolio.name, // spvs: [], spvs: portfolio.spvs.map(spv => ({ id: spv.spv.id, name: spv.spv.name })), feeTypes: portfolio.feeTypes.map(feeType => ({ - id: feeType.id, - name: feeType.name + id: feeType.spv.id, + name: feeType.spv.name })), portfolio: portfolio.portfolio.map(asset => ({ id: asset.id, @@ -20,17 +51,17 @@ export function transformPortfolioToState(portfolios: RWAPortfolio[]) { purchaseDate: asset.purchaseDate, name: asset.name, fixedIncomeType: { - id: asset.fixedIncomeType.id, - name: asset.fixedIncomeType.name + id: asset.fixedIncomeType?.id, + name: asset.fixedIncomeType?.name } })), - // fixedIncomeTypes: portfolio.fixedIncomeTypes.map(fixedIncomeType => ({ - // id: fixedIncomeType.id, - // name: fixedIncomeType.name - // })), - // accounts: portfolio.accounts.map(account => ({ - // id: account.id, - // name: account.name - // })) + fixedIncomeTypes: portfolio.fixedIncomeTypes.map(fixedIncomeType => ({ + id: fixedIncomeType.fixedIncome.id, + name: fixedIncomeType.fixedIncome.name + })), + accounts: portfolio.accounts.map(account => ({ + id: account.account.id, + name: account.account.label + })) })); }