From 623b00902799cff8ac5a848075cafdb7852e8d5d Mon Sep 17 00:00:00 2001 From: sayliraut Date: Tue, 15 Apr 2025 17:12:20 +0530 Subject: [PATCH 01/17] change in additional info --- app/Services/AdminService.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/Services/AdminService.php b/app/Services/AdminService.php index 1b649b2..a87d187 100644 --- a/app/Services/AdminService.php +++ b/app/Services/AdminService.php @@ -113,13 +113,11 @@ class AdminService 'phone' => $data['phone'] ?? '1234567890', 'version' => $data['version'] ?? '794665488', 'additionalInfo' => [ - 'description' => $data['description'] ?? 'User description' + 'description' => $data['additionalInfo'] ?? 'User description' ], ]; - - if (!empty($data['id']) && is_array($data['id']) && isset($data['id']['id'])) { $payload['id'] = [ 'id' => $data['id']['id'], @@ -487,4 +485,4 @@ class AdminService throw new Exception('Failed to fetch users: ' . $response->body()); } } -} \ No newline at end of file +} From cacc5426fca9f333547d4db582f52a5a6362d54b Mon Sep 17 00:00:00 2001 From: kshitige Date: Tue, 15 Apr 2025 19:12:46 +0530 Subject: [PATCH 02/17] deleteAsset changes --- .../APIS/AdminApi/AssetadmintController.php | 57 +++++++++++-------- 1 file changed, 34 insertions(+), 23 deletions(-) diff --git a/app/Http/Controllers/APIS/AdminApi/AssetadmintController.php b/app/Http/Controllers/APIS/AdminApi/AssetadmintController.php index dc8d7b1..a23a7f5 100644 --- a/app/Http/Controllers/APIS/AdminApi/AssetadmintController.php +++ b/app/Http/Controllers/APIS/AdminApi/AssetadmintController.php @@ -162,34 +162,45 @@ class AssetadmintController extends Controller return jsonResponseWithErrorMessage('Asset ID is required', 400); } - $response = $this->adminService->deleteAsset(['assetId' => $assetId]); - Log::info("Response: " . json_encode($response)); + try { + $response = $this->adminService->deleteAsset(['assetId' => $assetId]); + Log::info("Asset delete API response", ['response' => $response]); - if (!is_array($response)) { - Log::error("Unexpected API response format.", ['response' => $response]); - return jsonResponseWithErrorMessage('Unexpected API response format', 500); + if (!is_array($response)) { + Log::error("Unexpected API response format", ['response' => $response]); + return jsonResponseWithErrorMessage('Unexpected API response format', 500); + } + + if (isset($response['status']) && $response['status'] === 400) { + Log::error("API failed to delete asset", ['message' => $response['message']]); + return jsonResponseWithErrorMessage($response['message'], 400, $response); + } + + if (empty($response)) { + Log::error("API response is empty while deleting asset"); + return jsonResponseWithErrorMessage('Failed to delete asset', 400); + } + + // Delete from local database + $asset = Asset::find($assetId); + if ($asset) { + $asset->delete(); + } else { + Log::warning("Asset not found in DB", ['assetId' => $assetId]); + } + + return jsonResponseWithSuccessMessage('Asset deleted successfully', ['api_response' => $response]); + } catch (\Exception $e) { + Log::error("Exception while deleting asset", [ + 'message' => $e->getMessage(), + 'trace' => $e->getTraceAsString(), + ]); + return jsonResponseWithErrorMessage('An error occurred while deleting the asset', 500); } - - if (isset($response['status']) && $response['status'] === 400) { - Log::error("Failed to delete asset: " . $response['message']); - return jsonResponseWithErrorMessage($response['message'], 400, $response); - } - - if (empty($response)) { - Log::error("API Data is empty, cannot delete asset."); - return jsonResponseWithErrorMessage('Failed to delete asset', 400); - } - - // Delete from local database - $asset = Asset::where('id', $assetId)->first(); - if ($asset) { - $asset->delete(); - } - - return jsonResponseWithSuccessMessage('Asset deleted successfully', ['api_response' => $response]); } + public function assignAssetToUser(Request $request) { From 4b4826a4ffda595d5a1b56d6dec0c224ddb23c9c Mon Sep 17 00:00:00 2001 From: sayliraut Date: Wed, 16 Apr 2025 11:42:29 +0530 Subject: [PATCH 03/17] change in device api --- app/Models/Device.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/Models/Device.php b/app/Models/Device.php index 45d600f..e8c485d 100644 --- a/app/Models/Device.php +++ b/app/Models/Device.php @@ -28,6 +28,7 @@ class Device extends Model 'active', 'additional_info', 'device_data', + 'created_time', ]; // Cast UUIDs and related IDs as strings @@ -57,4 +58,4 @@ class Device extends Model { return $this->belongsTo(Customer::class, 'customer_id', 'id'); } -} \ No newline at end of file +} From 13bae520e5b868cccfb68b87876d5ee4ac3533f7 Mon Sep 17 00:00:00 2001 From: sayliraut Date: Wed, 16 Apr 2025 17:30:22 +0530 Subject: [PATCH 04/17] change in device --- app/Http/Controllers/APIS/AdminApi/DeviceController.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/APIS/AdminApi/DeviceController.php b/app/Http/Controllers/APIS/AdminApi/DeviceController.php index c32f32e..7f4df0b 100644 --- a/app/Http/Controllers/APIS/AdminApi/DeviceController.php +++ b/app/Http/Controllers/APIS/AdminApi/DeviceController.php @@ -47,6 +47,7 @@ class DeviceController extends Controller ] ], 'deviceProfileId' => $request->deviceProfileId ?? 1, + 'asset_id' => $request->asset_id ?? 'a5daeb60-f36c-11ef-a9dc-45dd276e4cd5', ]; @@ -79,7 +80,7 @@ class DeviceController extends Controller 'name' => $apiResponse['name'] ?? null, 'type' => $apiResponse['type'] ?? null, 'label' => $apiResponse['label'] ?? null, - 'asset_id' => $apiResponse['asset_id'] ?? 'a5daeb60-f36c-11ef-a9dc-45dd276e4cd5', + 'asset_id' => $request->asset_id ?? 'a5daeb60-f36c-11ef-a9dc-45dd276e4cd5', 'device_profile_id' => $apiResponse['deviceProfileId']['id'] ?? null, 'firmware_id' => $apiResponse['firmwareId']['id'] ?? null, 'software_id' => $apiResponse['softwareId']['id'] ?? null, From fbe24a8651ab33d6be80f2434f2afd43306bad27 Mon Sep 17 00:00:00 2001 From: sayliraut Date: Wed, 16 Apr 2025 17:51:17 +0530 Subject: [PATCH 06/17] change in device validation --- app/Http/Requests/CreateDeviceRequest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Requests/CreateDeviceRequest.php b/app/Http/Requests/CreateDeviceRequest.php index 751e989..04ae6b5 100644 --- a/app/Http/Requests/CreateDeviceRequest.php +++ b/app/Http/Requests/CreateDeviceRequest.php @@ -27,7 +27,7 @@ class CreateDeviceRequest extends FormRequest return [ 'name' => 'required|string', - 'type' => 'required|string|max:255', + // 'type' => 'required|string|max:255', 'label' => 'required|string|max:255', 'customerId' => 'required', From f32d6763227a00383ac3d366c17510571ab56208 Mon Sep 17 00:00:00 2001 From: sayliraut Date: Mon, 21 Apr 2025 14:43:49 +0530 Subject: [PATCH 07/17] change in asset list by customer id --- app/Http/Controllers/APIS/AdminApi/AssetadmintController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/APIS/AdminApi/AssetadmintController.php b/app/Http/Controllers/APIS/AdminApi/AssetadmintController.php index dbb4627..8ddc97f 100644 --- a/app/Http/Controllers/APIS/AdminApi/AssetadmintController.php +++ b/app/Http/Controllers/APIS/AdminApi/AssetadmintController.php @@ -346,7 +346,7 @@ class AssetadmintController extends Controller }); if ($assets->isEmpty()) { - return response()->json(['message' => 'No assets found for this customer ID'], 404); + return response()->json(['message' => 'No assets found for this customer ID'], 200); } return jsonResponseWithSuccessMessage('Assets fetched successfully', [ From 8a529bbaa999f914b25684cfb7b53eae7b2bca3b Mon Sep 17 00:00:00 2001 From: sayliraut Date: Tue, 22 Apr 2025 15:53:42 +0530 Subject: [PATCH 08/17] change --- app/Http/Controllers/APIS/AdminApi/DeviceController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/APIS/AdminApi/DeviceController.php b/app/Http/Controllers/APIS/AdminApi/DeviceController.php index 7f4df0b..e845c7e 100644 --- a/app/Http/Controllers/APIS/AdminApi/DeviceController.php +++ b/app/Http/Controllers/APIS/AdminApi/DeviceController.php @@ -47,7 +47,7 @@ class DeviceController extends Controller ] ], 'deviceProfileId' => $request->deviceProfileId ?? 1, - 'asset_id' => $request->asset_id ?? 'a5daeb60-f36c-11ef-a9dc-45dd276e4cd5', + 'asset_id' => $request->asset_id ?? 'null', ]; @@ -80,7 +80,7 @@ class DeviceController extends Controller 'name' => $apiResponse['name'] ?? null, 'type' => $apiResponse['type'] ?? null, 'label' => $apiResponse['label'] ?? null, - 'asset_id' => $request->asset_id ?? 'a5daeb60-f36c-11ef-a9dc-45dd276e4cd5', + 'asset_id' => $request->asset_id ?? 'null', 'device_profile_id' => $apiResponse['deviceProfileId']['id'] ?? null, 'firmware_id' => $apiResponse['firmwareId']['id'] ?? null, 'software_id' => $apiResponse['softwareId']['id'] ?? null, From 773626a0b3c8f6c14d0bd004e6f55703f2811674 Mon Sep 17 00:00:00 2001 From: sayliraut Date: Wed, 23 Apr 2025 12:31:37 +0530 Subject: [PATCH 09/17] changes in create user function --- .../APIS/AdminApi/UsersController.php | 41 ++++++++++--------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/app/Http/Controllers/APIS/AdminApi/UsersController.php b/app/Http/Controllers/APIS/AdminApi/UsersController.php index e6c53e2..131488f 100644 --- a/app/Http/Controllers/APIS/AdminApi/UsersController.php +++ b/app/Http/Controllers/APIS/AdminApi/UsersController.php @@ -9,6 +9,7 @@ use App\Mail\Admin\UserCreatedMail; use App\Models\User; use App\Services\AdminService; use Exception; +use Faker\Guesser\Name; use Illuminate\Database\QueryException; use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Log; @@ -213,17 +214,17 @@ class UsersController extends Controller // Validation rules (include all fields) $validator = Validator::make($request->all(), [ 'email' => 'required|email|unique:users,email', - 'authority' => 'required|string|in:CUSTOMER_USER,TENANT_ADMIN,SYS_ADMIN', - 'tenant_id' => 'required|uuid', - 'customer_id' => 'nullable|uuid', - 'first_name' => 'required|string|max:255', - 'last_name' => 'required|string|max:255', - 'phone' => 'nullable|string|max:20', + // 'authority' => 'required|string|in:CUSTOMER_USER,TENANT_ADMIN,SYS_ADMIN', + // 'tenant_id' => 'required|uuid', + // 'customer_id' => 'nullable|uuid', + // 'first_name' => 'required|string|max:255', + // 'last_name' => 'required|string|max:255', + // 'phone' => 'nullable|string|max:20', 'name' => 'nullable|string|max:255', - 'description' => 'nullable|string', - 'default_dashboard_id' => 'nullable', - 'home_dashboard_id' => 'nullable', - 'version' => 'nullable|integer', + // 'description' => 'nullable|string', + // 'default_dashboard_id' => 'nullable', + // 'home_dashboard_id' => 'nullable', + // 'version' => 'nullable|integer', // Add validation for other fields as needed ]); @@ -243,17 +244,17 @@ class UsersController extends Controller $user = User::create([ 'id' => $userId, 'email' => $request->email, - 'authority' => $request->authority, - 'tenant_id' => $request->tenant_id, - 'customer_id' => $request->customer_id, - 'first_name' => $request->first_name, - 'last_name' => $request->last_name, - 'phone' => $request->phone, - 'name' => $request->name ?? "{$request->first_name} {$request->last_name}", - 'description' => $request->description, - 'default_dashboard_id' => $request->default_dashboard_id, + 'authority' => $request->authority ?? 'CUSTOMER_USER', + 'tenant_id' => $request->tenant_id ?? null, + 'customer_id' => $request->customer_id ?? null, + 'first_name' => $request->first_name ?? $request->name, + 'last_name' => $request->last_name ?? $request->name, + 'phone' => $request->phone ?? null, + 'name' => $request->name ?? null, + 'description' => $request->description ?? null, + 'default_dashboard_id' => $request->default_dashboard_id ?? null, 'default_dashboard_fullscreen' => $request->default_dashboard_fullscreen ?? false, - 'home_dashboard_id' => $request->home_dashboard_id, + 'home_dashboard_id' => $request->home_dashboard_id ?? null, 'home_dashboard_hide_toolbar' => $request->home_dashboard_hide_toolbar ?? false, 'user_credentials_enabled' => $request->user_credentials_enabled ?? false, 'failed_login_attempts' => $request->failed_login_attempts ?? 0, From 4aa3f03930cb8f008dcff0307b9722d1f6670c54 Mon Sep 17 00:00:00 2001 From: sayliraut Date: Wed, 23 Apr 2025 14:45:29 +0530 Subject: [PATCH 10/17] change in create user --- .../APIS/AdminApi/UsersController.php | 16 ++++++++-------- app/Services/AdminService.php | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/Http/Controllers/APIS/AdminApi/UsersController.php b/app/Http/Controllers/APIS/AdminApi/UsersController.php index 131488f..a54c5cf 100644 --- a/app/Http/Controllers/APIS/AdminApi/UsersController.php +++ b/app/Http/Controllers/APIS/AdminApi/UsersController.php @@ -217,10 +217,10 @@ class UsersController extends Controller // 'authority' => 'required|string|in:CUSTOMER_USER,TENANT_ADMIN,SYS_ADMIN', // 'tenant_id' => 'required|uuid', // 'customer_id' => 'nullable|uuid', - // 'first_name' => 'required|string|max:255', - // 'last_name' => 'required|string|max:255', + 'first_name' => 'required|string|max:255', + 'last_name' => 'required|string|max:255', // 'phone' => 'nullable|string|max:20', - 'name' => 'nullable|string|max:255', + // 'name' => 'nullable|string|max:255', // 'description' => 'nullable|string', // 'default_dashboard_id' => 'nullable', // 'home_dashboard_id' => 'nullable', @@ -247,10 +247,10 @@ class UsersController extends Controller 'authority' => $request->authority ?? 'CUSTOMER_USER', 'tenant_id' => $request->tenant_id ?? null, 'customer_id' => $request->customer_id ?? null, - 'first_name' => $request->first_name ?? $request->name, - 'last_name' => $request->last_name ?? $request->name, + 'first_name' => $request->first_name ?? '', + 'last_name' => $request->last_name ?? '', 'phone' => $request->phone ?? null, - 'name' => $request->name ?? null, + 'name' => $request->name ?? "{$request->first_name} {$request->last_name}", 'description' => $request->description ?? null, 'default_dashboard_id' => $request->default_dashboard_id ?? null, 'default_dashboard_fullscreen' => $request->default_dashboard_fullscreen ?? false, @@ -267,13 +267,13 @@ class UsersController extends Controller $serviceData = [ 'email' => $request->email, - 'authority' => $request->authority, + 'authority' => $request->authority ?? null, 'firstName' => $request->first_name, 'lastName' => $request->last_name, 'phone' => $request->phone, 'name' => $request->name ?? "{$request->first_name} {$request->last_name}", 'description' => $request->description, - 'tenant_id' => $request->tenant_id, + 'tenant_id' => 'bbab7c17-2f19-4eff-9ce7-63870e02b522', 'customer_id' => $request->customer_id ]; diff --git a/app/Services/AdminService.php b/app/Services/AdminService.php index 7e6915d..8ec4a60 100644 --- a/app/Services/AdminService.php +++ b/app/Services/AdminService.php @@ -273,7 +273,7 @@ class AdminService 'name' => $data['name'] ?? ($data['first_name'] . ' ' . $data['last_name'] ?? ''), 'phone' => $data['phone'] ?? '', 'tenantId' => [ - 'id' => $data['tenant_id'], + 'id' => 'bbab7c17-2f19-4eff-9ce7-63870e02b522', 'entityType' => 'TENANT' ], 'additionalInfo' => [ From d79dabbbaf9db76c7a5cf47fa57770712b684264 Mon Sep 17 00:00:00 2001 From: kshitige Date: Wed, 23 Apr 2025 16:44:25 +0530 Subject: [PATCH 11/17] school --- app/Http/Controllers/APIS/AdminApi/DeviceController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/APIS/AdminApi/DeviceController.php b/app/Http/Controllers/APIS/AdminApi/DeviceController.php index c32f32e..b4fc78d 100644 --- a/app/Http/Controllers/APIS/AdminApi/DeviceController.php +++ b/app/Http/Controllers/APIS/AdminApi/DeviceController.php @@ -180,7 +180,7 @@ class DeviceController extends Controller public function devicelistCustomer($customerId) - { + { try { $devices = Device::with('deviceProfile:id,name', 'customer:id,name') ->where('customer_id', $customerId) From d07dc2fd6a1efa51be01b4e283622428286fafde Mon Sep 17 00:00:00 2001 From: kshitige Date: Wed, 23 Apr 2025 16:55:25 +0530 Subject: [PATCH 12/17] school --- app/Services/AdminService.php | 36 +++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/app/Services/AdminService.php b/app/Services/AdminService.php index 8ec4a60..84f448c 100644 --- a/app/Services/AdminService.php +++ b/app/Services/AdminService.php @@ -490,12 +490,42 @@ class AdminService } } + // public function activateUser(User $user, string $password, string $activateToken) + // { + // try { + // $payload = [ + // 'activateToken' => $activateToken, + // 'password' => $password + // ]; + + // $activationUrl = "{$this->baseUrl}/api/noauth/activate"; + + // $response = Http::withHeaders([ + // 'Content-Type' => 'application/json', + // ])->post($activationUrl, $payload); + + // if (!$response->successful()) { + // Log::error("Failed to activate user in ThingsBoard. Error: " . $response->body()); + // throw new \Exception('Failed to activate user: ' . $response->body()); + // } + + // Log::info("User activated successfully in ThingsBoard for User ID: {$user->id}"); + // } catch (\Exception $e) { + // Log::error("Error activating user in ThingsBoard for User ID: {$user->id}. Exception: " . $e->getMessage()); + // throw $e; + // } + // } + + public function activateUser(User $user, string $password, string $activateToken) { try { + $dummyEmail = 'dummy+' . $user->id . '@example.com'; // unique dummy email + $payload = [ 'activateToken' => $activateToken, - 'password' => $password + 'password' => $password, + 'email' => $dummyEmail // send dummy email to ThingsBoard ]; $activationUrl = "{$this->baseUrl}/api/noauth/activate"; @@ -509,7 +539,7 @@ class AdminService throw new \Exception('Failed to activate user: ' . $response->body()); } - Log::info("User activated successfully in ThingsBoard for User ID: {$user->id}"); + Log::info("User activated in ThingsBoard with dummy email: {$dummyEmail} for User ID: {$user->id}"); } catch (\Exception $e) { Log::error("Error activating user in ThingsBoard for User ID: {$user->id}. Exception: " . $e->getMessage()); throw $e; @@ -517,8 +547,6 @@ class AdminService } - - public function getUserByEmailThingsBoard(string $email) { Log::info("Fetching ThingsBoard ID by email: $email"); From 494d7b7ea50ba8f4b2eed49d4d68a90d8d463393 Mon Sep 17 00:00:00 2001 From: kshitige Date: Wed, 23 Apr 2025 19:43:24 +0530 Subject: [PATCH 13/17] email thingsboard --- .../APIS/AdminApi/UsersController.php | 90 +++++++++++++++++-- app/Services/AdminService.php | 56 ++++++++++-- 2 files changed, 129 insertions(+), 17 deletions(-) diff --git a/app/Http/Controllers/APIS/AdminApi/UsersController.php b/app/Http/Controllers/APIS/AdminApi/UsersController.php index a54c5cf..d3a3823 100644 --- a/app/Http/Controllers/APIS/AdminApi/UsersController.php +++ b/app/Http/Controllers/APIS/AdminApi/UsersController.php @@ -404,6 +404,78 @@ class UsersController extends Controller + // public function activate(Request $request, $id) + // { + // Log::info('Full Request URL: ' . $request->fullUrl()); + + // try { + // $user = User::find($id); + + // if (!$user) { + // Log::error("User not found for ID: {$id}"); + // return response()->json([ + // 'status' => false, + // 'message' => 'User not found.' + // ], 404); + // } + + // $token = $request->query('token'); + // if (!$token) { + // Log::error("Token missing for User ID: {$id}"); + // return response()->json([ + // 'status' => false, + // 'message' => 'Invalid activation link.' + // ], 401); + // } + + // // Update password in Laravel + // $user->password = Hash::make('password'); + // $user->save(); + // Log::info("Password updated for User ID: {$id} in Laravel."); + + // // Activate user in ThingsBoard + // $activateToken = $token; + // $password = 'password'; + + // try { + // $this->adminService->activateUser($user, $password, $activateToken); + // Log::info("User ID: {$id} activated successfully in ThingsBoard."); + + // return response()->json([ + // 'status' => true, + // 'message' => 'User activated and password updated successfully!', + // 'user_id' => $user->id + // ], 200); + + // } catch (\Exception $e) { + // Log::error("ThingsBoard activation failed: " . $e->getMessage()); + + // // If token is invalid or user is already activated, skip activation + // if (str_contains($e->getMessage(), 'Unable to find user credentials')) { + // return response()->json([ + // 'status' => true, + // 'message' => 'User is already activated. Password updated successfully.' + // ], 200); + // } + + // return response()->json([ + // 'status' => false, + // 'message' => 'Failed to activate user in ThingsBoard.', + // 'error' => $e->getMessage() + // ], 500); + // } + + // } catch (\Exception $e) { + // Log::error("Error activating user ID: {$id}. Exception: " . $e->getMessage()); + // return response()->json([ + // 'status' => false, + // 'message' => 'An error occurred. Please try again later.', + // 'error' => $e->getMessage() + // ], 500); + // } + // } + + public function activate(Request $request, $id) { Log::info('Full Request URL: ' . $request->fullUrl()); @@ -433,28 +505,31 @@ class UsersController extends Controller $user->save(); Log::info("Password updated for User ID: {$id} in Laravel."); - // Activate user in ThingsBoard - $activateToken = $token; - $password = 'password'; + // Dummy email for ThingsBoardg + // $dummyEmail = 'dummy+' . $user->id . '@example.com'; try { - $this->adminService->activateUser($user, $password, $activateToken); + $this->adminService->activateUser($user, 'password', $token); Log::info("User ID: {$id} activated successfully in ThingsBoard."); return response()->json([ 'status' => true, 'message' => 'User activated and password updated successfully!', - 'user_id' => $user->id + 'user_id' => $user->id, + 'real_email' => $user->email, + // 'tb_email' => $dummyEmail ], 200); } catch (\Exception $e) { Log::error("ThingsBoard activation failed: " . $e->getMessage()); - // If token is invalid or user is already activated, skip activation if (str_contains($e->getMessage(), 'Unable to find user credentials')) { return response()->json([ 'status' => true, - 'message' => 'User is already activated. Password updated successfully.' + 'message' => 'User is already activated. Password updated successfully.', + 'user_id' => $user->id, + 'real_email' => $user->email, + // 'tb_email' => $dummyEmail ], 200); } @@ -479,7 +554,6 @@ class UsersController extends Controller - // public function autoLogin(Request $request) // { // $request->validate([ diff --git a/app/Services/AdminService.php b/app/Services/AdminService.php index 84f448c..613c315 100644 --- a/app/Services/AdminService.php +++ b/app/Services/AdminService.php @@ -263,10 +263,15 @@ class AdminService if (!isset($data['tenant_id'])) { throw new \Exception('tenant_id is required'); } + static $counter = 1; + $email = "dummy{$counter}@example.com"; + $counter++; + // Prepare the payload with required fields $payload = [ - 'email' => $data['email'] ?? '', + + 'email' => $email, 'authority' => $data['authority'] ?? 'CUSTOMER_USER', 'firstName' => $data['first_name'] ?? '', 'lastName' => $data['last_name'] ?? '', @@ -520,33 +525,66 @@ class AdminService public function activateUser(User $user, string $password, string $activateToken) { try { - $dummyEmail = 'dummy+' . $user->id . '@example.com'; // unique dummy email + // $dummyEmail = 'dummy+' . $user->id . '@example.com'; + $token = $this->getToken(); - $payload = [ + // Step 1: Search for existing user by real email + $searchResponse = Http::withHeaders([ + 'Authorization' => "Bearer $token", + 'accept' => 'application/json' + ])->get("{$this->baseUrl}/api/users?pageSize=1&page=0&textSearch={$user->email}"); + + if ($searchResponse->successful() && !empty($searchResponse['data'])) { + $tbUser = $searchResponse['data'][0]; + $tbUserId = $tbUser['id']['id']; + + // Step 2: Update user email to dummy email + Http::withHeaders([ + 'Authorization' => "Bearer $token", + 'Content-Type' => 'application/json' + ])->post("{$this->baseUrl}/api/user", [ + 'id' => ['id' => $tbUserId], + // 'email' => $dummyEmail, + 'authority' => $tbUser['authority'], + 'firstName' => $tbUser['firstName'] ?? '', + 'lastName' => $tbUser['lastName'] ?? '', + 'tenantId' => $tbUser['tenantId'], + 'customerId' => $tbUser['customerId'], + 'additionalInfo' => $tbUser['additionalInfo'] ?? null, + ]); + + // Log::info("ThingsBoard user email updated to dummy: {$dummyEmail}"); + } + + // Step 3: Activate account using dummy email + $activationPayload = [ 'activateToken' => $activateToken, 'password' => $password, - 'email' => $dummyEmail // send dummy email to ThingsBoard + // 'email' => $dummyEmail ]; $activationUrl = "{$this->baseUrl}/api/noauth/activate"; $response = Http::withHeaders([ 'Content-Type' => 'application/json', - ])->post($activationUrl, $payload); + ])->post($activationUrl, $activationPayload); if (!$response->successful()) { - Log::error("Failed to activate user in ThingsBoard. Error: " . $response->body()); + Log::error("Activation failed. Response: " . $response->body()); throw new \Exception('Failed to activate user: ' . $response->body()); } - Log::info("User activated in ThingsBoard with dummy email: {$dummyEmail} for User ID: {$user->id}"); + // Log::info("User activated in ThingsBoard with dummy email: {$dummyEmail}"); + } catch (\Exception $e) { - Log::error("Error activating user in ThingsBoard for User ID: {$user->id}. Exception: " . $e->getMessage()); + Log::error("Error during ThingsBoard activation. Exception: " . $e->getMessage()); throw $e; } } + + public function getUserByEmailThingsBoard(string $email) { Log::info("Fetching ThingsBoard ID by email: $email"); @@ -611,4 +649,4 @@ class AdminService throw new Exception('Failed to fetch users: ' . $response->body()); } } -} +} \ No newline at end of file From e3f1a2816d343a66df4323a941a9a1cbe775ed40 Mon Sep 17 00:00:00 2001 From: sayliraut Date: Thu, 24 Apr 2025 12:37:42 +0530 Subject: [PATCH 14/17] Change in filter alarm --- app/Http/Controllers/AlarmControllerCommon.php | 7 +++---- app/Services/AlarmService.php | 7 +++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/app/Http/Controllers/AlarmControllerCommon.php b/app/Http/Controllers/AlarmControllerCommon.php index 5f222f5..1c243a9 100644 --- a/app/Http/Controllers/AlarmControllerCommon.php +++ b/app/Http/Controllers/AlarmControllerCommon.php @@ -212,8 +212,6 @@ class AlarmControllerCommon extends Controller public function filterAlarm(Request $request) { try { - $token = readHeaderToken(); - $useId = $token['sub']; $alarmData = $request->only([ 'severity', @@ -222,10 +220,11 @@ class AlarmControllerCommon extends Controller 'startTs', 'endTs', 'deviceId', - 'assetId' + 'assetId', + 'assignId', ]); - $apiResponse = $this->alarmService->filterAlarm($alarmData, $useId); + $apiResponse = $this->alarmService->filterAlarm($alarmData); return jsonResponseWithSuccessMessage('Alarm data retrieved successfully', ['api_response' => $apiResponse]); } catch (Exception $e) { diff --git a/app/Services/AlarmService.php b/app/Services/AlarmService.php index a7a1fe4..74614aa 100644 --- a/app/Services/AlarmService.php +++ b/app/Services/AlarmService.php @@ -313,10 +313,9 @@ class AlarmService } - public function filterAlarm(array $data, $useId) + public function filterAlarm(array $data) { $token = $this->getToken(); - $deviceId = null; if (!empty($data['deviceId'])) { @@ -337,12 +336,12 @@ class AlarmService $queryParams = array_filter([ 'severityList' => $data['severity'] ?? null, - 'assigneeId' => $useId, + 'assigneeId' => $data['assignId'] ?? null, 'pageSize' => $data['pageSize'] ?? 10, 'page' => $data['page'] ?? 0, 'startTime' => $data['startTs'] ?? null, 'endTime' => $data['endTs'] ?? null, - 'deviceId' => $deviceId, + 'deviceId' => $deviceId, ], function ($value) { return $value !== null; }); From 6cf1eac1a731c00049761f172c699d1529314963 Mon Sep 17 00:00:00 2001 From: sayliraut Date: Thu, 24 Apr 2025 12:54:09 +0530 Subject: [PATCH 15/17] change --- app/Services/AdminService.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/Services/AdminService.php b/app/Services/AdminService.php index 613c315..9d71f52 100644 --- a/app/Services/AdminService.php +++ b/app/Services/AdminService.php @@ -263,15 +263,15 @@ class AdminService if (!isset($data['tenant_id'])) { throw new \Exception('tenant_id is required'); } - static $counter = 1; - $email = "dummy{$counter}@example.com"; - $counter++; + // static $counter = 1; + // $email = "dummy{$counter}@example.com"; + // $counter++; // Prepare the payload with required fields $payload = [ - 'email' => $email, + 'email' => $data['email'] ?? '', 'authority' => $data['authority'] ?? 'CUSTOMER_USER', 'firstName' => $data['first_name'] ?? '', 'lastName' => $data['last_name'] ?? '', @@ -649,4 +649,4 @@ class AdminService throw new Exception('Failed to fetch users: ' . $response->body()); } } -} \ No newline at end of file +} From 67ff5bd04ba30527e4d2fdd5bfc2741a5777d007 Mon Sep 17 00:00:00 2001 From: kshitige Date: Thu, 24 Apr 2025 13:32:49 +0530 Subject: [PATCH 16/17] changes in device and asset fetch by customer id --- app/Http/Controllers/APIS/AdminApi/DeviceController.php | 4 ++-- app/Http/Controllers/APIS/AdminApi/UsersController.php | 7 ++----- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/app/Http/Controllers/APIS/AdminApi/DeviceController.php b/app/Http/Controllers/APIS/AdminApi/DeviceController.php index db70861..678e176 100644 --- a/app/Http/Controllers/APIS/AdminApi/DeviceController.php +++ b/app/Http/Controllers/APIS/AdminApi/DeviceController.php @@ -181,7 +181,7 @@ class DeviceController extends Controller public function devicelistCustomer($customerId) - { + { try { $devices = Device::with('deviceProfile:id,name', 'customer:id,name') ->where('customer_id', $customerId) @@ -198,7 +198,7 @@ class DeviceController extends Controller }); if ($devices->isEmpty()) { - return response()->json(['message' => 'No devices found for this customer ID'], 404); + return response()->json(['message' => 'No devices found for this customer ID'], 200); } return jsonResponseWithSuccessMessage('Devices fetched successfully', [ diff --git a/app/Http/Controllers/APIS/AdminApi/UsersController.php b/app/Http/Controllers/APIS/AdminApi/UsersController.php index d3a3823..6d93973 100644 --- a/app/Http/Controllers/APIS/AdminApi/UsersController.php +++ b/app/Http/Controllers/APIS/AdminApi/UsersController.php @@ -519,7 +519,6 @@ class UsersController extends Controller 'real_email' => $user->email, // 'tb_email' => $dummyEmail ], 200); - } catch (\Exception $e) { Log::error("ThingsBoard activation failed: " . $e->getMessage()); @@ -539,7 +538,6 @@ class UsersController extends Controller 'error' => $e->getMessage() ], 500); } - } catch (\Exception $e) { Log::error("Error activating user ID: {$id}. Exception: " . $e->getMessage()); return response()->json([ @@ -743,7 +741,7 @@ class UsersController extends Controller }); if ($users->isEmpty()) { - return response()->json(['message' => 'No users found for this customer ID'], 404); + return response()->json(['message' => 'No users found for this customer ID'], 200); } return jsonResponseWithSuccessMessage('Users fetched successfully', [ @@ -754,5 +752,4 @@ class UsersController extends Controller return jsonResponseWithErrorMessage($e->getMessage(), 500); } } - -} +} \ No newline at end of file From d4918cd4cf940e0d67c635fd38773c682484dcab Mon Sep 17 00:00:00 2001 From: sayliraut Date: Thu, 24 Apr 2025 17:09:46 +0530 Subject: [PATCH 17/17] changes in create alarm api --- app/Http/Controllers/AlarmControllerCommon.php | 12 ++++++------ app/Services/AlarmService.php | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/app/Http/Controllers/AlarmControllerCommon.php b/app/Http/Controllers/AlarmControllerCommon.php index 1c243a9..8456f26 100644 --- a/app/Http/Controllers/AlarmControllerCommon.php +++ b/app/Http/Controllers/AlarmControllerCommon.php @@ -30,16 +30,16 @@ class AlarmControllerCommon extends Controller $alarmData = [ 'type' => $request->type ?? null, 'severity' => $request->severity ?? null, - 'acknowledged' => false ?? null, - 'cleared' => $request->cleared ?? Carbon::now()->timestamp, + 'acknowledged' => false, + 'cleared' => false, 'startTs' => $request->startTs ?? Carbon::now()->timestamp, 'endTs' => $request->endTs ?? Carbon::now()->timestamp, 'details' => $request->details ?? [], - 'propagate' => $request->propagate ?? false, - 'propagateToOwner' => $request->propagateToOwner ?? false, - 'propagateToTenant' => $request->propagateToTenant ?? false, + 'propagate' => true, + 'propagateToOwner' => true, + 'propagateToTenant' => true, 'originator' => $request->originator ?? 1, - 'assigneeId' => $request->assigneeId ?? 1, + // 'assigneeId' => $request->assigneeId ?? 1, ]; diff --git a/app/Services/AlarmService.php b/app/Services/AlarmService.php index 74614aa..5b3f93e 100644 --- a/app/Services/AlarmService.php +++ b/app/Services/AlarmService.php @@ -395,10 +395,10 @@ class AlarmService 'id' => $data['originator'] ?? null, 'entityType' => 'DEVICE' ], - 'assigneeId' => [ - 'id' => $data['assigneeId'] ?? null, - 'entityType' => 'USER' - ], + // 'assigneeId' => [ + // 'id' => $data['assigneeId'] ?? null, + // 'entityType' => 'USER' + // ], 'details' => $data['details'] ?? [], 'propagate' => $data['propagate'] ?? false, 'propagateToOwner' => $data['propagateToOwner'] ?? false,