Skip to content

Commit

Permalink
Made currency required in the API, cleaned up the create or connect l…
Browse files Browse the repository at this point in the history
…ogic (podkrepi-bg#574)
  • Loading branch information
yyosifov authored Nov 7, 2023
1 parent b523642 commit fcab466
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 34 deletions.
15 changes: 4 additions & 11 deletions apps/api/src/campaign/campaign.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -476,8 +476,8 @@ export class CampaignService {
return this.prisma.campaign.create(createInput)
}

async getCampaignVault(campaignId: string): Promise<Vault | null> {
return this.prisma.vault.findFirst({ where: { campaignId } })
async getCampaignVault(campaignId: string): Promise<Vault> {
return this.prisma.vault.findFirstOrThrow({ where: { campaignId } })
}

async getDonationsForCampaign(
Expand Down Expand Up @@ -695,15 +695,8 @@ export class CampaignService {
newDonationStatus,
)

/**
* Create or connect campaign vault
*/
const vault = await tx.vault.findFirst({ where: { campaignId: campaign.id } })
const targetVaultData = vault
? // Connect the existing vault to this donation
{ connect: { id: vault.id } }
: // Create new vault for the campaign
{ create: { campaignId: campaign.id, currency: campaign.currency, name: campaign.title } }
const vault = await tx.vault.findFirstOrThrow({ where: { campaignId: campaign.id } })
const targetVaultData = { connect: { id: vault.id } }

try {
const donation = await tx.donation.create({
Expand Down
4 changes: 0 additions & 4 deletions apps/api/src/campaign/dto/create-campaign.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,7 @@ export class CreateCampaignDto {
reachedAmount: number

@ApiProperty()
@IsOptional()
@Expose()
@IsString()
@MinLength(3)
@MaxLength(3)
@IsEnum(Currency)
currency: Currency

Expand Down
21 changes: 2 additions & 19 deletions apps/api/src/donations/donations.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,6 @@ export class DonationsService {
paymentIntentId,
})

// /**
// * Create or connect campaign vault
// */
// const vault = await this.prisma.vault.findFirst({ where: { campaignId: campaign.id } })
// const targetVaultData = vault
// ? // Connect the existing vault to this donation
// { connect: { id: vault.id } }
// : // Create new vault for the campaign
// { create: { campaignId: campaign.id, currency: campaign.currency, name: campaign.title } }

/**
* Here we cannot create initial donation anymore because stripe is not returning paymentIntendId in the CreateSessionDto
* It will be created in the paymentIntent.created webhook
Expand All @@ -107,15 +97,8 @@ export class DonationsService {
paymentIntentId: paymentIntent.id,
})

/**
* Create or connect campaign vault
*/
const vault = await this.prisma.vault.findFirst({ where: { campaignId: campaign.id } })
const targetVaultData = vault
? // Connect the existing vault to this donation
{ connect: { id: vault.id } }
: // Create new vault for the campaign
{ create: { campaignId: campaign.id, currency: campaign.currency, name: campaign.title } }
const vault = await this.campaignService.getCampaignVault(campaign.id)
const targetVaultData = { connect: { id: vault.id } }

/**
* Create or update initial donation object
Expand Down

0 comments on commit fcab466

Please sign in to comment.