diff --git a/app/Api/V1/Controllers/AccountController.php b/app/Api/V1/Controllers/AccountController.php index 81adb7f2bf..861d3e4aff 100644 --- a/app/Api/V1/Controllers/AccountController.php +++ b/app/Api/V1/Controllers/AccountController.php @@ -169,6 +169,8 @@ class AccountController extends Controller } /** + * Update account. + * * @param AccountRequest $request * @param Account $account * diff --git a/app/Api/V1/Controllers/TransactionController.php b/app/Api/V1/Controllers/TransactionController.php index 3f5b4220f0..9490a190b1 100644 --- a/app/Api/V1/Controllers/TransactionController.php +++ b/app/Api/V1/Controllers/TransactionController.php @@ -80,7 +80,7 @@ class TransactionController extends Controller public function delete(Transaction $transaction) { $journal = $transaction->transactionJournal; - $this->repository->delete($journal); + $this->repository->destroy($journal); return response()->json([], 204); } diff --git a/app/Api/V1/Requests/AccountRequest.php b/app/Api/V1/Requests/AccountRequest.php index d1f9a468ad..649d21c29c 100644 --- a/app/Api/V1/Requests/AccountRequest.php +++ b/app/Api/V1/Requests/AccountRequest.php @@ -47,6 +47,7 @@ class AccountRequest extends Request 'name' => $this->string('name'), 'active' => $this->boolean('active'), 'accountType' => $this->string('type'), + 'account_type_id' => null, 'currency_id' => $this->integer('currency_id'), 'currency_code' => $this->string('currency_code'), 'virtualBalance' => $this->string('virtual_balance'), @@ -97,6 +98,7 @@ class AccountRequest extends Request $account = $this->route()->parameter('account'); $rules['name'] .= ':' . $account->id; $rules['account_number'] .= ':' . $account->id; + $rules['type'] = 'in:' . $types; break; } diff --git a/app/Api/V1/Requests/BillRequest.php b/app/Api/V1/Requests/BillRequest.php index d39c08edda..881364a3e9 100644 --- a/app/Api/V1/Requests/BillRequest.php +++ b/app/Api/V1/Requests/BillRequest.php @@ -108,8 +108,8 @@ class BillRequest extends Request $validator->after( function (Validator $validator) { $data = $validator->getData(); - $min = floatval($data['amount_min']); - $max = floatval($data['amount_max']); + $min = floatval($data['amount_min'] ?? 0); + $max = floatval($data['amount_max'] ?? 0); if ($min > $max) { $validator->errors()->add('amount_min', trans('validation.amount_min_over_max')); } diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index ba0f1a30d3..2dc4e0320c 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -77,8 +77,9 @@ class Handler extends ExceptionHandler return response()->json(['message' => 'Unauthenticated', 'exception' => 'AuthenticationException'], 401); } + if ($request->expectsJson()) { - $isDebug = env('APP_DEBUG', false); + $isDebug = config('app.debug', false); if ($isDebug) { return response()->json( [ diff --git a/app/Services/Internal/Support/TransactionServiceTrait.php b/app/Services/Internal/Support/TransactionServiceTrait.php index d87f3731d2..7b029997bb 100644 --- a/app/Services/Internal/Support/TransactionServiceTrait.php +++ b/app/Services/Internal/Support/TransactionServiceTrait.php @@ -216,6 +216,7 @@ trait TransactionServiceTrait protected function setBudget(Transaction $transaction, ?Budget $budget): void { if (is_null($budget)) { + $transaction->budgets()->sync([]); return; } $transaction->budgets()->sync([$budget->id]); @@ -231,6 +232,7 @@ trait TransactionServiceTrait protected function setCategory(Transaction $transaction, ?Category $category): void { if (is_null($category)) { + $transaction->categories()->sync([]); return; } $transaction->categories()->sync([$category->id]); diff --git a/tests/Api/V1/Controllers/TransactionControllerTest.php b/tests/Api/V1/Controllers/TransactionControllerTest.php index 5e87865985..9887ef65ff 100644 --- a/tests/Api/V1/Controllers/TransactionControllerTest.php +++ b/tests/Api/V1/Controllers/TransactionControllerTest.php @@ -64,7 +64,7 @@ class TransactionControllerTest extends TestCase // mock calls: $repository->shouldReceive('setUser')->once(); - $repository->shouldReceive('delete')->once()->andReturn(true); + $repository->shouldReceive('destroy')->once()->andReturn(true); // get account: $transaction = $this->user()->transactions()->first();