-
Notifications
You must be signed in to change notification settings - Fork 48
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
Changes from 3 commits
92f0403
85534ff
f19c047
a1f5771
bbb6a67
38e0a34
b203d7f
a31b597
1e992a4
802927b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -677,6 +677,20 @@ export class DonationsService { | |
return user.id | ||
} | ||
|
||
async getDonatedUsersCount() { | ||
const donatedUsersCount = await this.prisma.donation.groupBy({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't quite get the idea to group the donations by personId. Is there a reason not to use the prisma count() API, to get the total amount of succeeded donations? Edit: Saw that I commented on an outdated file for which I apologize, but since the logic has not changed, the question remains. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, After a discussion with @igoychev, we decided that it would be better to group the donations by "billingName". Regarding your question - we should have a way to count how many donations has "billingName" as null value, since we count them as different donors. Unfortunately, this is currently not possible with count()+distinct functionality provided by prisma, at least I couldn't find out how to do that. Therefore we had a two ways to implement this - having two queries or the way which I had implemented it. I'm open to any suggestions how we can improve that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the explanation, by reading the front-end related issue, I was left with the impression that total amount of donations was supposed to be shown, rather than the total amount of users who have donated. Aside from using raw SQL query to avoid prisma's limitation, the only improvement I could really think of is to order the records by null first(if possible). That way Also not sure if it is necessary to cover the unlikely usecase of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the suggestion. I have implemented it and now donations with billingName = "null" will appear always first , and in this way query is running in O(1). So regarding the front-end issue , there is a small change. Instead of the number of active contributors, we decided to show the number of donors. So we will have both - total amount of donations and number of different donors. |
||
by: ['personId'], | ||
where: { status: DonationStatus.succeeded }, | ||
_count: { | ||
_all: true, | ||
}, | ||
}) | ||
|
||
const anonymousDonations = donatedUsersCount.find((donation) => donation.personId === null) | ||
// substract one because anonymous donation is within all donations | ||
return { count: donatedUsersCount.length - 1 + (anonymousDonations?._count._all ?? 0) } | ||
} | ||
|
||
/** | ||
* @param res - Response object to be used for the export to excel file | ||
*/ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[naming] in this way the endpoint will be /api/v1/donation/user-donations, however it actually returns donors-count, so let's name it like this: /api/v1/donation/donors-count