Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add platform statistics #487

Merged
merged 10 commits into from
Apr 24, 2023
12 changes: 12 additions & 0 deletions apps/api/src/donations/donations.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,18 @@ export class DonationsController {
return await this.donationsService.getDonationsByUser(user.sub)
}

@Get('money')
@Public()
async totalDonatedMoney() {
return this.donationsService.getTotalDonatedMoney()
}

@Get('donors-count')
@Public()
async donorsCount() {
return await this.donationsService.getDonorsCount()
}

@Get('listPublic')
@Public()
@ApiQuery({ name: 'campaignId', required: false, type: String })
Expand Down
27 changes: 27 additions & 0 deletions apps/api/src/donations/donations.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,33 @@ export class DonationsService {
return user.id
}

async getTotalDonatedMoney() {
const totalMoney = await this.prisma.donation.aggregate({
_sum: {
amount: true,
},
where: { status: DonationStatus.succeeded },
})
return { total: totalMoney._sum.amount }
}

async getDonorsCount() {
const donorsCount = await this.prisma.donation.groupBy({
by: ['billingName'],
where: { status: DonationStatus.succeeded },
_count: {
_all: true,
},
orderBy: { billingName: { sort: 'asc', nulls: 'first' } },
})

// get count of the donations with billingName == null
const anonymousDonations = donorsCount[0]._count._all

// substract one because we don't want to include anonymousDonation again
return { count: donorsCount.length - 1 + anonymousDonations }
}

/**
* @param res - Response object to be used for the export to excel file
*/
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/vault/vault.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { CampaignService } from '../campaign/campaign.service'
import { CreateVaultDto } from './dto/create-vault.dto'
import { UpdateVaultDto } from './dto/update-vault.dto'
import { KeycloakTokenParsed } from '../auth/keycloak'
import { ApiTags } from '@nestjs/swagger';
import { ApiTags } from '@nestjs/swagger'

@ApiTags('vault')
@Controller('vault')
Expand Down
1 change: 1 addition & 0 deletions schema.prisma
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
generator client {
provider = "prisma-client-js"
binaryTargets = ["native"]
previewFeatures = ["orderByNulls"]
}

generator dbml {
Expand Down