Factory seems to work for update and create

This commit is contained in:
James Cole
2018-02-21 21:06:59 +01:00
parent 085eb650e7
commit 35d0bd1985
5 changed files with 172 additions and 95 deletions

View File

@@ -25,6 +25,7 @@ namespace FireflyIII\Repositories\Account;
use Carbon\Carbon;
use DB;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Factory\AccountFactory;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountMeta;
use FireflyIII\Models\AccountType;
@@ -241,32 +242,15 @@ class AccountRepository implements AccountRepositoryInterface
* @param array $data
*
* @return Account
*
* @throws FireflyException
*/
public function store(array $data): Account
{
$newAccount = $this->storeAccount($data);
$this->updateMetadata($newAccount, $data);
/** @var AccountFactory $factory */
$factory = app(AccountFactory::class);
$factory->setUser($this->user);
$account = $factory->create($data);
if ($this->validOpeningBalanceData($data)) {
$this->updateInitialBalance($newAccount, $data);
// update note:
if (isset($data['notes'])) {
$this->updateNote($newAccount, $data['notes']);
}
return $newAccount;
}
$this->deleteInitialBalance($newAccount);
// update note:
if (isset($data['notes'])) {
$this->updateNote($newAccount, $data['notes']);
}
return $newAccount;
return $account;
}
/**