. */ declare(strict_types=1); namespace FireflyIII\Api\V1\Requests; use FireflyIII\Rules\IsAssetAccountId; use FireflyIII\Rules\LessThanPiggyTarget; use FireflyIII\Support\Request\ChecksLogin; use FireflyIII\Support\Request\ConvertsDataTypes; use Illuminate\Foundation\Http\FormRequest; /** * Class PiggyBankUpdateRequest * * @codeCoverageIgnore */ class PiggyBankUpdateRequest extends FormRequest { use ConvertsDataTypes, ChecksLogin; /** * Get all data from the request. * * @return array */ public function getAll(): array { // if the value isn't present, dont return it at all. // TODO this should be the way to collect fields for all API things. // TODO make sure piggy bank uses 'start_date' etc. until right up to DB update. // TODO can we configure this and return it from config? // TODO this is the way. $fields = [ 'name' => ['name', 'string'], 'account_id' => ['account_id', 'integer'], 'targetamount' => ['target_amount', 'string'], 'current_amount' => ['current_amount', 'string'], 'startdate' => ['start_date', 'date'], 'targetdate' => ['target_date', 'string'], 'notes' => ['notes', 'nlString'], 'order' => ['order', 'integer'], 'object_group' => ['object_group', 'string'], 'object_group_id' => ['object_group_id', 'integer'], ]; return $this->getAllData($fields); } /** * The rules that the incoming request must be matched against. * * @return array */ public function rules(): array { $piggyBank = $this->route()->parameter('piggyBank'); return [ 'name' => 'between:1,255|uniquePiggyBankForUser:' . $piggyBank->id, 'current_amount' => ['numeric', 'gte:0', new LessThanPiggyTarget], 'target_amount' => 'numeric|gt:0', 'start_date' => 'date|nullable', 'target_date' => 'date|nullable|after:start_date', 'notes' => 'max:65000', 'account_id' => ['belongsToUser:accounts', new IsAssetAccountId], ]; } }