mirror of
https://github.com/ascribe/onion.git
synced 2024-11-15 01:25:17 +01:00
create public agreement
This commit is contained in:
parent
23eb3a7fd9
commit
ef22707680
@ -1,47 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
import alt from '../alt';
|
||||
import OwnershipFetcher from '../fetchers/ownership_fetcher';
|
||||
|
||||
|
||||
class ContractActions {
|
||||
constructor() {
|
||||
this.generateActions(
|
||||
'updateContract',
|
||||
'flushContract'
|
||||
);
|
||||
}
|
||||
|
||||
fetchContract(email) {
|
||||
if(email.match(/.+\@.+\..+/)) {
|
||||
OwnershipFetcher.fetchContract(email)
|
||||
.then((contracts) => {
|
||||
if (contracts && contracts.length > 0) {
|
||||
this.actions.updateContract({
|
||||
contractKey: contracts[0].s3Key,
|
||||
contractUrl: contracts[0].s3Url,
|
||||
contractEmail: email
|
||||
});
|
||||
}
|
||||
else {
|
||||
this.actions.updateContract({
|
||||
contractKey: null,
|
||||
contractUrl: null,
|
||||
contractEmail: null
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
console.logGlobal(err);
|
||||
this.actions.updateContract({
|
||||
contractKey: null,
|
||||
contractUrl: null,
|
||||
contractEmail: null
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default alt.createActions(ContractActions);
|
@ -4,7 +4,7 @@ import alt from '../alt';
|
||||
import Q from 'q';
|
||||
|
||||
import OwnershipFetcher from '../fetchers/ownership_fetcher';
|
||||
|
||||
import ContractListActions from './contract_list_actions';
|
||||
|
||||
class ContractAgreementListActions {
|
||||
constructor() {
|
||||
@ -16,25 +16,69 @@ class ContractAgreementListActions {
|
||||
|
||||
fetchContractAgreementList(issuer, accepted, pending) {
|
||||
return Q.Promise((resolve, reject) => {
|
||||
this.actions.updateContractAgreementList(null);
|
||||
OwnershipFetcher.fetchContractAgreementList(issuer, accepted, pending)
|
||||
.then((contractAgreementList) => {
|
||||
if (contractAgreementList.count > 0) {
|
||||
this.actions.updateContractAgreementList(contractAgreementList.results);
|
||||
resolve(contractAgreementList.results);
|
||||
}
|
||||
else {
|
||||
this.actions.updateContractAgreementList(null);
|
||||
else{
|
||||
resolve(null);
|
||||
}
|
||||
resolve();
|
||||
})
|
||||
.catch((err) => {
|
||||
console.logGlobal(err);
|
||||
this.actions.updateContractAgreementList(null);
|
||||
reject(err);
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
fetchAvailableContractAgreementList(issuer){
|
||||
this.actions.fetchContractAgreementList(issuer, 'True', null)
|
||||
.then((contractAgreementListAccepted) => {
|
||||
if (!contractAgreementListAccepted) {
|
||||
// fetch pending agreements if no accepted ones
|
||||
return this.actions.fetchContractAgreementList(issuer, null, 'True');
|
||||
}
|
||||
}).then((contractAgreementListPending) => {
|
||||
// fetch public contract if no accepted nor pending agreements
|
||||
if (!contractAgreementListPending) {
|
||||
return ContractListActions.fetchContractList(null, null, issuer);
|
||||
}
|
||||
}).then((publicContract) => {
|
||||
// create an agreement with the public contract if there is one
|
||||
if (publicContract && publicContract.length > 0) {
|
||||
return this.actions.createContractAgreement(null, publicContract[0]);
|
||||
}
|
||||
else {
|
||||
/*
|
||||
contractAgreementList in the store is already set to null;
|
||||
*/
|
||||
}
|
||||
}).then((publicContracAgreement) => {
|
||||
if (publicContracAgreement) {
|
||||
this.actions.updateContractAgreementList([publicContracAgreement]);
|
||||
}
|
||||
}).catch((err) => {
|
||||
console.logGlobal(err);
|
||||
});
|
||||
}
|
||||
|
||||
createContractAgreement(issuer, contract){
|
||||
return Q.Promise((resolve, reject) => {
|
||||
OwnershipFetcher.createContractAgreement(issuer, contract).then(
|
||||
(contractAgreement) => {
|
||||
resolve(contractAgreement);
|
||||
}
|
||||
).catch((err) => {
|
||||
console.logGlobal(err);
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default alt.createActions(ContractAgreementListActions);
|
||||
|
@ -12,15 +12,19 @@ class ContractListActions {
|
||||
);
|
||||
}
|
||||
|
||||
fetchContractList(isActive) {
|
||||
OwnershipFetcher.fetchContractList(isActive)
|
||||
.then((contracts) => {
|
||||
this.actions.updateContractList(contracts.results);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.logGlobal(err);
|
||||
this.actions.updateContractList([]);
|
||||
});
|
||||
fetchContractList(isActive, isPublic, issuer) {
|
||||
return Q.Promise((resolve, reject) => {
|
||||
OwnershipFetcher.fetchContractList(isActive, isPublic, issuer)
|
||||
.then((contracts) => {
|
||||
this.actions.updateContractList(contracts.results);
|
||||
resolve(contracts.results);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.logGlobal(err);
|
||||
this.actions.updateContractList([]);
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
@ -54,14 +54,8 @@ let LoanForm = React.createClass({
|
||||
componentDidMount() {
|
||||
ContractAgreementListStore.listen(this.onChange);
|
||||
if (this.props.email){
|
||||
ContractAgreementListActions.fetchContractAgreementList(
|
||||
this.props.email, 'True', null);
|
||||
ContractAgreementListActions.fetchAvailableContractAgreementList.defer(this.props.email);
|
||||
}
|
||||
|
||||
/* @Tim:
|
||||
throws Uncaught TypeError: Cannot read property 'defer' of undefined
|
||||
We might not need this
|
||||
ContractAgreementListActions.flushContractAgreementList().defer();*/
|
||||
},
|
||||
|
||||
componentWillUnmount() {
|
||||
|
@ -15,8 +15,21 @@ let OwnershipFetcher = {
|
||||
/**
|
||||
* Fetch the contracts of the logged-in user from the API.
|
||||
*/
|
||||
fetchContractList(isActive){
|
||||
return requests.get(ApiUrls.ownership_contract_list, isActive);
|
||||
fetchContractList(isActive, isPublic, issuer){
|
||||
let queryParams = {
|
||||
isActive,
|
||||
isPublic,
|
||||
issuer
|
||||
};
|
||||
return requests.get(ApiUrls.ownership_contract_list, queryParams);
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Create a contractagreement between the logged-in user and the email from the API with contract.
|
||||
*/
|
||||
createContractAgreement(signee, contractObj){
|
||||
return requests.post(ApiUrls.ownership_contract_agreements, { body: {signee: signee, contract: contractObj.id }});
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -1,28 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
import alt from '../alt';
|
||||
import ContractActions from '../actions/contract_actions';
|
||||
|
||||
|
||||
class ContractStore {
|
||||
constructor() {
|
||||
this.contractKey = null;
|
||||
this.contractUrl = null;
|
||||
this.contractEmail = null;
|
||||
this.bindActions(ContractActions);
|
||||
}
|
||||
|
||||
onUpdateContract({contractKey, contractUrl, contractEmail}) {
|
||||
this.contractKey = contractKey;
|
||||
this.contractUrl = contractUrl;
|
||||
this.contractEmail = contractEmail;
|
||||
}
|
||||
|
||||
onFlushContract() {
|
||||
this.contractKey = null;
|
||||
this.contractUrl = null;
|
||||
this.contractEmail = null;
|
||||
}
|
||||
}
|
||||
|
||||
export default alt.createStore(ContractStore, 'ContractStore');
|
Loading…
Reference in New Issue
Block a user