{"size": 1135, "ext": "js", "max_stars_repo_path": "app/controllers/register-flow/owner-customer-bank-account.js", "max_stars_repo_name": "dk-dev/balanced-dashboard", "max_stars_repo_stars_event_min_datetime": "2015-01-02T13:41:19.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-25T02:01:57.000Z", "max_issues_repo_path": "app/controllers/register-flow/owner-customer-bank-account.js", "max_issues_repo_name": "dk-dev/balanced-dashboard", "max_issues_repo_issues_event_min_datetime": "2015-01-04T06:27:00.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T02:48:33.000Z", "max_forks_repo_path": "app/controllers/register-flow/owner-customer-bank-account.js", "max_forks_repo_name": "dk-dev/balanced-dashboard", "max_forks_repo_forks_event_min_datetime": "2015-01-02T16:00:49.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-09T23:19:08.000Z"}
{"max_stars_count": 169, "max_issues_count": 36, "max_forks_count": 80, "avg_line_length": 26.3953488372, "max_line_length": 73, "alphanum_fraction": 0.7339207048}
import Ember from "ember";
import BankAccount from "balanced-dashboard/models/bank-account";
import Verification from "balanced-dashboard/models/verification";

var OwnerCustomerBankAccountController = Ember.Controller.extend({
	needs: ["marketplace"],
	find: function(bankAccountHref) {
		return BankAccount.find(bankAccountHref);
	},

	link: function(marketplace, bankAccount) {
		var customerLink = marketplace.get("links.owner_customer");
		bankAccount.set("links.customer", customerLink);
		return bankAccount.save();
	},

	verify: function(bankAccount) {
		return Verification
			.create({
				uri: bankAccount.get("bank_account_verifications_uri")
			})
			.save();
	},

	linkAndVerify: function(marketplace, bankAccountHref) {
		var self = this;
		return this
			.find(bankAccountHref)
			.then(function(bankAccount) {
				return self.link(marketplace, bankAccount);
			})
			.then(function(bankAccount) {
				return self.verify(bankAccount);
			})
			.then(function(a) {
				self.get("controllers.marketplace").updateBankAccountNotifications();
				return a;
			});
	},
});

export default OwnerCustomerBankAccountController;
