fix bracket, + overwrite required rulesets

This commit is contained in:
spencerrlongg 2024-04-23 16:29:07 -05:00
parent 53ccd196d7
commit b11c900a4c
2 changed files with 18 additions and 33 deletions

View file

@ -687,7 +687,6 @@ class AssetsController extends Controller
} }
} }
} }
}
if ($asset->save()) { if ($asset->save()) {
if (($request->filled('assigned_user')) && ($target = User::find($request->get('assigned_user')))) { if (($request->filled('assigned_user')) && ($target = User::find($request->get('assigned_user')))) {
@ -707,12 +706,12 @@ class AssetsController extends Controller
if ($asset->image) { if ($asset->image) {
$asset->image = $asset->getImageUrl(); $asset->image = $asset->getImageUrl();
}
if ($problems_updating_encrypted_custom_fields) { if ($problems_updating_encrypted_custom_fields) {
return response()->json(Helper::formatStandardApiResponse('success', $asset, trans('admin/hardware/message.update.encrypted_warning'))); return response()->json(Helper::formatStandardApiResponse('success', $asset, trans('admin/hardware/message.update.encrypted_warning')));
} else { } else {
return response()->json(Helper::formatStandardApiResponse('success', $asset, trans('admin/hardware/message.update.success'))); return response()->json(Helper::formatStandardApiResponse('success', $asset, trans('admin/hardware/message.update.success')));
}
} }
} }
return response()->json(Helper::formatStandardApiResponse('error', null, $asset->getErrors()), 200); return response()->json(Helper::formatStandardApiResponse('error', null, $asset->getErrors()), 200);

View file

@ -25,32 +25,18 @@ class UpdateAssetRequest extends ImageUploadRequest
*/ */
public function rules() public function rules()
{ {
$rules = array_merge([ $rules = array_merge(
'model_id' => ['integer', 'exists:models,id,deleted_at,NULL', 'not_array'], parent::rules(),
'status_id' => ['integer', 'exists:status_labels,id'], (new Asset)->getRules(),
'asset_tag' => ['min:1', 'max:255', 'not_array', Rule::unique('assets', 'asset_tag')->ignore($this->asset)->withoutTrashed()], // this is to overwrite rulesets that include required
'name' => ['nullable', 'max:255'], [
'company_id' => ['nullable', 'integer', 'exists:companies,id'], 'model_id' => ['integer', 'exists:models,id,deleted_at,NULL', 'not_array'],
'warranty_months' => ['nullable', 'numeric', 'digits_between:0,240'], 'status_id' => ['integer', 'exists:status_labels,id'],
'last_checkout' => ['nullable', 'date_format:Y-m-d H:i:s'], 'asset_tag' => [
'expected_checkin' => ['nullable', 'date'], 'min:1', 'max:255', 'not_array',
'last_audit_date' => 'nullable|date_format:Y-m-d H:i:s', Rule::unique('assets', 'asset_tag')->ignore($this->asset)->withoutTrashed()
'next_audit_date' => 'nullable|date|after:last_audit_date', ],
'location_id' => ['nullable', 'exists:locations,id'], ],
'rtd_location_id' => ['nullable', 'exists:locations,id'],
'purchase_date' => ['nullable', 'date', 'date_format:Y-m-d'],
'serial' => ['nullable', 'unique_undeleted:assets,serial'],
'purchase_cost' => ['nullable', 'numeric', 'gte:0'],
'supplier_id' => ['nullable', 'exists:suppliers,id'],
'asset_eol_date' => ['nullable', 'date'],
'eol_explicit' => ['nullable', 'boolean'],
'byod' => ['nullable', 'boolean'],
'order_number' => ['nullable', 'string', 'max:191'],
'notes' => ['nullable', 'string', 'max:65535'],
'assigned_to' => ['nullable', 'integer'],
'requestable' => ['nullable', 'boolean'],
],
parent::rules()
); );
return $rules; return $rules;
} }