a few fixes, tests pass

This commit is contained in:
spencerrlongg 2024-11-04 13:39:42 -06:00
parent b00f8b5c40
commit a57fffe696
4 changed files with 19 additions and 7 deletions

View file

@ -176,7 +176,7 @@ class StoreAssetAction
}
return $asset;
} else {
return $asset->getErrors();
dd($asset->getErrors()); //need to figure out how to return errors from watson validating...
}
}
}

View file

@ -8,5 +8,4 @@ class UpdateAssetAction
{
// stuff
}
}

View file

@ -117,7 +117,7 @@ class AssetsController extends Controller
model_id: $request->validated('model_id'),
status_id: $request->validated('status_id'),
name: $request->validated('name'),
serial: $serials[$key],
serial: $request->has('serials') ? $serials[$key] : null,
company_id: $request->validated('company_id'),
asset_tag: $asset_tag,
order_number: $request->validated('order_number'),
@ -138,7 +138,7 @@ class AssetsController extends Controller
assigned_asset: $request->validated('assigned_asset'),
assigned_location: $request->validated('assigned_location'),
custom_fields: $custom_fields,
request: $request, //this is just for the handleImages method...
request: $request, //this is just for the handleImages method... would love to figure out a different way of doing this
last_audit_date: $request->validated('last_audit_date'),
);
}
@ -149,7 +149,9 @@ class AssetsController extends Controller
} catch (CheckoutNotAllowed $e) {
return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.create.error'));
} catch (\Exception $e) {
return redirect()->back()->with('error', trans('admin/hardware/message.create.error'));
report($e);
dd($e);
return redirect()->back()->with('error', 'something bad');
}
}

View file

@ -37,8 +37,10 @@ class StoreAssetRequest extends ImageUploadRequest
$this->parseLastAuditDate();
$asset_tag = $this->parseAssetTag();
$this->merge([
'asset_tag' => $this->asset_tag ?? Asset::autoincrement_asset(),
'asset_tag' => $asset_tag,
'company_id' => $idForCurrentUser,
'assigned_to' => $assigned_to ?? null,
]);
@ -61,7 +63,6 @@ class StoreAssetRequest extends ImageUploadRequest
// converted to a float via setPurchaseCostAttribute).
$modelRules = $this->removeNumericRulesFromPurchaseCost($modelRules);
}
return array_merge(
$modelRules,
['status_id' => [new AssetCannotBeCheckedOutToNondeployableStatus()]],
@ -101,4 +102,14 @@ class StoreAssetRequest extends ImageUploadRequest
return $rules;
}
private function parseAssetTag(): mixed
{
// this is for a gui request to make the request pass validation
// this just checks the first asset tag from the gui, watson should pick up if any of the rest of them fail
if ($this->has('asset_tags') && !$this->expectsJson()) {
return $this->input('asset_tags')[1];
}
return $this->asset_tag ?? Asset::autoincrement_asset();
}
}