From cd62fae130513842612d53ff8633dc3b815d0500 Mon Sep 17 00:00:00 2001 From: Nikhil Kadam Date: Mon, 5 May 2025 13:40:56 +0530 Subject: [PATCH] Fixing routing issues --- .../APIS/CustomerApi/TelemetryController.php | 2 +- app/Services/AdminService.php | 29 ++++++++++--------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/app/Http/Controllers/APIS/CustomerApi/TelemetryController.php b/app/Http/Controllers/APIS/CustomerApi/TelemetryController.php index d837884..169214b 100644 --- a/app/Http/Controllers/APIS/CustomerApi/TelemetryController.php +++ b/app/Http/Controllers/APIS/CustomerApi/TelemetryController.php @@ -961,7 +961,7 @@ class TelemetryController extends Controller // Retrieve devices of user $assetDeviceListing = UserAssetLink::with('asset.devices') - ->where('user_id', $token['sub']) + ->where(['user_id' => $token['sub'], 'active' => 1]) ->get(); $formattedData = $assetDeviceListing->map(function ($link) { diff --git a/app/Services/AdminService.php b/app/Services/AdminService.php index b2f7f81..5a9a804 100644 --- a/app/Services/AdminService.php +++ b/app/Services/AdminService.php @@ -92,7 +92,7 @@ class AdminService // throw new Exception('Failed to create asset: ' . $response->body()); // } // } - + // public function createAsset(array $data) // { // $token = $this->getToken(); @@ -150,7 +150,7 @@ class AdminService 'Accept' => 'application/json', 'Content-Type' => 'application/json', ])->withBody(json_encode($payload), 'application/json') - ->post("{$this->baseUrl}/api/asset"); + ->post("{$this->baseUrl}api/asset"); if ($response->successful()) { return $response->json(); @@ -206,7 +206,7 @@ class AdminService - $url = "{$this->baseUrl}/api/customer"; + $url = "{$this->baseUrl}api/customer"; $method = 'post'; // Send request $response = Http::withHeaders([ @@ -267,7 +267,7 @@ class AdminService 'Content-Type' => 'application/json', ]) ->timeout(30) - ->post("{$this->baseUrl}/api/user", $payload); + ->post("{$this->baseUrl}api/user", $payload); if ($response->successful()) { return $response->json(); @@ -310,7 +310,7 @@ class AdminService 'Authorization' => "Bearer $token", 'Accept' => 'application/json', 'Content-Type' => 'application/json', - ])->delete("{$this->baseUrl}/api/asset/{$assetId}"); + ])->delete("{$this->baseUrl}api/asset/{$assetId}"); Log::info('Asset Deletion Response: ' . $response); @@ -360,7 +360,7 @@ class AdminService 'Authorization' => "Bearer $token", 'Accept' => 'application/json', 'Content-Type' => 'application/json', - ])->post("{$this->baseUrl}/api/customer/{$customerId}/asset/{$assetId}"); + ])->post("{$this->baseUrl}api/customer/{$customerId}/asset/{$assetId}"); // Log the response for debugging purposes Log::info('Asset Assignment Response: ' . $response->body()); @@ -381,7 +381,7 @@ class AdminService $token = $this->getToken(); - $url = "{$this->baseUrl}/api/customer/{$data['customerId']}"; + $url = "{$this->baseUrl}api/customer/{$data['customerId']}"; $response = Http::withHeaders([ 'Authorization' => "Bearer $token", @@ -413,9 +413,10 @@ class AdminService $token = $this->getToken(); $response = Http::withHeaders([ - 'Authorization' => "Bearer $token", + 'X-Authorization' => "Bearer $token", 'accept' => 'application/json', - ])->get("{$this->baseUrl}/api/users?pageSize=100&page=0"); + 'Content-Type' => 'application/json', + ])->get("{$this->baseUrl}api/users?pageSize=100&page=0"); if ($response->successful()) { return $response->json(); @@ -432,7 +433,7 @@ class AdminService $response = Http::withHeaders([ 'Authorization' => "Bearer $token", 'accept' => 'application/json', - ])->delete("{$this->baseUrl}/api/user/{$userId}"); + ])->delete("{$this->baseUrl}api/user/{$userId}"); if ($response->failed()) { Log::error('ThingsBoard deletion failed - Status: ' . $response->status() . ' - Body: ' . $response->body()); @@ -499,7 +500,7 @@ class AdminService $searchResponse = Http::withHeaders([ 'Authorization' => "Bearer $token", 'accept' => 'application/json' - ])->get("{$this->baseUrl}/api/users?pageSize=1&page=0&textSearch={$user->email}"); + ])->get("{$this->baseUrl}api/users?pageSize=1&page=0&textSearch={$user->email}"); if ($searchResponse->successful() && !empty($searchResponse['data'])) { $tbUser = $searchResponse['data'][0]; @@ -509,7 +510,7 @@ class AdminService Http::withHeaders([ 'Authorization' => "Bearer $token", 'Content-Type' => 'application/json' - ])->post("{$this->baseUrl}/api/user", [ + ])->post("{$this->baseUrl}api/user", [ 'id' => ['id' => $tbUserId], // 'email' => $dummyEmail, 'authority' => $tbUser['authority'], @@ -530,7 +531,7 @@ class AdminService // 'email' => $dummyEmail ]; - $activationUrl = "{$this->baseUrl}/api/noauth/activate"; + $activationUrl = "{$this->baseUrl}api/noauth/activate"; $response = Http::withHeaders([ 'Content-Type' => 'application/json', @@ -608,7 +609,7 @@ class AdminService $response = Http::withHeaders([ 'Authorization' => "Bearer $token", 'accept' => 'application/json', - ])->get("{$this->baseUrl}/api/users?pageSize=100&page=0"); + ])->get("{$this->baseUrl}api/users?pageSize=100&page=0"); if ($response->successful()) { return $response->json();