Process contributor data
Add util function for processing contributor data, and remove bignums, etc.
This commit is contained in:
@@ -1,14 +1,12 @@
|
|||||||
import EmberObject from '@ember/object';
|
import EmberObject from '@ember/object';
|
||||||
import bignumber from 'kredits-web/utils/cps/bignumber';
|
|
||||||
import kreditsValue from 'kredits-web/utils/cps/kredits';
|
|
||||||
|
|
||||||
export default EmberObject.extend({
|
export default EmberObject.extend({
|
||||||
// Contract
|
// Contract
|
||||||
id: bignumber('idRaw', 'toString'),
|
id: null,
|
||||||
account: null,
|
account: null,
|
||||||
balance: kreditsValue('balanceRaw'),
|
balance: 0,
|
||||||
totalKreditsEarned: bignumber('totalKreditsEarnedRaw', 'toNumber'),
|
totalKreditsEarned: 0,
|
||||||
contributionsCount: bignumber('contributionsCountRaw', 'toNumber'),
|
contributionsCount: 0,
|
||||||
isCore: false,
|
isCore: false,
|
||||||
ipfsHash: null,
|
ipfsHash: null,
|
||||||
|
|
||||||
@@ -20,6 +18,5 @@ export default EmberObject.extend({
|
|||||||
github_uid: null,
|
github_uid: null,
|
||||||
wiki_username: null,
|
wiki_username: null,
|
||||||
zoom_display_name: null,
|
zoom_display_name: null,
|
||||||
ipfsData: ''
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import { alias, notEmpty } from '@ember/object/computed';
|
|||||||
import { isEmpty, isPresent } from '@ember/utils';
|
import { isEmpty, isPresent } from '@ember/utils';
|
||||||
|
|
||||||
import groupBy from 'kredits-web/utils/group-by';
|
import groupBy from 'kredits-web/utils/group-by';
|
||||||
|
import processContributorData from 'kredits-web/utils/process-contributor-data';
|
||||||
import formatKredits from 'kredits-web/utils/format-kredits';
|
import formatKredits from 'kredits-web/utils/format-kredits';
|
||||||
|
|
||||||
import config from 'kredits-web/config/environment';
|
import config from 'kredits-web/config/environment';
|
||||||
@@ -208,8 +209,8 @@ export default Service.extend({
|
|||||||
getContributors () {
|
getContributors () {
|
||||||
return this.kredits.Contributor.all()
|
return this.kredits.Contributor.all()
|
||||||
.then(contributors => {
|
.then(contributors => {
|
||||||
return contributors.map(contributor => {
|
return contributors.map(data => {
|
||||||
return Contributor.create(contributor);
|
return Contributor.create(processContributorData(data));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
export default function processContributorData(data) {
|
||||||
|
const processed = {
|
||||||
|
id: data.id.toString(),
|
||||||
|
balance: data.balanceInt,
|
||||||
|
totalKreditsEarned: data.totalKreditsEarned,
|
||||||
|
contributionsCount: data.contributionsCount.toNumber()
|
||||||
|
}
|
||||||
|
|
||||||
|
const otherProperties = [
|
||||||
|
'account', 'accounts', 'ipfsHash', 'isCore', 'kind', 'name', 'url',
|
||||||
|
'github_username', 'github_uid', 'wiki_username', 'zoom_display_name'
|
||||||
|
];
|
||||||
|
|
||||||
|
otherProperties.forEach(prop => {
|
||||||
|
processed[prop] = data[prop];
|
||||||
|
});
|
||||||
|
|
||||||
|
return processed;
|
||||||
|
}
|
||||||
Vendored
+64
@@ -0,0 +1,64 @@
|
|||||||
|
export default {
|
||||||
|
"0": 1,
|
||||||
|
"1": "0x7E8f313C56F809188313aa274Fa67EE58c31515d",
|
||||||
|
"2": "0x99b8afd7b266e19990924a8be9099e81054b70c36b20937228a77a5cf75723b8",
|
||||||
|
"3": 18,
|
||||||
|
"4": 32,
|
||||||
|
"5": true,
|
||||||
|
"6": {
|
||||||
|
"_hex": "0x09979c0838e8fc880000"
|
||||||
|
},
|
||||||
|
"7": 53500,
|
||||||
|
"8": {
|
||||||
|
"_hex": "0x49"
|
||||||
|
},
|
||||||
|
"9": true,
|
||||||
|
"id": 1,
|
||||||
|
"account": "0x7E8f313C56F809188313aa274Fa67EE58c31515d",
|
||||||
|
"hashDigest": "0x99b8afd7b266e19990924a8be9099e81054b70c36b20937228a77a5cf75723b8",
|
||||||
|
"hashFunction": 18,
|
||||||
|
"hashSize": 32,
|
||||||
|
"isCore": true,
|
||||||
|
"balance": {
|
||||||
|
"_hex": "0x09979c0838e8fc880000"
|
||||||
|
},
|
||||||
|
"totalKreditsEarned": 53500,
|
||||||
|
"contributionsCount": {
|
||||||
|
"_hex": "0x49",
|
||||||
|
"toNumber": function() { return 73; }
|
||||||
|
},
|
||||||
|
"exists": true,
|
||||||
|
"balanceInt": 45298,
|
||||||
|
"ipfsHash": "QmYgiRd1FZ7JjDGBwkmLQNF6XQuyF8AWoFDRvUWhhmxiEj",
|
||||||
|
"name": "Bumi",
|
||||||
|
"kind": "person",
|
||||||
|
"url": "https://michaelbumann.com",
|
||||||
|
"accounts": [
|
||||||
|
{
|
||||||
|
"site": "github.com",
|
||||||
|
"uid": 318,
|
||||||
|
"username": "bumi",
|
||||||
|
"url": "https://github.com/bumi"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"site": "gitea.kosmos.org",
|
||||||
|
"username": "bumi",
|
||||||
|
"url": "https://gitea.kosmos.org/bumi"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"site": "wiki.kosmos.org",
|
||||||
|
"username": "Bumi",
|
||||||
|
"url": "https://wiki.kosmos.org/User:Bumi"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"site": "zoom.us",
|
||||||
|
"username": "bumi"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"github_uid": 318,
|
||||||
|
"github_username": "bumi",
|
||||||
|
"gitea_username": "bumi",
|
||||||
|
"wiki_username": "Bumi",
|
||||||
|
"zoom_display_name": "bumi",
|
||||||
|
"ipfsData": "{\n \"@context\": \"https://schema.kosmos.org\",\n \"@type\": \"Contributor\",\n \"kind\": \"person\",\n \"name\": \"Bumi\",\n \"accounts\": [\n {\n \"site\": \"github.com\",\n \"uid\": 318,\n \"username\": \"bumi\",\n \"url\": \"https://github.com/bumi\"\n },\n {\n \"site\": \"gitea.kosmos.org\",\n \"username\": \"bumi\",\n \"url\": \"https://gitea.kosmos.org/bumi\"\n },\n {\n \"site\": \"wiki.kosmos.org\",\n \"username\": \"Bumi\",\n \"url\": \"https://wiki.kosmos.org/User:Bumi\"\n },\n {\n \"site\": \"zoom.us\",\n \"username\": \"bumi\"\n }\n ],\n \"url\": \"https://michaelbumann.com\"\n}"
|
||||||
|
}
|
||||||
Vendored
+3
-3
@@ -3,9 +3,9 @@ import Contributor from 'kredits-web/models/contributor';
|
|||||||
const contributors = [];
|
const contributors = [];
|
||||||
|
|
||||||
const data = [
|
const data = [
|
||||||
{ id: 1, name: 'Bumi', totalKreditsEarned: 11500, github_uid: 318 },
|
{ id: '1', name: 'Bumi', totalKreditsEarned: 11500, github_uid: 318 },
|
||||||
{ id: 2, name: 'Râu Cao', totalKreditsEarned: 3000, github_uid: 842 },
|
{ id: '2', name: 'Râu Cao', totalKreditsEarned: 3000, github_uid: 842 },
|
||||||
{ id: 3, name: 'Manuel', totalKreditsEarned: 0, github_uid: 54812 }
|
{ id: '3', name: 'Manuel', totalKreditsEarned: 0, github_uid: 54812 }
|
||||||
];
|
];
|
||||||
|
|
||||||
data.forEach(attrs => contributors.push(Contributor.create(attrs)));
|
data.forEach(attrs => contributors.push(Contributor.create(attrs)));
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
import { module, test } from 'qunit';
|
||||||
|
import processContributorData from 'kredits-web/utils/process-contributor-data';
|
||||||
|
import testData from '../../fixtures/contributor-data';
|
||||||
|
|
||||||
|
module('Unit | Utility | process-contributor-data', function() {
|
||||||
|
|
||||||
|
let result = processContributorData(testData);
|
||||||
|
|
||||||
|
test('formats the data correctly', function(assert) {
|
||||||
|
// TODO use integers everywhere for IDs
|
||||||
|
assert.ok(typeof result.id == 'string');
|
||||||
|
assert.ok(typeof result.balance == 'number');
|
||||||
|
assert.ok(typeof result.totalKreditsEarned == 'number');
|
||||||
|
assert.ok(typeof result.contributionsCount == 'number');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('copies other properties', function(assert) {
|
||||||
|
[
|
||||||
|
'account', 'accounts', 'ipfsHash', 'isCore', 'kind', 'name', 'url',
|
||||||
|
'github_username', 'github_uid', 'wiki_username', 'zoom_display_name'
|
||||||
|
].forEach(p => {
|
||||||
|
assert.ok(Object.prototype.hasOwnProperty.call(result, p), `copies property ${p}`);
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
test('does not copy unnecessary properties', function(assert) {
|
||||||
|
['exists', '5'].forEach(p => {
|
||||||
|
assert.notOk(Object.prototype.hasOwnProperty.call(result, p));
|
||||||
|
})
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user