fix opencollective tracking
This commit is contained in:
parent
0b01929211
commit
1b32707089
1 changed files with 30 additions and 1 deletions
|
@ -17,6 +17,17 @@ export class OpenCollective extends shield {
|
||||||
this.transactions().then((data) => {
|
this.transactions().then((data) => {
|
||||||
try {
|
try {
|
||||||
this.json = JSON.parse(data);
|
this.json = JSON.parse(data);
|
||||||
|
this.monthlyContributions(this.json.nodes).forEach((item) => {
|
||||||
|
console.log("item", item);
|
||||||
|
item = item[0];
|
||||||
|
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) => {
|
this.json.nodes.forEach((item) => {
|
||||||
if (item.kind === "CONTRIBUTION" && item.order.frequency === "MONTHLY") {
|
if (item.kind === "CONTRIBUTION" && item.order.frequency === "MONTHLY") {
|
||||||
if (this.total[item.amount.currency] !== undefined) {
|
if (this.total[item.amount.currency] !== undefined) {
|
||||||
|
@ -26,7 +37,7 @@ export class OpenCollective extends shield {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
*/
|
||||||
this.render(element);
|
this.render(element);
|
||||||
this.loadingEnd(element);
|
this.loadingEnd(element);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -37,6 +48,24 @@ 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
console.log("monthly", monthly);
|
||||||
|
return Array.from(monthly.values());
|
||||||
|
}
|
||||||
|
|
||||||
async transactions() {
|
async transactions() {
|
||||||
try {
|
try {
|
||||||
const fetch = new fetcher();
|
const fetch = new fetcher();
|
||||||
|
|
Loading…
Reference in a new issue