Address input fixes, region_id/host_id must not be null, address constraints changes

This commit is contained in:
Deon George
2021-06-25 16:42:12 +10:00
parent 848f41b382
commit 1f04f8374e
6 changed files with 77 additions and 13 deletions

View File

@@ -13,6 +13,8 @@ class DomainController extends Controller
public const NODE_RC = 1<<2; // Region
public const NODE_NC = 1<<3; // Host
public const NODE_HC = 1<<4; // Hub
public const NODE_PVT = 1<<5; // Pvt
public const NODE_DOWN = 1<<6; // Down
// http://ftsc.org/docs/frl-1002.001
public const NUMBER_MAX = 0x7fff;
@@ -87,7 +89,7 @@ class DomainController extends Controller
->get();
return $oo->map(function($item) {
return ['id'=>$item->host_id,'value'=>sprintf('%s %s',$item->ftn,$item->system->name)];
return ['id'=>$item->id,'value'=>sprintf('%s %s',$item->ftn,$item->system->name)];
});
}

View File

@@ -42,7 +42,7 @@ class SystemController extends Controller
// Check that the region doesnt already exist
$o = Address::where(function($query) use ($value) {
return $query->where('region_id',$value)
->whereNULL('host_id')
->where('host_id',0)
->where('node_id',0)
->where('point_id',0)
->where('role',DomainController::NODE_RC);
@@ -74,7 +74,7 @@ class SystemController extends Controller
case 'host':
$request->validate([
'region_id' => ['nullable',new TwoByteInteger],
'region_id' => ['required',new TwoByteInteger],
'host_id_new' => [
'required',
new TwoByteInteger,
@@ -82,7 +82,7 @@ class SystemController extends Controller
// Check that the region doesnt already exist
$o = Address::where(function($query) use ($value) {
return $query->where('region_id',$value)
->whereNULL('host_id')
->where('host_id',0)
->where('node_id',0)
->where('point_id',0)
->where('role',DomainController::NODE_RC);
@@ -121,7 +121,7 @@ class SystemController extends Controller
$oo = new Address;
$oo->zone_id = $request->post('zone_id');
$oo->region_id = ($x=$request->post('region_id')) == 'no' ? NULL : $x;
$oo->region_id = ($x=$request->post('region_id')) == 'no' ? 0 : $x;
$oo->host_id = $request->post('host_id_new');
$oo->node_id = $request->post('node_id_new');
$oo->point_id = 0;
@@ -133,8 +133,8 @@ class SystemController extends Controller
case 'node':
$request->validate([
'region_id' => ['nullable',new TwoByteInteger],
'host_id' => ['nullable',new TwoByteInteger],
'region_id' => ['required',new TwoByteInteger],
'host_id' => ['required',new TwoByteInteger],
'node_id' => [
'required',
new TwoByteInteger,
@@ -142,7 +142,7 @@ class SystemController extends Controller
// Check that the region doesnt already exist
$o = Address::where(function($query) use ($request,$value) {
return $query
->where('host_id',$request->post('host_id_new'))
->where('host_id',$request->post('host_id'))
->where('node_id',$value)
->where('point_id',0)
->where('role',DomainController::NODE_RC);
@@ -158,14 +158,16 @@ class SystemController extends Controller
$fail(sprintf('Point numbers must be between 0 and %d',DomainController::NUMBER_MAX));
}],
'hub' => 'required|boolean',
'hub_id' => 'nullable|exists:addresses,id',
]);
$oo = new Address;
$oo->zone_id = $request->post('zone_id');
$oo->region_id = ($x=$request->post('region_id')) == 'no' ? NULL : $x;
$oo->region_id = ($x=$request->post('region_id')) == 'no' ? 0 : $x;
$oo->host_id = $request->post('host_id');
$oo->node_id = $request->post('node_id');
$oo->point_id = $request->post('point_id');
$oo->hub_id = $request->post('hub_id');
$oo->role = (! $oo->point_id) && $request->post('hub') ? DomainController::NODE_HC : NULL;
$oo->active = TRUE;

View File

@@ -4,13 +4,14 @@ namespace App\Models;
use Exception;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use App\Http\Controllers\DomainController;
use App\Traits\ScopeActive;
class Address extends Model
{
use ScopeActive;
use ScopeActive,SoftDeletes;
/* SCOPES */
@@ -18,7 +19,7 @@ class Address extends Model
{
return $query
->orderBy('region_id')
->orderByRaw('host_id NULLS FIRST')
->orderBy('host_id')
->orderBy('node_id')
->orderBy('point_id');
}

View File

@@ -15,6 +15,7 @@ class Zone extends Model
public function scopeDomainZoneOrder($query)
{
return $query
->select('zones.*')
->join('domains',['domains.id'=>'zones.domain_id'])
->orderBy('domains.name')
->orderBy('zone_id');