mirror of
				https://github.com/firefly-iii/firefly-iii.git
				synced 2025-10-31 02:36:28 +00:00 
			
		
		
		
	Fix endpoints, validate dates.
This commit is contained in:
		| @@ -73,6 +73,6 @@ class BudgetController extends Controller | ||||
|             } | ||||
|         ); | ||||
| 
 | ||||
|         return response()->api($filtered); | ||||
|         return response()->api($filtered->toArray()); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -73,6 +73,6 @@ class CategoryController extends Controller | ||||
|             } | ||||
|         ); | ||||
| 
 | ||||
|         return response()->api($filtered); | ||||
|         return response()->api($filtered->toArray()); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -157,7 +157,15 @@ abstract class Controller extends BaseController | ||||
|                 $value = null; | ||||
|             } | ||||
|             if (null !== $value) { | ||||
|                 $bag->set($integer, (int) $value); | ||||
|                 $value = (int) $value; | ||||
|                 if ($value < 1) { | ||||
|                     $value = 1; | ||||
|                 } | ||||
|                 if ($value > 2 ** 16) { | ||||
|                     $value = 2 ** 16; | ||||
|                 } | ||||
| 
 | ||||
|                 $bag->set($integer, $value); | ||||
|             } | ||||
|             if (null === $value | ||||
|                 && 'limit' === $integer // @phpstan-ignore-line
 | ||||
|   | ||||
| @@ -58,6 +58,7 @@ class AutocompleteRequest extends FormRequest | ||||
|     public function rules(): array | ||||
|     { | ||||
|         return [ | ||||
|             'date' => 'date|after:1900-01-01|before:2099-12-31' | ||||
|         ]; | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -25,6 +25,7 @@ declare(strict_types=1); | ||||
| namespace FireflyIII\Api\V1\Requests\Data; | ||||
| 
 | ||||
| use FireflyIII\Exceptions\FireflyException; | ||||
| use FireflyIII\Exceptions\ValidationException; | ||||
| use FireflyIII\Support\Request\ChecksLogin; | ||||
| use FireflyIII\Support\Request\ConvertsDataTypes; | ||||
| use Illuminate\Foundation\Http\FormRequest; | ||||
| @@ -49,7 +50,7 @@ class DateRequest extends FormRequest | ||||
|         $start->startOfDay(); | ||||
|         $end->endOfDay(); | ||||
|         if ($start->diffInYears($end, true) > 5) { | ||||
|             throw new FireflyException('Date range out of range.'); | ||||
|             throw new ValidationException('Date range out of range.'); | ||||
|         } | ||||
| 
 | ||||
|         return [ | ||||
|   | ||||
| @@ -57,6 +57,10 @@ class CronRequest extends FormRequest | ||||
|         if ($this->has('date')) { | ||||
|             $data['date'] = $this->getCarbonDate('date'); | ||||
|         } | ||||
|         // catch NULL.
 | ||||
|         if(null === $data['date']) { | ||||
|             $data['date'] = today(config('app.timezone')); | ||||
|         } | ||||
| 
 | ||||
|         return $data; | ||||
|     } | ||||
|   | ||||
| @@ -133,6 +133,13 @@ class Handler extends ExceptionHandler | ||||
| 
 | ||||
|             return response()->json(['message' => $e->getMessage(), 'exception' => 'BadHttpHeaderException'], $e->statusCode); | ||||
|         } | ||||
|         if($e instanceof ValidationException && $expectsJson) { | ||||
|             $errorCode = 422; | ||||
|             return response()->json( | ||||
|                 ['message' => sprintf('Validation exception: %s', $e->getMessage()), 'errors' => ['date' => 'Date is invalid']], | ||||
|                 $errorCode | ||||
|             ); | ||||
|         } | ||||
| 
 | ||||
|         if ($expectsJson) { | ||||
|             $errorCode = 500; | ||||
|   | ||||
| @@ -419,7 +419,9 @@ class CreateRecurringTransactions implements ShouldQueue | ||||
|         /** @var RecurrenceTransaction $transaction */ | ||||
|         foreach ($transactions as $index => $transaction) { | ||||
|             $single   = [ | ||||
|                 'type'                  => null === $transaction->transactionType->type ? strtolower($recurrence->transactionType->type) : strtolower($transaction->transactionType->type), | ||||
|                 'type'                  => null === $transaction?->transactionType?->type ? | ||||
|                     strtolower($recurrence->transactionType->type) : | ||||
|                     strtolower($transaction->transactionType->type), | ||||
|                 'date'                  => $date, | ||||
|                 'user'                  => $recurrence->user_id, | ||||
|                 'currency_id'           => $transaction->transaction_currency_id, | ||||
|   | ||||
		Reference in New Issue
	
	Block a user