You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: cloudflare-worker/src/db/d1-db.ts
+33Lines changed: 33 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -30,6 +30,7 @@ import {
30
30
IdMapping,
31
31
Publication,
32
32
Purchase,
33
+
PurchasesStatisticsData,
33
34
Refund,
34
35
Tester,
35
36
}from"../types/data";
@@ -867,6 +868,38 @@ export class CloudflareD1DB implements FeedbackFlowDB {
867
868
pageInfo,
868
869
}asPurchaseStatusResponse;
869
870
},
871
+
/**
872
+
* Get some statistics of purchases for a tester
873
+
* @param testerUuid UUID of the tester
874
+
* @returns Promise<PurchasesStatisticsData> Statistics data for the tester's purchases
875
+
*/
876
+
getPurchaseStatistics: async(
877
+
testerUuid: string,
878
+
): Promise<PurchasesStatisticsData>=>{
879
+
const{ results }=awaitthis.db
880
+
.prepare(
881
+
`SELECT
882
+
SUM(CASE WHEN refunded = 1 THEN 1 ELSE 0 END) as nb_refunded,
883
+
SUM(CASE WHEN refunded = 0 THEN 1 ELSE 0 END) as nb_not_refunded,
884
+
SUM(CASE WHEN refunded = 0 AND id IN (SELECT purchase_id FROM feedbacks) AND id IN (SELECT purchase_id FROM publications) THEN 1 ELSE 0 END) as nb_ready_for_refund,
885
+
COUNT(*) as nb_total,
886
+
SUM(CASE WHEN refunded = 1 THEN amount ELSE 0 END) as total_refunded_amount,
887
+
SUM(CASE WHEN refunded = 0 THEN amount ELSE 0 END) as total_not_refunded_amount,
0 commit comments