From b2a43697d7d3bd3e3f15f3e612e8ecf8f5626f4f Mon Sep 17 00:00:00 2001 From: zutto Date: Sun, 18 Aug 2024 09:02:15 +0300 Subject: [PATCH] fix opencollective tracking --- src/js/plugins/opencollective.js | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/js/plugins/opencollective.js b/src/js/plugins/opencollective.js index 9e8155c..fe3172d 100644 --- a/src/js/plugins/opencollective.js +++ b/src/js/plugins/opencollective.js @@ -17,6 +17,18 @@ export class OpenCollective extends shield { this.transactions().then((data) => { try { this.json = JSON.parse(data); + let monthly = this.monthlyContributions(this.json.nodes); + console.log("monthly", monthly); + monthly.forEach((item) => { + console.log("processing", item); + if (this.total[item.amount.currency] !== undefined) { + this.total[item.amount.currency] += (item.amount.value * -1); + } else { + this.total[item.amount.currency] = (item.amount.value * -1); + } + + }); + /* this.json.nodes.forEach((item) => { if (item.kind === "CONTRIBUTION" && item.order.frequency === "MONTHLY") { if (this.total[item.amount.currency] !== undefined) { @@ -26,7 +38,7 @@ export class OpenCollective extends shield { } } }); - + */ this.render(element); this.loadingEnd(element); } catch (e) { @@ -37,6 +49,23 @@ export class OpenCollective extends shield { }) } + + monthlyContributions(nodes) { + let monthly = new Map(); + nodes.forEach(node => { + //group items by node.order.createdAt + if (node.kind === "CONTRIBUTION" && node.order.frequency === "MONTHLY" && node.order.status === "ACTIVE") { + var id = `${node.oppositeAccount.id}${node.order.createdAt}`; + if (monthly[id] === undefined) { + monthly[id] = [node]; + console.log("new", id); + } + } + } + ); + return monthly; + } + async transactions() { try { const fetch = new fetcher();