Skip to content

Commit

Permalink
Clean up StoreServerRequest a little
Browse files Browse the repository at this point in the history
  • Loading branch information
ericwang401 committed Jan 26, 2024
1 parent e3836ea commit 1683a96
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions app/Http/Requests/Admin/Servers/StoreServerRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,19 @@

namespace Convoy\Http\Requests\Admin\Servers;

use Convoy\Http\Requests\BaseApiRequest;
use Convoy\Models\Address;
use Convoy\Models\Node;
use Convoy\Models\Server;
use Convoy\Models\Address;
use Convoy\Rules\EnglishKeyboardCharacters;
use Convoy\Rules\Password;
use Illuminate\Validation\Validator;
use Convoy\Http\Requests\BaseApiRequest;
use Convoy\Rules\EnglishKeyboardCharacters;

/**
* @property mixed $type
*/
class StoreServerRequest extends BaseApiRequest
{
/**
* Get the validation rules that apply to the request.
*
* @return array<string, mixed>
*/
public function rules(): array
{
$rules = Server::getRules();
Expand Down Expand Up @@ -47,8 +42,7 @@ public function rules(): array
];
}

// check that all of the address_ids server_id is null
public function withValidator(Validator $validator)
public function withValidator(Validator $validator): void
{
$validator->after(function ($validator) {
$addressIds = $this->input('limits.address_ids');
Expand Down Expand Up @@ -77,11 +71,15 @@ public function withValidator(Validator $validator)
$disk = intval($this->input('limits.disk'));

if ($memory > $nodeMemoryLimit || $memory < 0) {
$validator->errors()->add('limits.memory', 'The memory value exceeds the node\'s limit.');
$validator->errors()->add(
'limits.memory', 'The memory value exceeds the node\'s limit.',
);
}

if ($disk > $nodeDiskLimit || $disk < 0) {
$validator->errors()->add('limits.disk', 'The disk value exceeds the node\'s limit.');
$validator->errors()->add(
'limits.disk', 'The disk value exceeds the node\'s limit.',
);
}
});
}
Expand Down

0 comments on commit 1683a96

Please sign in to comment.