Skip to content

Commit

Permalink
vault.service: Select campaign data as json object
Browse files Browse the repository at this point in the history
  • Loading branch information
sashko9807 committed Dec 12, 2023
1 parent 2269643 commit 54a5844
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions apps/api/src/vault/vault.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ import { PrismaService } from '../prisma/prisma.service'
import { CreateVaultDto } from './dto/create-vault.dto'
import { UpdateVaultDto } from './dto/update-vault.dto'

type VaultWithWithdrawalSum = Vault & { withdrawnAmount: number; campaignTitle: string }
type VaultWithWithdrawalSum = Prisma.VaultGetPayload<{
include: { campaign: { select: { id: true; title: true } } }
}> & {
withdrawnAmount: number
}

@Injectable()
export class VaultService {
Expand All @@ -37,7 +41,7 @@ export class VaultService {
v.currency, v."blockedAmount",
v.name,
v.amount,
c.title as "campaignTitle",
json_build_object('id', campaign.id, 'title', campaign.title) AS campaign,
COALESCE(SUM(w."successfullWithdrawn")::INTEGER, 0) as "withdrawnAmount"
FROM vaults v
LEFT JOIN LATERAL (
Expand All @@ -49,9 +53,9 @@ export class VaultService {
LEFT JOIN LATERAL (
SELECT id, title FROM campaigns WHERE id::uuid = v.campaign_id::uuid
) as c ON TRUE
) as campaign ON TRUE
GROUP BY v.id, c.title
GROUP BY v.id, campaign.id, campaign.title
`
return result
}
Expand Down

0 comments on commit 54a5844

Please sign in to comment.