Merge branch 'main' of http://git.wdipl.com/Nikhil.Kadam/vib360 into nikhil
This commit is contained in:
@@ -82,9 +82,9 @@ class AssetadmintController extends Controller
|
||||
public function storeAssest(CreateAssetRequest $request)
|
||||
{
|
||||
try {
|
||||
$additionalInfo = $request->has('additional_info') && is_string($request->additional_info)
|
||||
? json_decode($request->additional_info, true)
|
||||
: $request->additional_info;
|
||||
// $additionalInfo = $request->has('additional_info') && is_string($request->additional_info)
|
||||
// ? json_decode($request->additional_info, true)
|
||||
// : $request->additional_info;
|
||||
$assetData = [
|
||||
'entity_type' => 'ASSET', // Backend defined
|
||||
'createdTime' => now()->timestamp, // Backend defined
|
||||
@@ -96,7 +96,8 @@ class AssetadmintController extends Controller
|
||||
'assetProfileId' => $request->asset_profile_id ?? Str::uuid()->toString(),
|
||||
'externalId' => $request->external_id ?? Str::uuid()->toString(),
|
||||
'version' => $request->version ?? '1.0',
|
||||
'additionalInfo' => $additionalInfo ?? ['description' => 'Default asset description'],
|
||||
// 'additionalInfo' => $additionalInfo ?? ['description' => 'Default asset description'],
|
||||
'additionalInfo' => $request->additionalInfo
|
||||
];
|
||||
$response = $this->adminService->createAsset($assetData);
|
||||
if (!$response) {
|
||||
@@ -115,6 +116,7 @@ class AssetadmintController extends Controller
|
||||
$asset->external_id = $assetData['externalId'];
|
||||
$asset->version = $response['version'] ?? $assetData['version'];
|
||||
$asset->additional_info = json_encode($response['additionalInfo'] ?? $assetData['additionalInfo']);
|
||||
// 'additional_info' => json_encode($apiData['additionalInfo'] ?? [])
|
||||
$asset->save();
|
||||
// Fetch only the customer name
|
||||
$customerName = \App\Models\Customer::where('id', $assetData['customerId'])->value('name');
|
||||
@@ -129,76 +131,137 @@ class AssetadmintController extends Controller
|
||||
return response()->json(['error' => $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
// public function storeAssest(CreateAssetRequest $request)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// public function listAssest()
|
||||
// {
|
||||
// try {
|
||||
// $additionalInfo = $request->has('additional_info') && is_string($request->additional_info)
|
||||
// ? json_decode($request->additional_info, true)
|
||||
// : (is_array($request->additional_info) ? $request->additional_info : ['description' => 'Default asset description']);
|
||||
// $assets = Asset::with('customer')->get()->map(function ($asset) {
|
||||
// $assetData = $asset->toArray();
|
||||
// unset($assetData['customer']);
|
||||
// $assetData['customer_name'] = $asset->customer?->name;
|
||||
// return $assetData;
|
||||
// });
|
||||
|
||||
// $assetData = [
|
||||
// 'entity_type' => 'ASSET',
|
||||
// 'createdTime' => now()->timestamp,
|
||||
// 'tenantId' => $request->tenant_id ?? Str::uuid()->toString(),
|
||||
// 'customerId' => $request->customer_xid,
|
||||
// 'name' => $request->name,
|
||||
// 'type' => $request->type ?? 'Default Type',
|
||||
// 'label' => $request->label ?? '',
|
||||
// 'assetProfileId' => $request->asset_profile_id ?? Str::uuid()->toString(),
|
||||
// 'externalId' => $request->external_id ?? Str::uuid()->toString(),
|
||||
// 'additionalInfo' => $additionalInfo,
|
||||
// ];
|
||||
// return jsonResponseWithSuccessMessage('Assets fetched successfully', [
|
||||
// 'assests' => $assets
|
||||
// ]);
|
||||
// } catch (Exception $e) {
|
||||
|
||||
// $response = $this->adminService->createAsset($assetData);
|
||||
|
||||
// if (!$response) {
|
||||
// throw new \Exception('Failed to create asset via admin service');
|
||||
// }
|
||||
|
||||
// $asset = new Asset();
|
||||
// $asset->id = $response['id']['id'] ?? Str::uuid()->toString();
|
||||
// $asset->entity_type = $assetData['entity_type'];
|
||||
// $asset->created_time = $assetData['createdTime'];
|
||||
// $asset->tenant_id = $assetData['tenantId'];
|
||||
// $asset->customer_xid = $assetData['customerId'];
|
||||
// $asset->name = $response['name'] ?? $assetData['name'];
|
||||
// $asset->type = $response['type'] ?? $assetData['type'];
|
||||
// $asset->label = $response['label'] ?? $assetData['label'];
|
||||
// $asset->asset_profile_id = $assetData['assetProfileId'];
|
||||
// $asset->external_id = $assetData['externalId'];
|
||||
// $asset->version = $response['version'] ?? 1;
|
||||
// $asset->additional_info = json_encode($response['additionalInfo'] ?? $assetData['additionalInfo']);
|
||||
// $asset->save();
|
||||
|
||||
// $customerName = \App\Models\Customer::where('id', $assetData['customerId'])->value('name');
|
||||
|
||||
// return response()->json([
|
||||
// 'message' => 'Asset created successfully!',
|
||||
// 'data' => $asset,
|
||||
// 'customer_name' => $customerName,
|
||||
// 'api_response' => $response
|
||||
// ], 200);
|
||||
// } catch (\Exception $e) {
|
||||
// Log::error('Error in creating asset: ' . $e->getMessage());
|
||||
// return response()->json(['error' => $e->getMessage()], 500);
|
||||
// Log::error("An error occurred: " . $e->getMessage());
|
||||
// return jsonResponseWithErrorMessage($e->getMessage(), 500);
|
||||
// }
|
||||
// }
|
||||
|
||||
// public function listAssest()
|
||||
// {
|
||||
// try {
|
||||
// $assets = Asset::with([
|
||||
// 'customer:id,name',
|
||||
// 'userAssetLinks.user:id,first_name' // eager load first_name only
|
||||
// ])->get()->map(function ($asset) {
|
||||
// $assetData = $asset->toArray();
|
||||
|
||||
// unset($assetData['customer'], $assetData['user_asset_links']); // remove full objects
|
||||
|
||||
// $assetData['customer_name'] = $asset->customer?->name;
|
||||
|
||||
// // Collect user first names from user_asset_links
|
||||
// $userFirstNames = $asset->userAssetLinks->map(function ($userAssetLink) {
|
||||
// return optional($userAssetLink->user)->first_name;
|
||||
// })->filter()->values(); // remove nulls and reset keys
|
||||
|
||||
// $assetData['assign_to_user'] = $userFirstNames;
|
||||
|
||||
// return $assetData;
|
||||
// });
|
||||
|
||||
// return jsonResponseWithSuccessMessage('Assets fetched successfully', [
|
||||
// 'assets' => $assets
|
||||
// ]);
|
||||
// } catch (Exception $e) {
|
||||
// Log::error("An error occurred: " . $e->getMessage());
|
||||
// return jsonResponseWithErrorMessage($e->getMessage(), 500);
|
||||
// }
|
||||
// }
|
||||
|
||||
// public function listAssest()
|
||||
// {
|
||||
// try {
|
||||
// $assets = Asset::with([
|
||||
// 'customer:id,name',
|
||||
// 'userAssetLinks.user:id,first_name,last_name' // eager load first_name and last_name
|
||||
// ])->get()->map(function ($asset) {
|
||||
// $assetData = $asset->toArray();
|
||||
|
||||
// unset($assetData['customer'], $assetData['user_asset_links']); // remove full objects
|
||||
|
||||
// $assetData['customer_name'] = $asset->customer?->name;
|
||||
|
||||
// // Collect user id and full name (first_name + last_name) from user_asset_links
|
||||
// $assignToUsers = $asset->userAssetLinks->map(function ($userAssetLink) {
|
||||
// $user = $userAssetLink->user;
|
||||
// if ($user) {
|
||||
// return [
|
||||
// 'user_id' => $user->id,
|
||||
// 'full_name' => trim($user->first_name . ' ' . $user->last_name),
|
||||
// ];
|
||||
// }
|
||||
// return null;
|
||||
// })->filter()->values(); // remove nulls and reset keys
|
||||
|
||||
// $assetData['assign_to_users'] = $assignToUsers;
|
||||
|
||||
// return $assetData;
|
||||
// });
|
||||
|
||||
// return jsonResponseWithSuccessMessage('Assets fetched successfully', [
|
||||
// 'assets' => $assets
|
||||
// ]);
|
||||
// } catch (Exception $e) {
|
||||
// Log::error("An error occurred: " . $e->getMessage());
|
||||
// return jsonResponseWithErrorMessage($e->getMessage(), 500);
|
||||
// }
|
||||
// }
|
||||
|
||||
public function listAssest()
|
||||
{
|
||||
try {
|
||||
$assets = Asset::with('customer')->get()->map(function ($asset) {
|
||||
$assets = Asset::with([
|
||||
'customer:id,name',
|
||||
'userAssetLinks' => function ($query) {
|
||||
$query->where('active', 1) // Only fetch active user asset links
|
||||
->with(['user:id,first_name,last_name']); // Eager load user info
|
||||
}
|
||||
])->get()->map(function ($asset) {
|
||||
$assetData = $asset->toArray();
|
||||
unset($assetData['customer']);
|
||||
|
||||
unset($assetData['customer'], $assetData['user_asset_links']); // remove full objects
|
||||
|
||||
$assetData['customer_name'] = $asset->customer?->name;
|
||||
|
||||
// Collect user id and full name (first_name + last_name) from active user_asset_links
|
||||
$assignToUsers = $asset->userAssetLinks->map(function ($userAssetLink) {
|
||||
$user = $userAssetLink->user;
|
||||
if ($user) {
|
||||
return [
|
||||
'user_id' => $user->id,
|
||||
'full_name' => trim($user->first_name . ' ' . $user->last_name),
|
||||
];
|
||||
}
|
||||
return null;
|
||||
})->filter()->values(); // remove nulls and reset keys
|
||||
|
||||
$assetData['assign_to_users'] = $assignToUsers;
|
||||
|
||||
return $assetData;
|
||||
});
|
||||
|
||||
return jsonResponseWithSuccessMessage('Assets fetched successfully', [
|
||||
'assests' => $assets
|
||||
'assets' => $assets
|
||||
]);
|
||||
} catch (Exception $e) {
|
||||
Log::error("An error occurred: " . $e->getMessage());
|
||||
@@ -210,6 +273,9 @@ class AssetadmintController extends Controller
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public function deleteAsset(Request $request)
|
||||
{
|
||||
$assetId = $request->input('assetId'); // Fetching ID from request body
|
||||
@@ -256,58 +322,152 @@ class AssetadmintController extends Controller
|
||||
}
|
||||
|
||||
|
||||
// public function assignAssetToUser(Request $request)
|
||||
// {
|
||||
|
||||
// try {
|
||||
// $request->validate([
|
||||
// 'user_id' => 'required|exists:users,id',
|
||||
// 'asset_id' => 'required|uuid'
|
||||
// ]);
|
||||
|
||||
// $userId = $request->user_id;
|
||||
// $assetId = $request->asset_id;
|
||||
|
||||
// $userAssetLink = UserAssetLink::where('user_id', $userId)
|
||||
// ->where('asset_id', $assetId)
|
||||
// ->first();
|
||||
|
||||
// if (!$userAssetLink) {
|
||||
// $userAssetLink = new UserAssetLink();
|
||||
// $userAssetLink->user_id = $userId;
|
||||
// $userAssetLink->asset_id = $assetId;
|
||||
// $userAssetLink->active = 1;
|
||||
// $userAssetLink->save();
|
||||
|
||||
// Log::info("Asset successfully assigned to user.", ['userId' => $userId, 'assetId' => $assetId]);
|
||||
|
||||
// return response()->json([
|
||||
// 'success' => true,
|
||||
// 'message' => 'Asset assigned to user successfully.',
|
||||
// 'data' => $userAssetLink
|
||||
// ], 200);
|
||||
// }
|
||||
|
||||
// if ($userAssetLink->active == 1) {
|
||||
// $userAssetLink->active = 0;
|
||||
// $userAssetLink->save();
|
||||
// return response()->json([
|
||||
// 'success' => true,
|
||||
// 'message' => 'Asset unassigned from user.',
|
||||
// 'data' => $userAssetLink
|
||||
// ], 200);
|
||||
// }
|
||||
|
||||
// $userAssetLink->active = 1;
|
||||
// $userAssetLink->save();
|
||||
// return response()->json([
|
||||
// 'success' => true,
|
||||
// 'message' => 'Asset reassigned to user successfully.',
|
||||
// 'data' => $userAssetLink
|
||||
// ], 200);
|
||||
// } catch (Exception $e) {
|
||||
// Log::error("Error assigning asset: " . $e->getMessage());
|
||||
// return response()->json([
|
||||
// 'success' => false,
|
||||
// 'message' => 'Failed to assign or unassign asset to user',
|
||||
// 'error' => $e->getMessage()
|
||||
// ], 500);
|
||||
// }
|
||||
// }
|
||||
|
||||
// public function assignAssetToUser(Request $request)
|
||||
// {
|
||||
// try {
|
||||
// $request->validate([
|
||||
// 'user_id' => 'required|exists:users,id',
|
||||
// 'asset_id' => 'required|uuid',
|
||||
// 'active' => 'required|boolean'
|
||||
// ]);
|
||||
|
||||
// $userId = $request->user_id;
|
||||
// $assetId = $request->asset_id;
|
||||
// $activeStatus = $request->active;
|
||||
|
||||
// $userAssetLink = UserAssetLink::where('user_id', $userId)
|
||||
// ->where('asset_id', $assetId)
|
||||
// ->first();
|
||||
|
||||
// if (!$userAssetLink) {
|
||||
// $userAssetLink = new UserAssetLink();
|
||||
// $userAssetLink->user_id = $userId;
|
||||
// $userAssetLink->asset_id = $assetId;
|
||||
// }
|
||||
|
||||
// $userAssetLink->active = $activeStatus;
|
||||
// $userAssetLink->save();
|
||||
|
||||
// $message = $activeStatus
|
||||
// ? 'Asset assigned to user successfully.'
|
||||
// : 'Asset unassigned from user.';
|
||||
|
||||
// Log::info($message, ['userId' => $userId, 'assetId' => $assetId]);
|
||||
|
||||
// return response()->json([
|
||||
// 'success' => true,
|
||||
// 'message' => $message,
|
||||
// 'data' => $userAssetLink
|
||||
// ], 200);
|
||||
// } catch (Exception $e) {
|
||||
// Log::error("Error assigning/unassigning asset: " . $e->getMessage());
|
||||
// return response()->json([
|
||||
// 'success' => false,
|
||||
// 'message' => 'Failed to assign or unassign asset to user',
|
||||
// 'error' => $e->getMessage()
|
||||
// ], 500);
|
||||
// }
|
||||
// }
|
||||
public function assignAssetToUser(Request $request)
|
||||
{
|
||||
|
||||
try {
|
||||
$request->validate([
|
||||
'user_id' => 'required|exists:users,id',
|
||||
'asset_id' => 'required|uuid'
|
||||
'asset_id' => 'required|uuid',
|
||||
'active' => 'required|boolean'
|
||||
]);
|
||||
|
||||
$userId = $request->user_id;
|
||||
$assetId = $request->asset_id;
|
||||
$activeStatus = $request->active;
|
||||
|
||||
$userAssetLink = UserAssetLink::where('user_id', $userId)
|
||||
->where('asset_id', $assetId)
|
||||
->first();
|
||||
|
||||
if (!$userAssetLink) {
|
||||
$userAssetLink = new UserAssetLink();
|
||||
$userAssetLink->user_id = $userId;
|
||||
$userAssetLink->asset_id = $assetId;
|
||||
$userAssetLink->active = 1;
|
||||
$userAssetLink->save();
|
||||
|
||||
Log::info("Asset successfully assigned to user.", ['userId' => $userId, 'assetId' => $assetId]);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Asset assigned to user successfully.',
|
||||
'data' => $userAssetLink
|
||||
], 200);
|
||||
if ($activeStatus) {
|
||||
// If assigning asset, first unassign from any other users
|
||||
UserAssetLink::where('asset_id', $assetId)
|
||||
->update(['active' => 0]);
|
||||
}
|
||||
|
||||
if ($userAssetLink->active == 1) {
|
||||
$userAssetLink->active = 0;
|
||||
$userAssetLink->save();
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Asset unassigned from user.',
|
||||
'data' => $userAssetLink
|
||||
], 200);
|
||||
}
|
||||
// Now either update existing record or create a new one for this user and asset
|
||||
$userAssetLink = UserAssetLink::firstOrNew([
|
||||
'user_id' => $userId,
|
||||
'asset_id' => $assetId
|
||||
]);
|
||||
|
||||
$userAssetLink->active = 1;
|
||||
$userAssetLink->active = $activeStatus;
|
||||
$userAssetLink->save();
|
||||
|
||||
$message = $activeStatus
|
||||
? 'Asset assigned to user successfully.'
|
||||
: 'Asset unassigned from user.';
|
||||
|
||||
Log::info($message, ['userId' => $userId, 'assetId' => $assetId]);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Asset reassigned to user successfully.',
|
||||
'message' => $message,
|
||||
'data' => $userAssetLink
|
||||
], 200);
|
||||
} catch (Exception $e) {
|
||||
Log::error("Error assigning asset: " . $e->getMessage());
|
||||
Log::error("Error assigning/unassigning asset: " . $e->getMessage());
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Failed to assign or unassign asset to user',
|
||||
@@ -316,6 +476,8 @@ class AssetadmintController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function customerList()
|
||||
{
|
||||
try {
|
||||
@@ -331,22 +493,147 @@ class AssetadmintController extends Controller
|
||||
}
|
||||
|
||||
|
||||
// public function assestlistCustomer($customerId)
|
||||
// {
|
||||
// try {
|
||||
// $assets = Asset::with('customer:id,name')
|
||||
// ->where('customer_xid', $customerId)
|
||||
// ->get()
|
||||
// ->map(function ($asset) {
|
||||
// return collect($asset)
|
||||
// ->except('customer') // remove the full customer object
|
||||
// ->merge([
|
||||
// 'customer_name' => optional($asset->customer)->name,
|
||||
// ]);
|
||||
// });
|
||||
|
||||
// if ($assets->isEmpty()) {
|
||||
// return response()->json(['message' => 'No assets found for this customer ID'], 200);
|
||||
// }
|
||||
|
||||
// return jsonResponseWithSuccessMessage('Assets fetched successfully', [
|
||||
// 'assets' => $assets
|
||||
// ]);
|
||||
// } catch (Exception $e) {
|
||||
// Log::error("An error occurred in asset listing: " . $e->getMessage());
|
||||
// return jsonResponseWithErrorMessage($e->getMessage(), 500);
|
||||
// }
|
||||
// }
|
||||
|
||||
// public function assestlistCustomer($customerId)
|
||||
// {
|
||||
// try {
|
||||
// $assets = Asset::with([
|
||||
// 'customer:id,name',
|
||||
// 'userAssetLinks.user:id,name' // eager load user through userAssetLink
|
||||
// ])
|
||||
// ->where('customer_xid', $customerId)
|
||||
// ->get()
|
||||
// ->map(function ($asset) {
|
||||
// // Get user names linked to the asset
|
||||
// $userNames = $asset->userAssetLinks->map(function ($userAssetLink) {
|
||||
// return optional($userAssetLink->user)->name;
|
||||
// })->filter()->values(); // filter nulls and reset keys
|
||||
|
||||
// return collect($asset)
|
||||
// ->except('customer', 'userAssetLinks') // remove full objects
|
||||
// ->merge([
|
||||
// 'customer_name' => optional($asset->customer)->name,
|
||||
// 'assign_to_user' => $userNames, // attach user names
|
||||
// ]);
|
||||
// });
|
||||
|
||||
// if ($assets->isEmpty()) {
|
||||
// return response()->json(['message' => 'No assets found for this customer ID'], 200);
|
||||
// }
|
||||
|
||||
// return jsonResponseWithSuccessMessage('Assets fetched successfully', [
|
||||
// 'assets' => $assets
|
||||
// ]);
|
||||
// } catch (Exception $e) {
|
||||
// Log::error("An error occurred in asset listing: " . $e->getMessage());
|
||||
// return jsonResponseWithErrorMessage($e->getMessage(), 500);
|
||||
// }
|
||||
// }
|
||||
|
||||
// public function assestlistCustomer($customerId)
|
||||
// {
|
||||
// try {
|
||||
// $assets = Asset::with([
|
||||
// 'customer:id,name',
|
||||
// 'userAssetLinks.user:id,first_name,last_name' // eager load first_name and last_name
|
||||
// ])
|
||||
// ->where('customer_xid', $customerId)
|
||||
// ->get()
|
||||
// ->map(function ($asset) {
|
||||
// // Get user details (id and full name) linked to the asset
|
||||
// $assignToUsers = $asset->userAssetLinks->map(function ($userAssetLink) {
|
||||
// $user = $userAssetLink->user;
|
||||
// if ($user) {
|
||||
// return [
|
||||
// 'user_id' => $user->id,
|
||||
// 'full_name' => trim($user->first_name . ' ' . $user->last_name),
|
||||
// ];
|
||||
// }
|
||||
// return null;
|
||||
// })->filter()->values(); // filter nulls and reset keys
|
||||
|
||||
// return collect($asset)
|
||||
// ->except('customer', 'userAssetLinks') // remove full objects
|
||||
// ->merge([
|
||||
// 'customer_name' => optional($asset->customer)->name,
|
||||
// 'assign_to_users' => $assignToUsers, // attach user_id and full_name
|
||||
// ]);
|
||||
// });
|
||||
|
||||
// if ($assets->isEmpty()) {
|
||||
// return response()->json(['message' => 'No assets found for this customer ID'], 200);
|
||||
// }
|
||||
|
||||
// return jsonResponseWithSuccessMessage('Assets fetched successfully', [
|
||||
// 'assets' => $assets
|
||||
// ]);
|
||||
// } catch (Exception $e) {
|
||||
// Log::error("An error occurred in asset listing: " . $e->getMessage());
|
||||
// return jsonResponseWithErrorMessage($e->getMessage(), 500);
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
public function assestlistCustomer($customerId)
|
||||
{
|
||||
try {
|
||||
$assets = Asset::with('customer:id,name')
|
||||
$assets = Asset::with([
|
||||
'customer:id,name',
|
||||
'userAssetLinks' => function ($query) {
|
||||
$query->where('active', 1) // Only active links
|
||||
->with('user:id,first_name,last_name'); // Eager load user
|
||||
}
|
||||
])
|
||||
->where('customer_xid', $customerId)
|
||||
->get()
|
||||
->map(function ($asset) {
|
||||
// Since only active userAssetLinks are fetched, take the first one (only one user per asset)
|
||||
$assignToUser = $asset->userAssetLinks->first(); // get first active link if exists
|
||||
|
||||
$userDetails = null;
|
||||
if ($assignToUser && $assignToUser->user) {
|
||||
$userDetails = [
|
||||
'user_id' => $assignToUser->user->id,
|
||||
'full_name' => trim($assignToUser->user->first_name . ' ' . $assignToUser->user->last_name),
|
||||
];
|
||||
}
|
||||
|
||||
return collect($asset)
|
||||
->except('customer') // remove the full customer object
|
||||
->except('customer', 'userAssetLinks') // remove full objects
|
||||
->merge([
|
||||
'customer_name' => optional($asset->customer)->name,
|
||||
'assign_to_user' => $userDetails, // assign only one user
|
||||
]);
|
||||
});
|
||||
|
||||
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', [
|
||||
|
||||
@@ -47,6 +47,7 @@ class DeviceController extends Controller
|
||||
]
|
||||
],
|
||||
'deviceProfileId' => $request->deviceProfileId ?? 1,
|
||||
'asset_id' => $request->asset_id ?? 'null',
|
||||
|
||||
];
|
||||
|
||||
@@ -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 ?? 'null',
|
||||
'device_profile_id' => $apiResponse['deviceProfileId']['id'] ?? null,
|
||||
'firmware_id' => $apiResponse['firmwareId']['id'] ?? null,
|
||||
'software_id' => $apiResponse['softwareId']['id'] ?? null,
|
||||
@@ -197,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', [
|
||||
|
||||
@@ -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',
|
||||
// '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',
|
||||
// 'phone' => 'nullable|string|max:20',
|
||||
// 'name' => 'nullable|string|max:255',
|
||||
// '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,
|
||||
'authority' => $request->authority ?? 'CUSTOMER_USER',
|
||||
'tenant_id' => $request->tenant_id ?? null,
|
||||
'customer_id' => $request->customer_id ?? null,
|
||||
'first_name' => $request->first_name ?? '',
|
||||
'last_name' => $request->last_name ?? '',
|
||||
'phone' => $request->phone ?? null,
|
||||
'name' => $request->name ?? "{$request->first_name} {$request->last_name}",
|
||||
'description' => $request->description,
|
||||
'default_dashboard_id' => $request->default_dashboard_id,
|
||||
'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,
|
||||
@@ -266,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
|
||||
];
|
||||
|
||||
@@ -294,13 +295,14 @@ class UsersController extends Controller
|
||||
$activationLink = url("/apia/activate/{$userId}?token={$randomToken}");
|
||||
|
||||
// Send activation email
|
||||
Mail::to($user->email)->queue(new UserCreatedMail($user, $activationLink));
|
||||
Mail::to($user->email)->send(new UserCreatedMail($user, $activationLink));
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'User created successfully',
|
||||
'data' => [
|
||||
'user_id' => $userId,
|
||||
'token'=>$randomToken,
|
||||
'activation_link' => $activationLink,
|
||||
'external_service_response' => $serviceResponse
|
||||
]
|
||||
@@ -403,6 +405,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());
|
||||
@@ -432,28 +506,30 @@ 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);
|
||||
}
|
||||
|
||||
@@ -463,7 +539,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([
|
||||
@@ -478,7 +553,6 @@ class UsersController extends Controller
|
||||
|
||||
|
||||
|
||||
|
||||
// public function autoLogin(Request $request)
|
||||
// {
|
||||
// $request->validate([
|
||||
@@ -588,7 +662,6 @@ class UsersController extends Controller
|
||||
$localResponse = null;
|
||||
$thingsboardResponse = null;
|
||||
|
||||
// ✅ Check in Local database
|
||||
$user = User::where('email', $email)->first();
|
||||
|
||||
if ($user) {
|
||||
@@ -615,6 +688,9 @@ class UsersController extends Controller
|
||||
], 200);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public function userlistCustomer(Request $request)
|
||||
{
|
||||
try {
|
||||
@@ -668,7 +744,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', [
|
||||
@@ -679,5 +755,4 @@ class UsersController extends Controller
|
||||
return jsonResponseWithErrorMessage($e->getMessage(), 500);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
|
||||
];
|
||||
@@ -108,7 +108,7 @@ class AlarmControllerCommon extends Controller
|
||||
public function acknowledgeAlarmById($id)
|
||||
{
|
||||
try {
|
||||
$token = app('App\Services\AdminService')->getToken(); // Fetch cached token
|
||||
$token = app('App\Services\AdminService')->getToken(); // Fetch cached token0
|
||||
$url = env('THINGSBOARD_URL') . "/api/alarm/{$id}";
|
||||
|
||||
$getResponse = Http::withHeaders([
|
||||
@@ -149,6 +149,8 @@ class AlarmControllerCommon extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
return jsonResponseWithErrorMessage('Failed to acknowledge alarm: ' . $ackResponse->body(), $ackResponse->status());
|
||||
} catch (\Exception $e) {
|
||||
return jsonResponseWithErrorMessage('An error occurred: ' . $e->getMessage(), 500);
|
||||
@@ -200,6 +202,7 @@ class AlarmControllerCommon extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
return jsonResponseWithErrorMessage('Failed to clear alarm: ' . $clearResponse->body(), $clearResponse->status());
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Error clearing alarm: ' . $e->getMessage());
|
||||
@@ -212,8 +215,6 @@ class AlarmControllerCommon extends Controller
|
||||
public function filterAlarm(Request $request)
|
||||
{
|
||||
try {
|
||||
$token = readHeaderToken();
|
||||
$useId = $token['sub'];
|
||||
|
||||
$alarmData = $request->only([
|
||||
'severity',
|
||||
@@ -222,10 +223,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) {
|
||||
|
||||
@@ -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',
|
||||
|
||||
|
||||
@@ -62,6 +62,8 @@ class Asset extends Model
|
||||
{
|
||||
return $this->hasMany(Device::class, 'asset_id', 'id');
|
||||
}
|
||||
|
||||
|
||||
public function userAssetLinks()
|
||||
{
|
||||
return $this->hasMany(UserAssetLink::class, 'asset_id', 'id');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ class AdminService
|
||||
// throw new Exception('Failed to create asset: ' . $response->body());
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
// public function createAsset(array $data)
|
||||
// {
|
||||
// $token = $this->getToken();
|
||||
@@ -141,7 +141,8 @@ class AdminService
|
||||
'type' => $data['type'],
|
||||
'label' => $data['label'],
|
||||
// 'version' => removed to let backend default to 1
|
||||
'additionalInfo' => $data['additionalInfo'],
|
||||
// 'additionalInfo' => $data['additionalInfo'],
|
||||
'additionalInfo' => ['description' => $data['additionalInfo'] ?? 'User description'],
|
||||
];
|
||||
|
||||
$response = Http::withHeaders([
|
||||
@@ -159,37 +160,6 @@ class AdminService
|
||||
}
|
||||
}
|
||||
|
||||
// public function createAsset(array $data)
|
||||
// {
|
||||
// $token = $this->getToken();
|
||||
|
||||
// $payload = [
|
||||
// 'entityType' => $data['entity_type'],
|
||||
// 'createdTime' => $data['createdTime'],
|
||||
// 'customerId' => [
|
||||
// 'id' => $data['customerId'],
|
||||
// 'entityType' => 'CUSTOMER'
|
||||
// ],
|
||||
// 'name' => $data['name'],
|
||||
// 'type' => $data['type'],
|
||||
// 'label' => $data['label'],
|
||||
// 'additionalInfo' => $data['additionalInfo'], // must be an array
|
||||
// ];
|
||||
|
||||
// $response = Http::withHeaders([
|
||||
// 'Authorization' => "Bearer $token",
|
||||
// 'Accept' => 'application/json',
|
||||
// 'Content-Type' => 'application/json',
|
||||
// ])->withBody(json_encode($payload), 'application/json')
|
||||
// ->post("{$this->baseUrl}/api/asset");
|
||||
|
||||
// if ($response->successful()) {
|
||||
// return $response->json();
|
||||
// } else {
|
||||
// Log::error('Error in creating asset: ' . $response->body());
|
||||
// throw new Exception('Failed to create asset: ' . $response->body());
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
|
||||
@@ -262,17 +232,20 @@ class AdminService
|
||||
if (!isset($data['tenant_id'])) {
|
||||
throw new \Exception('tenant_id is required');
|
||||
}
|
||||
$randomNumber = rand(1000, 9999);
|
||||
$email = "dummy{$randomNumber}@example.com";
|
||||
|
||||
// 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'] ?? '',
|
||||
'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' => [
|
||||
@@ -489,28 +462,89 @@ 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 {
|
||||
$payload = [
|
||||
// $dummyEmail = 'dummy+' . $user->id . '@example.com';
|
||||
$token = $this->getToken();
|
||||
|
||||
// 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
|
||||
'password' => $password,
|
||||
// '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 successfully in ThingsBoard 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -313,16 +313,14 @@ class AlarmService
|
||||
}
|
||||
|
||||
|
||||
public function filterAlarm(array $data, $useId)
|
||||
public function filterAlarm(array $data)
|
||||
{
|
||||
$token = $this->getToken();
|
||||
|
||||
$deviceId = null;
|
||||
|
||||
if (!empty($data['deviceId'])) {
|
||||
$deviceId = $data['deviceId'];
|
||||
}
|
||||
elseif (!empty($data['assetId'])) {
|
||||
} elseif (!empty($data['assetId'])) {
|
||||
$deviceId = Device::where('asset_id', $data['assetId'])->value('id');
|
||||
}
|
||||
|
||||
@@ -337,12 +335,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;
|
||||
});
|
||||
@@ -388,7 +386,7 @@ class AlarmService
|
||||
$payload = [
|
||||
'type' => $data['type'] ?? null,
|
||||
'severity' => $data['severity'] ?? null,
|
||||
'acknowledged' => $data['acknowledged'] ?? null,
|
||||
'acknowledged' => false,
|
||||
'cleared' => $data['cleared'] ?? Carbon::now()->timestamp,
|
||||
'startTs' => $data['startTs'] ?? Carbon::now()->timestamp,
|
||||
'endTs' => $data['endTs'] ?? Carbon::now()->timestamp,
|
||||
@@ -396,10 +394,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,
|
||||
|
||||
Reference in New Issue
Block a user