From 617fe8569984dbcba20019ab95b95fbd439bdc9e Mon Sep 17 00:00:00 2001 From: spencerrlongg Date: Wed, 20 Nov 2024 13:11:03 -0600 Subject: [PATCH] Fix typos and use correct array notation in asset updates Corrected spelling mistakes in test files and updated code to use the correct array notation in request validation for asset updates. This ensures better readability and consistency in the codebase while preventing potential errors related to incorrect data handling. --- app/Actions/Assets/UpdateAssetAction.php | 11 ++++++++--- app/Http/Controllers/Assets/AssetsController.php | 7 ++++--- tests/Feature/Assets/Ui/EditAssetTest.php | 6 +++--- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/app/Actions/Assets/UpdateAssetAction.php b/app/Actions/Assets/UpdateAssetAction.php index 10b3801ab8..e7b09fc7ee 100644 --- a/app/Actions/Assets/UpdateAssetAction.php +++ b/app/Actions/Assets/UpdateAssetAction.php @@ -104,13 +104,13 @@ class UpdateAssetAction $asset->rtd_location_id = $rtd_location_id ?? $asset->rtd_location_id; if ($request->has('model_id')) { - $asset->model()->associate(AssetModel::find($request->validated()['model_id'])); + $asset->model()->associate(AssetModel::find($request->validated('model_id'))); } if ($request->has('company_id')) { - $asset->company_id = Company::getIdForCurrentUser($request->validated()['company_id']); + $asset->company_id = Company::getIdForCurrentUser($request->validated('company_id')); } if ($request->has('rtd_location_id') && !$request->has('location_id')) { - $asset->location_id = $request->validated()['rtd_location_id']; + $asset->location_id = $request->validated('rtd_location_id'); } if ($request->input('last_audit_date')) { $asset->last_audit_date = Carbon::parse($request->input('last_audit_date'))->startOfDay()->format('Y-m-d H:i:s'); @@ -121,13 +121,17 @@ class UpdateAssetAction // This is a non-deployable status label - we should check the asset back in. if (($status && $status->getStatuslabelType() != 'deployable') && ($target = $asset->assignedTo)) { + dump('status logic'); $originalValues = $asset->getRawOriginal(); $asset->assigned_to = null; $asset->assigned_type = null; $asset->accepted = null; + dump($asset->assigned_to); event(new CheckoutableCheckedIn($asset, $target, auth()->user(), 'Checkin on asset update', date('Y-m-d H:i:s'), $originalValues)); + // reset this to null so checkout logic doesn't happen below + $target = null; } //this is causing an issue while setting location_id - this came from the gui but doesn't seem to work as expected in the api - @@ -239,6 +243,7 @@ class UpdateAssetAction } if (isset($target)) { + dump($target); $asset->checkOut($target, auth()->user(), date('Y-m-d H:i:s'), '', 'Checked out on asset update', e($request->get('name')), $location); } diff --git a/app/Http/Controllers/Assets/AssetsController.php b/app/Http/Controllers/Assets/AssetsController.php index 555174d9eb..cf460ab401 100755 --- a/app/Http/Controllers/Assets/AssetsController.php +++ b/app/Http/Controllers/Assets/AssetsController.php @@ -241,7 +241,7 @@ class AssetsController extends Controller $asset_tag = $request->input('asset_tags')[1]; } - $asset = UpdateAssetAction::run( + $updatedAsset = UpdateAssetAction::run( asset: $asset, request: $request, status_id: $request->validated('status_id'), @@ -264,13 +264,14 @@ class AssetsController extends Controller asset_tag: $asset_tag, // same as serials notes: $request->validated('notes'), ); - return redirect()->to(Helper::getRedirectOption($request, $asset->id, 'Assets')) + dump('returned'.$asset->assigned_to); + return redirect()->to(Helper::getRedirectOption($request, $updatedAsset->id, 'Assets')) ->with('success', trans('admin/hardware/message.update.success')); } catch (ValidationException $e) { return redirect()->back()->withInput()->withErrors($e->getErrors()); } catch (\Exception $e) { report($e); - return redirect()->back()->with('error', trans('admin/hardware/message.update.error'), $asset); + return redirect()->back()->with('error', trans('admin/hardware/message.update.error')); } } diff --git a/tests/Feature/Assets/Ui/EditAssetTest.php b/tests/Feature/Assets/Ui/EditAssetTest.php index 27f00b5313..ebe7bf9a97 100644 --- a/tests/Feature/Assets/Ui/EditAssetTest.php +++ b/tests/Feature/Assets/Ui/EditAssetTest.php @@ -74,7 +74,7 @@ class EditAssetTest extends TestCase $user = User::factory()->create(); $deployable_status = Statuslabel::factory()->rtd()->create(); - $achived_status = Statuslabel::factory()->archived()->create(); + $archived_status = Statuslabel::factory()->archived()->create(); $asset = Asset::factory()->assignedToUser($user)->create(['status_id' => $deployable_status->id]); $this->assertTrue($asset->assignedTo->is($user)); @@ -83,7 +83,7 @@ class EditAssetTest extends TestCase $this->actingAs(User::factory()->viewAssets()->editAssets()->create()) ->from(route('hardware.edit', $asset->id)) ->put(route('hardware.update', $asset->id), [ - 'status_id' => $achived_status->id, + 'status_id' => $archived_status->id, 'model_id' => $asset->model_id, 'asset_tags' => $asset->asset_tag, ], @@ -95,7 +95,7 @@ class EditAssetTest extends TestCase $asset = Asset::find($asset->id); $this->assertNull($asset->assigned_to); $this->assertNull($asset->assigned_type); - $this->assertEquals($achived_status->id, $asset->status_id); + $this->assertEquals($archived_status->id, $asset->status_id); Event::assertDispatched(function (CheckoutableCheckedIn $event) use ($currentTimestamp) { return Carbon::parse($event->action_date)->diffInSeconds($currentTimestamp) < 2;