Merge pull request #41 from 67P/refactor/cleanup-models

Cleanup controller, templates and service
This commit was merged in pull request #41.
This commit is contained in:
2018-04-08 12:56:05 +00:00
committed by GitHub
6 changed files with 99 additions and 121 deletions
+20 -20
View File
@@ -109,24 +109,22 @@ export default Service.extend({
});
},
// TODO: Should be part of the service
buildContributor(attributes) {
debug('[kredits] buildContributor', attributes);
buildModel(name, attributes) {
debug('[kredits] build', name, attributes);
let model = getOwner(this).lookup(`model:${name}`);
let contributor = getOwner(this).lookup('model:contributor');
contributor.setProperties(attributes);
return contributor;
},
// coerce id to string
if (attributes.id) {
attributes.id = attributes.id.toString();
}
buildProposal(attributes) {
debug('[kredits] buildProposal', attributes);
let proposal = getOwner(this).lookup('model:proposal');
proposal.setProperties(attributes);
return proposal;
model.setProperties(attributes);
return model;
},
getContributorById(id) {
id = ethers.utils.bigNumberify(id);
return this.get('contributorsContract')
.then((contract) => contract.getContributorById(id))
.then(this.reassembleIpfsHash)
@@ -135,7 +133,7 @@ export default Service.extend({
let isCurrentUser = this.get('currentUserAccounts').includes(address);
return {
id: id.toString(),
id: id,
address,
balance: balance.toNumber(),
ipfsHash,
@@ -148,7 +146,7 @@ export default Service.extend({
return this.fetchAndMergeIpfsData(data, ContributorSerializer);
})
.then((attributes) => {
return this.buildContributor(attributes);
return this.buildModel('contributor', attributes);
});
},
@@ -203,6 +201,8 @@ export default Service.extend({
},
getProposalById(id) {
id = ethers.utils.bigNumberify(id);
return this.get('kreditsContract')
.then((contract) => contract.proposals(id))
.then(this.reassembleIpfsHash)
@@ -217,9 +217,9 @@ export default Service.extend({
ipfsHash,
}) => {
return {
id: id.toString(),
id: id,
creatorAddress,
recipientId: recipientId.toNumber(),
recipientId: recipientId.toString(),
votesCount: votesCount.toNumber(),
votesNeeded: votesNeeded.toNumber(),
amount: amount.toNumber(),
@@ -232,7 +232,7 @@ export default Service.extend({
return this.fetchAndMergeIpfsData(data, ContributionSerializer);
})
.then((attributes) => {
return this.buildProposal(attributes);
return this.buildModel('proposal', attributes);
});
},
@@ -296,7 +296,7 @@ export default Service.extend({
})
.then((data) => {
debug('[kredits] add contributor response', data);
return this.buildContributor(attributes);
return this.buildModel('contributor', attributes);
});
},
@@ -333,7 +333,7 @@ export default Service.extend({
})
.then((data) => {
debug('[kredits] add proposal response', data);
return this.buildProposal(attributes);
return this.buildModel('proposal', attributes);
});
},