diff --git a/app/Http/Controllers/APIS/CustomerApi/TelemetryController.php b/app/Http/Controllers/APIS/CustomerApi/TelemetryController.php index 3a7acc8..04a9b9a 100644 --- a/app/Http/Controllers/APIS/CustomerApi/TelemetryController.php +++ b/app/Http/Controllers/APIS/CustomerApi/TelemetryController.php @@ -1583,4 +1583,62 @@ class TelemetryController extends Controller } } + public function getUserAssets(){ + $token = readHeaderToken(); + $userId = $token['sub']; + + $userAssets = UserAssetLink::with('asset:id,name') + ->where(['user_id' => $userId, 'active' => 1]) + ->get() + ->map(function($link) { + return [ + 'id' => $link->asset->id, + 'name' => $link->asset->name + ]; + }); + return response()->json($userAssets); + } + + public function getUserDeviceByAsset($assetId){ + $token = readHeaderToken(); + $userDevices = UserAssetLink::with('asset.devices') + ->where('user_id', $token['sub']) + ->where('asset_id', $assetId) + ->get() + ->pluck('asset.devices') + ->flatten() + ->select('id','name'); + + return response()->json($userDevices); + } + + public function getUserAlarms(Request $request){ + try { + $token = readHeaderToken(); + $userId = $token['sub']; + + if($request->assetIds){ + $getDeviceByAsset = Device::whereIn('asset_id', $request->assetIds)->pluck('id')->toArray(); + }else{ + $getDeviceByAsset = $request->deviceIds; + } + + $data = [ + 'statusList' => $request->statusList ?? ['ACTIVE'], + 'severityList' => $request->severityList, + 'startTs' => $request->startTs, + 'endTs' => $request->endTs, + 'deviceIds' => $getDeviceByAsset, + ]; + + $allDevices = Device::pluck('id')->toArray(); + + $alarms = $this->customerInfoService->fetchDeviceAlarms($allDevices, $data); + + return response()->json(['success' => true, 'data' => $alarms]); + } catch(Exception $e){ + return response()->json(['success' => false, 'message' => $e->getMessage()], 500); + } + } + } diff --git a/routes/customer_api.php b/routes/customer_api.php index de1d594..9c7ea21 100644 --- a/routes/customer_api.php +++ b/routes/customer_api.php @@ -58,4 +58,9 @@ Route::middleware(['customerApiBasicAuth'])->group(function () { Route::get('/get-trends/{deviceId}', [TelemetryController::class, 'getTrends']); Route::get('/get-cylinder-specific-indicators/{deviceId}', [TelemetryController::class, 'getCylinderSpecificIndicators']); Route::get('/get-peak-pressure/{deviceId}', [TelemetryController::class, 'getPeakPressure']); + + // Alarms + Route::post('/get-user-alarms', [TelemetryController::class, 'getUserAlarms']); + Route::get('/get-user-device-by-asset/{assetId}', [TelemetryController::class, 'getUserDeviceByAsset']); + Route::get('/get-user-assets', [TelemetryController::class, 'getUserAssets']); });