diff --git a/api/prisma/schema.prisma b/api/prisma/schema.prisma index 448ae3f1..4c963e12 100644 --- a/api/prisma/schema.prisma +++ b/api/prisma/schema.prisma @@ -201,13 +201,12 @@ model RWAPortfolioFixedIncomeType { } model RWAPortfolioSpv { - id String @default(uuid()) - portfolioId String - name String? - portfolio RWAPortfolio @relation(fields: [portfolioId], references: [id], onDelete: Cascade) - RWAPortfolioSpvOnPortfolio RWAPortfolioSpvOnPortfolio[] - RWAPortfolioServiceProviderOnPortfolio RWAPortfolioServiceProviderOnPortfolio[] - RWAPortfolioAsset RWAPortfolioAsset[] + id String @default(uuid()) + portfolioId String + name String? + portfolio RWAPortfolio @relation(fields: [portfolioId], references: [id], onDelete: Cascade) + RWAPortfolioSpvOnPortfolio RWAPortfolioSpvOnPortfolio[] + RWAPortfolioAsset RWAPortfolioAsset[] @@id([id, portfolioId]) } @@ -233,8 +232,8 @@ model RWAAccountOnPortfolio { model RWAPortfolioServiceProviderOnPortfolio { portfolioId String spvId String - portfolio RWAPortfolio @relation(fields: [portfolioId], references: [id], onDelete: Cascade) - spv RWAPortfolioSpv @relation(fields: [spvId, portfolioId], references: [id, portfolioId]) + portfolio RWAPortfolio @relation(fields: [portfolioId], references: [id], onDelete: Cascade) + spv RWAPortfolioServiceProviderFeeType @relation(fields: [spvId, portfolioId], references: [id, portfolioId]) @@id([spvId, portfolioId]) } @@ -249,14 +248,15 @@ model RWAPortfolioFixedIncomeTypeOnPortfolio { } model RWAPortfolioServiceProviderFeeType { - id String @default(uuid()) - portfolioId String - name String? - feeType String? - accountId String? - portfolio RWAPortfolio @relation(fields: [portfolioId], references: [id], onDelete: Cascade) - account RWAPortfolioAccount? @relation(fields: [accountId, portfolioId], references: [id, portfolioId]) - RWAGroupTransactionFee RWAGroupTransactionFee[] + id String @default(uuid()) + portfolioId String + name String? + feeType String? + accountId String? + portfolio RWAPortfolio @relation(fields: [portfolioId], references: [id], onDelete: Cascade) + account RWAPortfolioAccount? @relation(fields: [accountId, portfolioId], references: [id, portfolioId]) + RWAGroupTransactionFee RWAGroupTransactionFee[] + RWAPortfolioServiceProviderOnPortfolio RWAPortfolioServiceProviderOnPortfolio[] @@id([id, portfolioId]) } diff --git a/api/src/graphql/generated/drive/nexus.ts b/api/src/graphql/generated/drive/nexus.ts index 4f1b4450..ec0528c0 100644 --- a/api/src/graphql/generated/drive/nexus.ts +++ b/api/src/graphql/generated/drive/nexus.ts @@ -123,7 +123,7 @@ export interface NexusGenInputs { export interface NexusGenEnums { AuditReportStatus: "Approved" | "ApprovedWithComments" | "Escalated" | "NeedsAction" BudgetStatus: "Draft" | "Escalated" | "Final" | "Review" - GroupTransactionType: "AssetPurchase" | "AssetSale" | "FeesPayment" | "InterestDraw" | "InterestReturn" | "PrincipalDraw" | "PrincipalReturn" + GroupTransactionType: "AssetPurchase" | "AssetSale" | "FeesPayment" | "InterestDraw" | "InterestPayment" | "InterestReturn" | "PrincipalDraw" | "PrincipalReturn" ScopeFrameworkElementType: "Article" | "Core" | "Scope" | "Section" | "TypeSpecification" TransmitterType: "Internal" | "MatrixConnect" | "PullResponder" | "RESTWebhook" | "SecureConnect" | "SwitchboardPush" TypeSpecificationComponentCategory: "Accessory" | "Immutable" | "Primary" | "Supporting" diff --git a/api/src/graphql/generated/drive/schema.graphql b/api/src/graphql/generated/drive/schema.graphql index 4eb81c94..ad275d9d 100644 --- a/api/src/graphql/generated/drive/schema.graphql +++ b/api/src/graphql/generated/drive/schema.graphql @@ -253,6 +253,7 @@ enum GroupTransactionType { AssetSale FeesPayment InterestDraw + InterestPayment InterestReturn PrincipalDraw PrincipalReturn diff --git a/api/src/modules/real-world-assets/listener.ts b/api/src/modules/real-world-assets/listener.ts index 5feb2966..67cca572 100644 --- a/api/src/modules/real-world-assets/listener.ts +++ b/api/src/modules/real-world-assets/listener.ts @@ -302,6 +302,13 @@ const surgicalOperations: Record { logger.debug({ msg: "Editing SPV", input }); @@ -319,6 +326,15 @@ const surgicalOperations: Record { logger.debug({ msg: "Deleting SPV", input }); + await prisma.rWAPortfolioSpvOnPortfolio.delete({ + where: { + spvId_portfolioId: { + portfolioId: portfolio.id, + spvId: input.id + } + } + }); + await prisma.rWAPortfolioSpv.delete({ where: { id_portfolioId: { @@ -330,12 +346,22 @@ const surgicalOperations: Record { logger.debug({ msg: "Creating service provider", input }); - await prisma.rWAPortfolioServiceProviderFeeType.create({ - data: { - ...input, - portfolioId: portfolio.id - } - }); + try { + await prisma.rWAPortfolioServiceProviderFeeType.create({ + data: { + ...input, + portfolioId: portfolio.id + } + }); + await prisma.rWAPortfolioServiceProviderOnPortfolio.create({ + data: { + portfolioId: portfolio.id, + spvId: input.id + } + }); + } catch (e) { + logger.debug(e); + } }, "EDIT_SERVICE_PROVIDER_FEE_TYPE": async (input: EditServiceProviderFeeTypeInput, portfolio: RWAPortfolio, prisma: Prisma.TransactionClient) => { logger.debug({ msg: "Editing service provider", input }); @@ -364,6 +390,15 @@ const surgicalOperations: Record { logger.debug({ msg: "Deleting service provider", input }); + await prisma.rWAPortfolioServiceProviderOnPortfolio.delete({ + where: { + spvId_portfolioId: { + portfolioId: portfolio.id, + spvId: input.id + } + } + }); + await prisma.rWAPortfolioServiceProviderFeeType.delete({ where: { id_portfolioId: { @@ -381,6 +416,13 @@ const surgicalOperations: Record { logger.debug({ msg: "Editing account", input }); @@ -399,6 +441,16 @@ const surgicalOperations: Record { logger.debug({ msg: "Deleting account", input }); + + await prisma.rWAAccountOnPortfolio.delete({ + where: { + accountId_portfolioId: { + portfolioId: portfolio.id, + accountId: input.id + } + } + }); + await prisma.rWAPortfolioAccount.delete({ where: { id_portfolioId: { @@ -416,6 +468,12 @@ const surgicalOperations: Record { logger.debug({ msg: "Editing fixed income type", input }); @@ -432,6 +490,24 @@ const surgicalOperations: Record { + await prisma.rWAPortfolioFixedIncomeTypeOnPortfolio.delete({ + where: { + fixedIncomeTypeId_portfolioId: { + portfolioId: portfolio.id, + fixedIncomeTypeId: input.id + } + } + }); + await prisma.rWAPortfolioFixedIncomeType.delete({ + where: { + id_portfolioId: { + id: input.id, + portfolioId: portfolio.id + } + } + }); + }, "DELETE_FIXED_INCOME_ASSET": async (input: DeleteFixedIncomeAssetInput, portfolio: RWAPortfolio, prisma: Prisma.TransactionClient) => { logger.debug({ msg: "Deleting fixed income asset", input }); await prisma.rWAPortfolioAsset.delete({ @@ -486,16 +562,18 @@ const surgicalOperations: Record