2015-07-15 14:03:23 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
import alt from '../alt';
|
|
|
|
import OwnershipFetcher from '../fetchers/ownership_fetcher';
|
|
|
|
|
|
|
|
|
|
|
|
class LoanContractActions {
|
|
|
|
constructor() {
|
|
|
|
this.generateActions(
|
|
|
|
'updateLoanContract'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
fetchLoanContract(email) {
|
|
|
|
|
|
|
|
if(email.match(/.+\@.+\..+/)) {
|
|
|
|
OwnershipFetcher.fetchLoanContract(email)
|
|
|
|
.then((contracts) => {
|
|
|
|
if (contracts && contracts.length > 0) {
|
|
|
|
this.actions.updateLoanContract({
|
|
|
|
contractKey: contracts[0].s3Key,
|
2015-07-15 14:48:51 +02:00
|
|
|
contractUrl: contracts[0].s3Url,
|
|
|
|
contractEmail: email
|
2015-07-15 14:03:23 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.actions.updateLoanContract({
|
|
|
|
contractKey: null,
|
2015-07-15 14:48:51 +02:00
|
|
|
contractUrl: null,
|
|
|
|
contractEmail: null
|
2015-07-15 14:03:23 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
2015-07-17 15:41:09 +02:00
|
|
|
console.logGlobal(err);
|
2015-07-15 14:03:23 +02:00
|
|
|
this.actions.updateLoanContract({
|
|
|
|
contractKey: null,
|
2015-07-15 14:48:51 +02:00
|
|
|
contractUrl: null,
|
|
|
|
contractEmail: null
|
2015-07-15 14:03:23 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
/* No email was entered - Ignore and keep going*/
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default alt.createActions(LoanContractActions);
|