sayliR #79

Merged
Sayli.Raut merged 3 commits from sayliR into main 2025-04-15 05:27:13 +00:00
2 changed files with 7 additions and 14 deletions

View File

@@ -31,7 +31,6 @@ class AssetadmintController extends Controller
$additionalInfo = $request->has('additional_info') && is_string($request->additional_info)
? json_decode($request->additional_info, true)
: $request->additional_info;
$assetData = [
'entity_type' => $request->entity_type,
'createdTime' => $request->created_time ?? now()->timestamp,
@@ -45,13 +44,10 @@ class AssetadmintController extends Controller
'version' => $request->version ?? '1.0',
'additionalInfo' => $additionalInfo ?? ['description' => 'Default asset description'],
];
$response = $this->adminService->createAsset($assetData);
if (!$response) {
throw new Exception('Failed to create asset via admin service');
throw new \Exception('Failed to create asset via admin service');
}
$asset = new Asset();
$asset->id = $response['id']['id'] ?? Str::uuid()->toString();
$asset->entity_type = $response['entityType'] ?? $assetData['entity_type'];
@@ -65,15 +61,16 @@ class AssetadmintController extends Controller
$asset->external_id = $assetData['externalId'];
$asset->version = $response['version'] ?? $assetData['version'];
$asset->additional_info = json_encode($response['additionalInfo'] ?? $assetData['additionalInfo']);
$asset->save();
// Fetch only the customer name
$customerName = \App\Models\Customer::where('id', $asset->customer_xid)->value('name');
return response()->json([
'message' => 'Asset created successfully!',
'data' => $asset,
'api_response' => $response
'customer_name' => $customerName,
// 'api_response' => $response
], 200);
} catch (Exception $e) {
} catch (\Exception $e) {
Log::error('Error in creating asset: ' . $e->getMessage());
return response()->json(['error' => $e->getMessage()], 500);
}
@@ -238,8 +235,4 @@ class AssetadmintController extends Controller
return jsonResponseWithErrorMessage($e->getMessage(), 500);
}
}
}

View File

@@ -29,7 +29,7 @@ return new class extends Migration
$table->uuid('external_id')->nullable();
$table->integer('version')->default(1);
$table->json('additional_info')->nullable();
$table->bigInteger('country_xid')->nullable();
$table->longText('country_xid')->nullable();
$table->longText('state_xid')->nullable();
$table->longText('city_xid')->nullable();