mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-04 03:43:07 +00:00
Catch errors in transaction API.
This commit is contained in:
@@ -119,6 +119,9 @@ class GroupUpdateService
|
||||
if (empty($data)) {
|
||||
return;
|
||||
}
|
||||
if (1 === count($data) && array_key_exists('transaction_journal_id', $data)) {
|
||||
return;
|
||||
}
|
||||
/** @var JournalUpdateService $updateService */
|
||||
$updateService = app(JournalUpdateService::class);
|
||||
$updateService->setTransactionGroup($transactionGroup);
|
||||
|
@@ -89,27 +89,30 @@ trait GroupValidation
|
||||
protected function preventNoAccountInfo(Validator $validator): void
|
||||
{
|
||||
$transactions = $this->getTransactionsArray($validator);
|
||||
$hasAccountInfo = false;
|
||||
$keys = ['source_id', 'destination_id', 'source_name', 'destination_name', 'source_iban', 'destination_iban', 'source_number',
|
||||
'destination_number'];
|
||||
$keys = ['source_id', 'destination_id', 'source_name', 'destination_name', 'source_iban', 'destination_iban', 'source_number', 'destination_number'];
|
||||
/** @var array $transaction */
|
||||
foreach ($transactions as $transaction) {
|
||||
foreach ($transactions as $index => $transaction) {
|
||||
$hasAccountInfo = false;
|
||||
$hasJournalId = array_key_exists('transaction_journal_id', $transaction);
|
||||
foreach ($keys as $key) {
|
||||
if (array_key_exists($key, $transaction) && '' !== (string) $transaction[$key]) {
|
||||
$hasAccountInfo = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(false === $hasAccountInfo) {
|
||||
// set errors:
|
||||
if (false === $hasAccountInfo && !$hasJournalId) {
|
||||
$validator->errors()->add(
|
||||
'transactions.0.source_id', (string)trans('validation.generic_no_source')
|
||||
sprintf('transactions.%d.source_id', $index), (string) trans('validation.generic_no_source')
|
||||
);
|
||||
$validator->errors()->add(
|
||||
'transactions.0.destination_id', (string)trans('validation.generic_no_destination')
|
||||
sprintf('transactions.%d.destination_id', $index), (string) trans('validation.generic_no_destination')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// only an issue if there is no transaction_journal_id
|
||||
}
|
||||
|
||||
/**
|
||||
* This method validates if the user has submitted transaction journal ID's for each array they submit, if they've submitted more than 1 transaction
|
||||
* journal. This check is necessary because Firefly III isn't able to distinguish between journals without the ID.
|
||||
|
Reference in New Issue
Block a user