Skip to content

Commit 3a3b221

Browse files
committed
fix: update stats account fot uniqueDonorCount
1 parent 66deb71 commit 3a3b221

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

packages/repository/src/kysely/repositories/application.repository.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,24 @@ export class KyselyApplicationRepository implements IApplicationRepository<Kysel
169169
): Promise<void> {
170170
try {
171171
const queryBuilder = (tx || this.db).withSchema(this.schemaName);
172+
173+
const uniqueDonorsResult = await queryBuilder
174+
.withSchema(this.schemaName)
175+
.selectFrom("donations")
176+
.where("chainId", "=", where.chainId)
177+
.where("roundId", "=", where.roundId)
178+
.where("applicationId", "=", where.id)
179+
.select((qb) => qb.fn.count("donorAddress").distinct().as("uniqueDonorsCount"))
180+
.executeTakeFirst();
181+
182+
const uniqueDonorsCount = Number(uniqueDonorsResult?.uniqueDonorsCount ?? 0);
183+
172184
await queryBuilder
173185
.updateTable("applications")
174186
.set((eb) => ({
175187
totalDonationsCount: eb("totalDonationsCount", "+", 1),
176188
totalAmountDonatedInUsd: eb("totalAmountDonatedInUsd", "+", amountInUsd),
189+
uniqueDonorsCount,
177190
}))
178191
.where("id", "=", where.id)
179192
.where("chainId", "=", where.chainId)

packages/repository/src/kysely/repositories/round.repository.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,23 @@ export class KyselyRoundRepository implements IRoundRepository<KyselyTransaction
213213
): Promise<void> {
214214
try {
215215
const queryBuilder = (tx || this.db).withSchema(this.schemaName);
216+
217+
const uniqueDonorsResult = await queryBuilder
218+
.withSchema(this.schemaName)
219+
.selectFrom("donations")
220+
.where("chainId", "=", where.chainId)
221+
.where("roundId", "=", where.roundId)
222+
.select((qb) => qb.fn.count("donorAddress").distinct().as("uniqueDonorsCount"))
223+
.executeTakeFirst();
224+
225+
const uniqueDonorsCount = Number(uniqueDonorsResult?.uniqueDonorsCount ?? 0);
226+
216227
await queryBuilder
217228
.updateTable("rounds")
218229
.set((eb) => ({
219230
totalDonationsCount: eb("totalDonationsCount", "+", 1),
220231
totalAmountDonatedInUsd: eb("totalAmountDonatedInUsd", "+", amountInUsd),
232+
uniqueDonorsCount,
221233
}))
222234
.where("chainId", "=", where.chainId)
223235
.where("id", "=", where.roundId)

0 commit comments

Comments
 (0)