52 lines
1.9 KiB
PHP
52 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Resources\SuperAdmin;
|
|
|
|
use App\Http\Resources\CityMunicipalityResource;
|
|
use App\Models\User;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
class SuperAdminTenantResource extends JsonResource
|
|
{
|
|
public function toArray(Request $request): array
|
|
{
|
|
$boundaryPoints = null;
|
|
if ($this->boundary_polygon) {
|
|
$rings = $this->boundary_polygon->getGeometries();
|
|
$ring = $rings->first();
|
|
if ($ring) {
|
|
$boundaryPoints = $ring->getGeometries()
|
|
->map(fn ($p) => ['lat' => $p->latitude, 'lng' => $p->longitude])
|
|
->all();
|
|
}
|
|
}
|
|
|
|
$adminUser = $this->relationLoaded('users')
|
|
? $this->users->first(fn ($u) => $u->role === User::ROLE_ADMIN)
|
|
: $this->users()->where('role', User::ROLE_ADMIN)->first();
|
|
|
|
return [
|
|
'id' => $this->uuid,
|
|
'db_id' => $this->id,
|
|
'name' => $this->name,
|
|
'code' => $this->code,
|
|
'short_name' => $this->short_name,
|
|
'city_municipality_id' => $this->city_municipality_id,
|
|
'boundary_polygon' => $boundaryPoints,
|
|
'theme_color' => $this->theme_color,
|
|
'logo_path' => $this->logo_path,
|
|
'contact_email' => $this->contact_email,
|
|
'contact_phone' => $this->contact_phone,
|
|
'status' => $this->status,
|
|
'timezone' => $this->timezone,
|
|
'users_count' => $this->users_count ?? 0,
|
|
'households_count' => $this->households_count ?? 0,
|
|
'trucks_count' => $this->trucks_count ?? 0,
|
|
'admin_email' => $adminUser?->email,
|
|
'city_municipality' => CityMunicipalityResource::make($this->whenLoaded('cityMunicipality')),
|
|
'created_at' => $this->created_at?->toIso8601String(),
|
|
];
|
|
}
|
|
}
|