Skip to content

Commit

Permalink
fix: rwaPortfolios query
Browse files Browse the repository at this point in the history
  • Loading branch information
froid1911 committed May 3, 2024
1 parent 2dba2cf commit 079e8d7
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 29 deletions.
34 changes: 17 additions & 17 deletions api/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
Expand All @@ -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])
}
Expand All @@ -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])
}
Expand Down
2 changes: 1 addition & 1 deletion api/src/graphql/generated/drive/nexus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions api/src/graphql/generated/drive/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ enum GroupTransactionType {
AssetSale
FeesPayment
InterestDraw
InterestPayment
InterestReturn
PrincipalDraw
PrincipalReturn
Expand Down
98 changes: 88 additions & 10 deletions api/src/modules/real-world-assets/listener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,13 @@ const surgicalOperations: Record<string, (input: any, portfolio: RWAPortfolio, p
portfolioId: portfolio.id
}
});

await prisma.rWAPortfolioSpvOnPortfolio.create({
data: {
portfolioId: portfolio.id,
spvId: input.id
}
});
},
"EDIT_SPV": async (input: EditSpvInput, portfolio: RWAPortfolio, prisma: Prisma.TransactionClient) => {
logger.debug({ msg: "Editing SPV", input });
Expand All @@ -319,6 +326,15 @@ const surgicalOperations: Record<string, (input: any, portfolio: RWAPortfolio, p
},
"DELETE_SPV": async (input: DeleteSpvInput, portfolio: RWAPortfolio, prisma: Prisma.TransactionClient) => {
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: {
Expand All @@ -330,12 +346,22 @@ const surgicalOperations: Record<string, (input: any, portfolio: RWAPortfolio, p
},
"CREATE_SERVICE_PROVIDER_FEE_TYPE": async (input: CreateServiceProviderFeeTypeInput, portfolio: RWAPortfolio, prisma: Prisma.TransactionClient) => {
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 });
Expand Down Expand Up @@ -364,6 +390,15 @@ const surgicalOperations: Record<string, (input: any, portfolio: RWAPortfolio, p
},
"DELETE_SERVICE_PROVIDER_FEE_TYPE": async (input: DeleteServiceProviderFeeTypeInput, portfolio: RWAPortfolio, prisma: Prisma.TransactionClient) => {
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: {
Expand All @@ -381,6 +416,13 @@ const surgicalOperations: Record<string, (input: any, portfolio: RWAPortfolio, p
portfolioId: portfolio.id
}
});

await prisma.rWAAccountOnPortfolio.create({
data: {
portfolioId: portfolio.id,
accountId: input.id
}
});
},
"EDIT_ACCOUNT": async (input: EditAccountInput, portfolio: RWAPortfolio, prisma: Prisma.TransactionClient) => {
logger.debug({ msg: "Editing account", input });
Expand All @@ -399,6 +441,16 @@ const surgicalOperations: Record<string, (input: any, portfolio: RWAPortfolio, p
},
"DELETE_ACCOUNT": async (input: DeleteAccountInput, portfolio: RWAPortfolio, prisma: Prisma.TransactionClient) => {
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: {
Expand All @@ -416,6 +468,12 @@ const surgicalOperations: Record<string, (input: any, portfolio: RWAPortfolio, p
portfolioId: portfolio.id
}
});
await prisma.rWAPortfolioFixedIncomeTypeOnPortfolio.create({
data: {
portfolioId: portfolio.id,
fixedIncomeTypeId: input.id
}
});
},
"EDIT_FIXED_INCOME_TYPE": async (input: EditFixedIncomeTypeInput, portfolio: RWAPortfolio, prisma: Prisma.TransactionClient) => {
logger.debug({ msg: "Editing fixed income type", input });
Expand All @@ -432,6 +490,24 @@ const surgicalOperations: Record<string, (input: any, portfolio: RWAPortfolio, p
}
});
},
"DELETE_FIXED_INCOME_TYPE": async (input: DeleteFixedIncomeAssetInput, portfolio: RWAPortfolio, prisma: Prisma.TransactionClient) => {
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({
Expand Down Expand Up @@ -486,16 +562,18 @@ const surgicalOperations: Record<string, (input: any, portfolio: RWAPortfolio, p
id: input.id,
portfolioId: portfolio.id,
type: input.type,
entryTime: input.entryTime
entryTime: input.entryTime,
cashBalanceChange: input.cashBalanceChange.toString(),
unitPrice: input.unitPrice?.toString() ?? undefined,
}
});

for (const feeTx of input.fees ?? []) {
const { amount, serviceProviderFeeTypeId } = feeTx
const feeTxEntity = await prisma.rWABaseTransaction.create({
data: {
...feeTx,
id: feeTx.id ?? undefined,
amount: feeTx.amount,
id: id ?? undefined,
amount: amount,
portfolioId: portfolio.id,
}
});
Expand Down
2 changes: 1 addition & 1 deletion api/src/modules/real-world-assets/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export const AssetUnion = unionType({

export const GroupTransactionType = enumType({
name: "GroupTransactionType",
members: ['AssetPurchase', 'AssetSale', 'InterestDraw', 'InterestReturn', 'FeesPayment', 'PrincipalDraw', 'PrincipalReturn'],
members: ['AssetPurchase', 'AssetSale', 'InterestDraw', 'InterestReturn', 'FeesPayment', 'PrincipalDraw', 'PrincipalReturn', 'InterestPayment'],
});

export const RealWorldAssetsPortfolio = objectType({
Expand Down

0 comments on commit 079e8d7

Please sign in to comment.