Fix missing contributors in toplist
Adds contributors without unconfirmed contributions to the kreditsByContributor collection. fixes #114
This commit is contained in:
+17
-2
@@ -46,18 +46,33 @@ export default Service.extend({
|
|||||||
}),
|
}),
|
||||||
|
|
||||||
kreditsByContributor: computed('contributionsUnconfirmed.[]', 'contributors', function() {
|
kreditsByContributor: computed('contributionsUnconfirmed.[]', 'contributors', function() {
|
||||||
const contributionsGrouped = groupBy(this.contributionsUnconfirmed, 'contributorId');
|
const contributionsUnconfirmed = this.contributionsUnconfirmed;
|
||||||
|
const contributionsGrouped = groupBy(contributionsUnconfirmed, 'contributorId');
|
||||||
|
const contributorsWithUnconfirmed = contributionsGrouped.map(c => c.value.toString());
|
||||||
|
const contributorsWithOnlyConfirmed = this.contributors.reject(c => contributorsWithUnconfirmed.includes(c.id))
|
||||||
|
|
||||||
return contributionsGrouped.map(c => {
|
const kreditsByContributor = contributionsGrouped.map(c => {
|
||||||
const amountUnconfirmed = c.items.mapBy('amount').reduce((a, b) => a + b);
|
const amountUnconfirmed = c.items.mapBy('amount').reduce((a, b) => a + b);
|
||||||
const contributor = this.contributors.findBy('id', c.value.toString());
|
const contributor = this.contributors.findBy('id', c.value.toString());
|
||||||
|
|
||||||
return EmberObject.create({
|
return EmberObject.create({
|
||||||
contributor: contributor,
|
contributor: contributor,
|
||||||
amountUnconfirmed: amountUnconfirmed,
|
amountUnconfirmed: amountUnconfirmed,
|
||||||
amountConfirmed: contributor.totalKreditsEarned,
|
amountConfirmed: contributor.totalKreditsEarned,
|
||||||
amountTotal: contributor.totalKreditsEarned + amountUnconfirmed
|
amountTotal: contributor.totalKreditsEarned + amountUnconfirmed
|
||||||
})
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
contributorsWithOnlyConfirmed.forEach(c => {
|
||||||
|
kreditsByContributor.push(EmberObject.create({
|
||||||
|
contributor: c,
|
||||||
|
amountUnconfirmed: 0,
|
||||||
|
amountConfirmed: c.totalKreditsEarned,
|
||||||
|
amountTotal: c.totalKreditsEarned
|
||||||
|
}));
|
||||||
})
|
})
|
||||||
|
|
||||||
|
return kreditsByContributor;
|
||||||
}),
|
}),
|
||||||
|
|
||||||
init () {
|
init () {
|
||||||
|
|||||||
@@ -32,8 +32,6 @@ module('Unit | Service | kredits', function(hooks) {
|
|||||||
|
|
||||||
const kreditsByContributor = service.kreditsByContributor;
|
const kreditsByContributor = service.kreditsByContributor;
|
||||||
|
|
||||||
console.log(kreditsByContributor);
|
|
||||||
|
|
||||||
assert.equal(kreditsByContributor.length, 3, 'includes all contributors with confirmed kredits');
|
assert.equal(kreditsByContributor.length, 3, 'includes all contributors with confirmed kredits');
|
||||||
|
|
||||||
const c1 = kreditsByContributor.find(k => k.contributor.id == 1);
|
const c1 = kreditsByContributor.find(k => k.contributor.id == 1);
|
||||||
|
|||||||
Reference in New Issue
Block a user