Active devices for admin
This commit is contained in:
@@ -11,6 +11,7 @@ use App\Services\CustomerInfoService;
|
||||
use Illuminate\Container\Attributes\Log;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use App\Models\UserAssetLink;
|
||||
|
||||
class AdminDashboardController extends Controller
|
||||
{
|
||||
@@ -106,4 +107,43 @@ class AdminDashboardController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
public function getAdminActiveDevicesList(){
|
||||
try {
|
||||
// $token = readHeaderToken();
|
||||
$devices = UserAssetLink::with('asset.devices')
|
||||
->where(['active' => 1])
|
||||
->get()
|
||||
->pluck('asset.devices')
|
||||
->flatten()
|
||||
->unique('id');
|
||||
|
||||
$deviceIds = $devices->pluck('id')->toArray();
|
||||
$activeDevices = $this->customerInfoService->getActiveDevicesList($deviceIds);
|
||||
$deviceCount = $this->customerInfoService->getDevicesCount($deviceIds);
|
||||
|
||||
$activeDeviceIds = collect($activeDevices['activeDevices'])->pluck('entityId')->pluck('id')->toArray();
|
||||
|
||||
$getDevices = Device::with('asset')->whereIn('id', $activeDeviceIds)->get(['id', 'name', 'label', 'asset_id', 'customer_id', 'type', 'created_at']);
|
||||
|
||||
$liveDevices = $getDevices->map(function($device){
|
||||
|
||||
$assetName = Asset::where('id', $device->asset_id)->first()->name;
|
||||
|
||||
return [
|
||||
'deviceId' => $device->id,
|
||||
'assetName' => $assetName,
|
||||
'deviceName' => $device->label,
|
||||
'deviceType' => $device->type,
|
||||
'deviceCustomer' => $device->customer->title,
|
||||
'deviceCreatedAt' => $device->created_at ?? 'N/A'
|
||||
];
|
||||
});
|
||||
|
||||
|
||||
return response()->json(['success' => true, 'totalDevices' => $deviceCount['totalDevices'] ?? 0, 'activeDevices' => $deviceCount['activeDevices'] ?? 0, 'data' => $liveDevices]);
|
||||
} catch(Exception $e){
|
||||
return response()->json(['success' => false, 'message' => $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ Route::get('/adminapi', function () {
|
||||
//******************************************************* Admin Assest API ********************************************************
|
||||
Route::post('/admin-login', [LoginController::class, 'adminLogin'])->name('admin.login');
|
||||
Route::get('/admin-dashboard', [AdminDashboardController::class, 'adminDashboard'])->name('admin.dashboard');
|
||||
Route::get('/get-admin-active-devices-list', [AdminDashboardController::class, 'getAdminActiveDevicesList']);
|
||||
|
||||
Route::post('/asset', [AssetadmintController::class, 'storeAssest'])->name('assest.create');
|
||||
Route::get('/assets-list', [AssetadmintController::class, 'listAssest'])->name('assest.list');
|
||||
|
||||
Reference in New Issue
Block a user