From a5520d45e745bb3e63e47c343559cdc1ef289752 Mon Sep 17 00:00:00 2001 From: James Cole Date: Fri, 21 Dec 2018 15:42:57 +0100 Subject: [PATCH] Store booleans correctly. --- app/Api/V1/Controllers/CurrencyController.php | 1 + app/Api/V1/Requests/BillRequest.php | 8 ++++++-- app/Api/V1/Requests/BudgetRequest.php | 7 ++++++- app/Api/V1/Requests/TransactionRequest.php | 2 +- app/Api/V1/Requests/UserRequest.php | 6 +++++- app/Factory/BillFactory.php | 2 +- 6 files changed, 20 insertions(+), 6 deletions(-) diff --git a/app/Api/V1/Controllers/CurrencyController.php b/app/Api/V1/Controllers/CurrencyController.php index 672dff7746..45d82f6cd2 100644 --- a/app/Api/V1/Controllers/CurrencyController.php +++ b/app/Api/V1/Controllers/CurrencyController.php @@ -276,6 +276,7 @@ class CurrencyController extends Controller $pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; $unfiltered = $repository->getAllBudgetLimits($this->parameters->get('start'), $this->parameters->get('end')); + // TODO replace this // filter budget limits on currency ID $collection = $unfiltered->filter( function (BudgetLimit $budgetLimit) use ($currency) { diff --git a/app/Api/V1/Requests/BillRequest.php b/app/Api/V1/Requests/BillRequest.php index 80e4d66ca4..d65b1a9861 100644 --- a/app/Api/V1/Requests/BillRequest.php +++ b/app/Api/V1/Requests/BillRequest.php @@ -51,6 +51,11 @@ class BillRequest extends Request */ public function getAll(): array { + $active = true; + if(null !== $this->get('active')) { + $active = $this->boolean('active'); + } + $data = [ 'name' => $this->string('name'), 'amount_min' => $this->string('amount_min'), @@ -60,8 +65,7 @@ class BillRequest extends Request 'date' => $this->date('date'), 'repeat_freq' => $this->string('repeat_freq'), 'skip' => $this->integer('skip'), - 'automatch' => $this->boolean('automatch'), - 'active' => $this->boolean('active'), + 'active' => $active, 'notes' => $this->string('notes'), ]; diff --git a/app/Api/V1/Requests/BudgetRequest.php b/app/Api/V1/Requests/BudgetRequest.php index 9e48acccd2..2a42362e7a 100644 --- a/app/Api/V1/Requests/BudgetRequest.php +++ b/app/Api/V1/Requests/BudgetRequest.php @@ -49,9 +49,14 @@ class BudgetRequest extends Request */ public function getAll(): array { + $active = true; + if (null !== $this->get('active')) { + $active = $this->boolean('active'); + } + return [ 'name' => $this->string('name'), - 'active' => $this->boolean('active'), + 'active' => $active, 'order' => 0, ]; } diff --git a/app/Api/V1/Requests/TransactionRequest.php b/app/Api/V1/Requests/TransactionRequest.php index 373fb298c8..9c6820dad7 100644 --- a/app/Api/V1/Requests/TransactionRequest.php +++ b/app/Api/V1/Requests/TransactionRequest.php @@ -211,7 +211,7 @@ class TransactionRequest extends Request 'source_name' => isset($transaction['source_name']) ? (string)$transaction['source_name'] : null, 'destination_id' => isset($transaction['destination_id']) ? (int)$transaction['destination_id'] : null, 'destination_name' => isset($transaction['destination_name']) ? (string)$transaction['destination_name'] : null, - 'reconciled' => $transaction['reconciled'] ?? false, + 'reconciled' => $this->convertBoolean((string)($transaction['reconciled'] ?? 'false')), 'identifier' => $index, ]; } diff --git a/app/Api/V1/Requests/UserRequest.php b/app/Api/V1/Requests/UserRequest.php index bd0afa207f..71100881eb 100644 --- a/app/Api/V1/Requests/UserRequest.php +++ b/app/Api/V1/Requests/UserRequest.php @@ -65,9 +65,13 @@ class UserRequest extends Request */ public function getAll(): array { + $blocked = false; + if (null === $this->get('blocked')) { + $blocked = $this->boolean('blocked'); + } $data = [ 'email' => $this->string('email'), - 'blocked' => $this->boolean('blocked'), + 'blocked' => $blocked, 'blocked_code' => $this->string('blocked_code'), 'role' => $this->string('role'), ]; diff --git a/app/Factory/BillFactory.php b/app/Factory/BillFactory.php index f29e7ae04a..797d9a14cd 100644 --- a/app/Factory/BillFactory.php +++ b/app/Factory/BillFactory.php @@ -80,7 +80,7 @@ class BillFactory 'date' => $data['date'], 'repeat_freq' => $data['repeat_freq'], 'skip' => $data['skip'], - 'automatch' => $data['automatch'] ?? true, + 'automatch' => true, 'active' => $data['active'] ?? true, ] );