fix opencollective tracking

This commit is contained in:
zutto 2024-08-18 09:02:15 +03:00
parent 0b01929211
commit 560bfd05c7

View file

@ -17,6 +17,15 @@ export class OpenCollective extends shield {
this.transactions().then((data) => {
try {
this.json = JSON.parse(data);
this.monthlyContributions(this.json.nodes).forEach((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 +35,7 @@ export class OpenCollective extends shield {
}
}
});
*/
this.render(element);
this.loadingEnd(element);
} catch (e) {
@ -37,6 +46,23 @@ export class OpenCollective extends shield {
})
}
monthlyContributions(nodes) {
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];
}
}
}
return monthly;
}
async transactions() {
try {
const fetch = new fetcher();