mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
No longer have to submit mandatory fields to account end point. Just submit the field you wish to update, the rest will be untouched.
This commit is contained in:
@@ -23,10 +23,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Internal\Update;
|
||||
|
||||
use FireflyIII\Factory\TransactionCurrencyFactory;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Models\TransactionCurrency;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Services\Internal\Support\AccountServiceTrait;
|
||||
use FireflyIII\User;
|
||||
@@ -39,13 +37,13 @@ class AccountUpdateService
|
||||
{
|
||||
use AccountServiceTrait;
|
||||
|
||||
/** @var array */
|
||||
private $canHaveVirtual;
|
||||
/** @var AccountRepositoryInterface */
|
||||
protected $accountRepository;
|
||||
|
||||
/** @var array */
|
||||
private $canHaveVirtual;
|
||||
/** @var User */
|
||||
private $user;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
@@ -73,22 +71,35 @@ class AccountUpdateService
|
||||
$this->user = $account->user;
|
||||
|
||||
// update the account itself:
|
||||
$account->name = $data['name'];
|
||||
$account->active = $data['active'];
|
||||
$account->virtual_balance = '' === trim($data['virtual_balance']) ? '0' : $data['virtual_balance'];
|
||||
$account->iban = $data['iban'];
|
||||
|
||||
$account->name = $data['name'] ?? $account->name;
|
||||
$account->active = $data['active'] ?? $account->active;
|
||||
if (null !== $data['virtual_balance']) {
|
||||
$account->virtual_balance = '' === trim($data['virtual_balance']) ? '0' : $data['virtual_balance'];
|
||||
}
|
||||
$account->iban = $data['iban'] ?? $account->iban;
|
||||
$account->save();
|
||||
|
||||
if (isset($data['currency_id']) && 0 === $data['currency_id']) {
|
||||
|
||||
if (isset($data['currency_id']) && null !== $data['currency_id'] && 0 === $data['currency_id']) {
|
||||
unset($data['currency_id']);
|
||||
}
|
||||
|
||||
|
||||
// find currency, or use default currency instead.
|
||||
$currency = $this->getCurrency((int)($data['currency_id'] ?? null), (string)($data['currency_code'] ?? null));
|
||||
unset($data['currency_code']);
|
||||
$data['currency_id'] = $currency->id;
|
||||
if (null !== $data['currency_id'] || null !== $data['currency_code']) {
|
||||
$currency = $this->getCurrency((int)($data['currency_id'] ?? null), (string)($data['currency_code'] ?? null));
|
||||
unset($data['currency_code']);
|
||||
$data['currency_id'] = $currency->id;
|
||||
}
|
||||
|
||||
if (null === $data['currency_id']) {
|
||||
$data['currency_id'] = $this->accountRepository->getMetaValue($account, 'currency_id');
|
||||
}
|
||||
|
||||
if (null === $data['account_role']) {
|
||||
$data['account_role'] = $this->accountRepository->getMetaValue($account, 'account_role');
|
||||
}
|
||||
// update all meta data:
|
||||
$this->updateMetaData($account, $data);
|
||||
|
||||
@@ -108,7 +119,7 @@ class AccountUpdateService
|
||||
}
|
||||
|
||||
// update note:
|
||||
if (isset($data['notes'])) {
|
||||
if (isset($data['notes']) && null !== $data['notes']) {
|
||||
$this->updateNote($account, (string)$data['notes']);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user