mirror of
https://github.com/ascribe/onion.git
synced 2024-12-22 17:33:14 +01:00
Merge pull request #81 from ascribe/AD-1524-coa-should-be-created-if-none-exists
If fetching COA results in 404, create a new COA
This commit is contained in:
commit
d996967dd9
@ -8,7 +8,12 @@ import EditionActions from '../actions/edition_actions';
|
||||
const CoaSource = {
|
||||
lookupCoa: {
|
||||
remote(state) {
|
||||
return requests.get('coa', { id: state.edition.coa });
|
||||
return requests
|
||||
.get('coa', { id: state.edition.coa })
|
||||
.then((res) => {
|
||||
// If no coa is found here, fake a 404 error so the error action can pick it up
|
||||
return (res && res.coa) ? res : Promise.reject({ json: { status: 404 } });
|
||||
});
|
||||
},
|
||||
|
||||
success: EditionActions.successFetchCoa,
|
||||
|
@ -31,9 +31,9 @@ class EditionStore {
|
||||
this.getInstance().lookupEdition();
|
||||
}
|
||||
|
||||
onSuccessFetchEdition(res) {
|
||||
if(res && res.edition) {
|
||||
this.edition = res.edition;
|
||||
onSuccessFetchEdition({ edition }) {
|
||||
if (edition) {
|
||||
this.edition = edition;
|
||||
this.editionMeta.err = null;
|
||||
this.editionMeta.idToFetch = null;
|
||||
|
||||
@ -48,9 +48,9 @@ class EditionStore {
|
||||
}
|
||||
}
|
||||
|
||||
onSuccessFetchCoa(res) {
|
||||
if (res && res.coa && Object.keys(this.edition).length) {
|
||||
this.edition.coa = res.coa;
|
||||
onSuccessFetchCoa({ coa }) {
|
||||
if (coa && Object.keys(this.edition).length) {
|
||||
this.edition.coa = coa;
|
||||
this.coaMeta.err = null;
|
||||
} else {
|
||||
this.coaMeta.err = new Error('Problem generating/fetching the COA');
|
||||
@ -73,8 +73,13 @@ class EditionStore {
|
||||
}
|
||||
|
||||
onErrorCoa(err) {
|
||||
// On 404s, create a new COA as the COA has not been made yet
|
||||
if (err && err.json && err.json.status === 404) {
|
||||
this.getInstance().performCreateCoa();
|
||||
} else {
|
||||
this.coaMeta.err = err;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default alt.createStore(EditionStore, 'EditionStore');
|
||||
|
Loading…
Reference in New Issue
Block a user