fix opencollective tracking
This commit is contained in:
parent
0b01929211
commit
7d07e89207
1 changed files with 21 additions and 8 deletions
|
@ -17,16 +17,14 @@ export class OpenCollective extends shield {
|
|||
this.transactions().then((data) => {
|
||||
try {
|
||||
this.json = JSON.parse(data);
|
||||
this.json.nodes.forEach((item) => {
|
||||
if (item.kind === "CONTRIBUTION" && item.order.frequency === "MONTHLY") {
|
||||
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.render(element);
|
||||
this.loadingEnd(element);
|
||||
} catch (e) {
|
||||
|
@ -37,6 +35,21 @@ export class OpenCollective extends shield {
|
|||
})
|
||||
}
|
||||
|
||||
|
||||
monthlyContributions(nodes) {
|
||||
let monthly = new Map();
|
||||
nodes.forEach(node => {
|
||||
if (node.kind === "CONTRIBUTION" && node.order.frequency === "MONTHLY" && node.order.status === "ACTIVE") {
|
||||
var id = `${node.oppositeAccount.id}${node.order.createdAt}`;
|
||||
if (!monthly.has(id)) {
|
||||
monthly.set(id, node);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
return Array.from(monthly.values());
|
||||
}
|
||||
|
||||
async transactions() {
|
||||
try {
|
||||
const fetch = new fetcher();
|
||||
|
|
Loading…
Reference in a new issue