1
0
mirror of https://github.com/ascribe/onion.git synced 2024-06-30 13:41:57 +02:00

create CoA when not found

This commit is contained in:
diminator 2015-09-30 09:14:57 +02:00
parent e356570bc8
commit ea4805caa0
2 changed files with 38 additions and 15 deletions

View File

@ -3,6 +3,7 @@
import alt from '../alt'; import alt from '../alt';
import CoaFetcher from '../fetchers/coa_fetcher'; import CoaFetcher from '../fetchers/coa_fetcher';
import Q from 'q';
class CoaActions { class CoaActions {
constructor() { constructor() {
@ -13,22 +14,39 @@ class CoaActions {
} }
fetchOne(id) { fetchOne(id) {
CoaFetcher.fetchOne(id) return Q.Promise((resolve, reject) => {
.then((res) => { CoaFetcher.fetchOne(id)
this.actions.updateCoa(res.coa); .then((res) => {
}) if (res.coa) {
.catch((err) => { this.actions.updateCoa(res.coa);
console.logGlobal(err); resolve(res.coa);
}); }
else {
this.actions.updateCoa(null);
resolve(null);
}
})
.catch((err) => {
console.logGlobal(err);
this.actions.updateCoa(null);
reject(err);
});
});
} }
create(edition) { create(edition) {
CoaFetcher.create(edition.bitcoin_id) return Q.Promise((resolve, reject) => {
.then((res) => { CoaFetcher.create(edition.bitcoin_id)
this.actions.updateCoa(res.coa); .then((res) => {
}) this.actions.updateCoa(res.coa);
.catch((err) => { })
console.logGlobal(err); .catch((err) => {
}); console.logGlobal(err);
this.actions.updateCoa(null);
reject(err);
});
});
} }
} }

View File

@ -338,7 +338,12 @@ let CoaDetails = React.createClass({
componentDidMount() { componentDidMount() {
CoaStore.listen(this.onChange); CoaStore.listen(this.onChange);
if(this.props.edition.coa) { if(this.props.edition.coa) {
CoaActions.fetchOne(this.props.edition.coa); CoaActions.fetchOne(this.props.edition.coa)
.then((res) => {
if (res === null){
CoaActions.create(this.props.edition);
}
});
} }
else { else {
CoaActions.create(this.props.edition); CoaActions.create(this.props.edition);