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.
This commit is contained in:
spencerrlongg 2024-11-20 13:11:03 -06:00
parent 03d9f936ab
commit 617fe85699
3 changed files with 15 additions and 9 deletions

View file

@ -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);
}

View file

@ -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'));
}
}

View file

@ -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;