client-ui
Version:
Testing implementation of nodeJs Backend, angular frontend, and hopefully in a way that this can be deployed to s3/cloudfront
75 lines (67 loc) • 2.72 kB
JavaScript
(function () {
'use strict';
angular.module(moduleName).controller('identityDocumentController', identityDocumentController);
identityDocumentController.$inject = ['$filter', '$state', 'client', 'loan', 'util', '$q', '$rootScope'];
function identityDocumentController($filter, $state, clientService, loanService, util, $q, $rootScope) {
var self = this;
self.client = clientService.getClientStore();
self.generateUploadUrl = generateUploadUrl;
self.onUploadSuccess = onUploadSuccess;
self.onFileAdded = onFileAdded;
self.onRemoveItem = onRemoveItem;
self.init = init;
function init() {
self.allowedDocTypes = null;
self.working = false;
self.hasPendingDocs = false;
self.uploadedDocs = [];
for (var i in self.client.documents) {
if (self.client.documents[i].documentPurpose === "identityVerification") {
self.uploadedDocs.push(self.client.documents[i]);
}
}
}
self.goToNextStep = function () {
return $state.go(loanService.getNextStep());
};
function onFileAdded(item) {
self.allowedDocTypes = globalConfig.documentTypes.identityVerification;
self.uploadDocType = "DL";
}
function onRemoveItem(item) {
self.allowedDocTypes = null;
}
function onUploadSuccess(item) {
var deferred = $q.defer();
clientService.uploadCallback(item.callbackURL)
.then(function(response) {
self.working = false;
clientService.setClientStore(response);
self.client = response;
init();
config.scrollToTop($('h3').offset().top);
deferred.resolve(response);
}, function(error) {
init();
deferred.reject(error);
self.working = false;
});
return deferred.promise;
}
function generateUploadUrl(item) {
var deferred = $q.defer();
var form = {
documentName: item.file.name,
documentPurpose: "identityVerification",
documentType: self.uploadDocType
};
clientService.generateUploadUrl(form)
.then(function(response) {
deferred.resolve(response.data);
}, function(error) {
deferred.reject(error.data);
});
return deferred.promise;
}
}
})();