A free open source IT asset/license management system
Always run validation on checkin
Marcus Mooref932a4fc76a3
diff --git a/app/Http/Controllers/Api/ComponentsController.php b/app/Http/Controllers/Api/ComponentsController.phpindex cd1e31f961..0f594f5e75 100644--- a/app/Http/Controllers/Api/ComponentsController.php+++ b/app/Http/Controllers/Api/ComponentsController.php@@ -317,14 +317,12 @@ class ComponentsController extends Controller$max_to_checkin = $component_assets->assigned_qty;- if ($max_to_checkin > 1) {- $validator = Validator::make($request->all(), [- "checkin_qty" => "required|numeric|between:1,$max_to_checkin"- ]);-- if ($validator->fails()) {- return response()->json(Helper::formatStandardApiResponse('error', null, 'Checkin quantity must be between 1 and '.$max_to_checkin));- }+ $validator = Validator::make($request->all(), [+ "checkin_qty" => "required|numeric|between:1,$max_to_checkin"+ ]);++ if ($validator->fails()) {+ return response()->json(Helper::formatStandardApiResponse('error', null, 'Checkin quantity must be between 1 and ' . $max_to_checkin));}// Validation passed, so let's figure out what we have to do here.diff --git a/tests/Feature/Checkins/Api/ComponentCheckinTest.php b/tests/Feature/Checkins/Api/ComponentCheckinTest.phpindex 845ed8acca..0497a8135c 100644--- a/tests/Feature/Checkins/Api/ComponentCheckinTest.php+++ b/tests/Feature/Checkins/Api/ComponentCheckinTest.php@@ -52,7 +52,7 @@ class ComponentCheckinTest extends TestCase implements TestsFullMultipleCompanie$component = Component::factory()->checkedOutToAsset()->create();$pivot = $component->assets->first()->pivot;- $pivot->update(['assigned_qty' => 2]);+ $pivot->update(['assigned_qty' => 1]);$this->actingAsForApi(User::factory()->checkinComponents()->create())->postJson(route('api.components.checkin', $component->assets->first()->pivot->id), [