mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Update API endpoints.
This commit is contained in:
@@ -26,6 +26,7 @@ namespace FireflyIII\Validation\Api\Data\Bulk;
|
||||
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use Illuminate\Validation\Validator;
|
||||
use JsonException;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -34,30 +35,32 @@ trait ValidatesBulkTransactionQuery
|
||||
{
|
||||
/**
|
||||
* @param Validator $validator
|
||||
*
|
||||
* @throws JsonException
|
||||
*/
|
||||
protected function validateTransactionQuery(Validator $validator): void
|
||||
{
|
||||
$data = $validator->getData();
|
||||
// assumption is all validation has already taken place
|
||||
// and the query key exists.
|
||||
$json = json_decode($data['query'], true, 8);
|
||||
$json = json_decode($data['query'], true, 8, JSON_THROW_ON_ERROR);
|
||||
|
||||
if (array_key_exists('source_account_id', $json['where'])
|
||||
&& array_key_exists('destination_account_id', $json['update'])
|
||||
if (array_key_exists('account_id', $json['where'])
|
||||
&& array_key_exists('account_id', $json['update'])
|
||||
) {
|
||||
// find both accounts
|
||||
// must be same type.
|
||||
// already validated: belongs to this user.
|
||||
$repository = app(AccountRepositoryInterface::class);
|
||||
$source = $repository->find((int)$json['where']['source_account_id']);
|
||||
$dest = $repository->find((int)$json['update']['destination_account_id']);
|
||||
$source = $repository->find((int)$json['where']['account_id']);
|
||||
$dest = $repository->find((int)$json['update']['account_id']);
|
||||
if (null === $source) {
|
||||
$validator->errors()->add('query', sprintf((string)trans('validation.invalid_query_data'), 'where', 'source_account_id'));
|
||||
$validator->errors()->add('query', sprintf((string)trans('validation.invalid_query_data'), 'where', 'account_id'));
|
||||
|
||||
return;
|
||||
}
|
||||
if (null === $dest) {
|
||||
$validator->errors()->add('query', sprintf((string)trans('validation.invalid_query_data'), 'update', 'destination_account_id'));
|
||||
$validator->errors()->add('query', sprintf((string)trans('validation.invalid_query_data'), 'update', 'account_id'));
|
||||
|
||||
return;
|
||||
}
|
||||
|
Reference in New Issue
Block a user