Преглед изворни кода

refactor: remove 'active_students_medium' from various models, requests, and resources

alvesantos пре 3 дана
родитељ
комит
79281108da

+ 0 - 1
app/Http/Controllers/FranchiseeDashboardController.php

@@ -32,7 +32,6 @@ public function summary(): JsonResponse
             ],
             'unit_config' => [
                 'active_students_min' => $unit->active_students_min ?? 30,
-                'active_students_medium' => $unit->active_students_medium ?? 50,
                 'active_students_max' => $unit->active_students_max ?? 80,
             ],
             'contracts' => [

+ 2 - 2
app/Http/Controllers/StudentController.php

@@ -27,10 +27,10 @@ public function index(): JsonResponse
         return $this->successResponse(payload: StudentResource::collection($items));
     }
 
-    public function franchisorActive(): JsonResponse
+    public function franchisorStudents(): JsonResponse
     {
         $unitIds = array_filter((array) request()->input('unit_ids', []));
-        $items   = $this->service->getFranchisorActive($unitIds);
+        $items   = $this->service->getFranchisorStudents($unitIds);
         return $this->successResponse(payload: StudentResource::collection($items));
     }
 

+ 0 - 1
app/Http/Controllers/UnitController.php

@@ -73,7 +73,6 @@ public function updateMe(UnitRequest $request): JsonResponse
             'avatar',
             'automatic_protocol',
             'active_students_min',
-            'active_students_medium',
             'active_students_max'
         ]));
 

+ 0 - 1
app/Http/Requests/UnitRequest.php

@@ -32,7 +32,6 @@ public function rules(): array
             'cell_number'            => 'sometimes|required|string|max:20',
             'automatic_protocol'     => 'sometimes|boolean',
             'active_students_min'    => 'sometimes|integer|min:0',
-            'active_students_medium' => 'sometimes|integer|min:0',
             'active_students_max'    => 'sometimes|integer|min:0',
             'avatar'                 => 'sometimes|nullable|image|max:20480',
             'contracts'              => 'sometimes|nullable|array',

+ 0 - 1
app/Http/Resources/UnitResource.php

@@ -40,7 +40,6 @@ public function toArray(Request $request): array
             'automatic_protocol' => (bool) ($this->automatic_protocol ?? true),
 
             'active_students_min'    => (int) ($this->active_students_min ?? 30),
-            'active_students_medium' => (int) ($this->active_students_medium ?? 50),
             'active_students_max'    => (int) ($this->active_students_max ?? 80),
 
             'avatar_url' => $this->avatar_url

+ 0 - 1
app/Models/Unit.php

@@ -86,7 +86,6 @@ class Unit extends Model
     protected $casts = [
         'automatic_protocol'     => 'boolean',
         'active_students_min'    => 'integer',
-        'active_students_medium' => 'integer',
         'active_students_max'    => 'integer',
         'cnpj'                   => Cnpj::class,
         'created_at'             => 'datetime',

+ 1 - 2
app/Services/StudentService.php

@@ -136,10 +136,9 @@ public function delete(int $id): bool
 
     //
 
-    public function getFranchisorActive(array $unitIds = []): Collection
+    public function getFranchisorStudents(array $unitIds = []): Collection
     {
         return Student::with('unit')
-            ->whereHas('contracts', fn ($q) => $q->latestVersion()->where('status', 'active'))
             ->when(! empty($unitIds), fn ($q) => $q->whereIn('unit_id', $unitIds))
             ->orderBy('name')
             ->get();

+ 28 - 0
database/migrations/2026_09_09_154544_drop_active_students_medium_from_units_table.php

@@ -0,0 +1,28 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+    /**
+     * Run the migrations.
+     */
+    public function up(): void
+    {
+        Schema::table('units', function (Blueprint $table) {
+            $table->dropColumn('active_students_medium');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     */
+    public function down(): void
+    {
+        Schema::table('units', function (Blueprint $table) {
+            $table->integer('active_students_medium')->default(50)->after('active_students_min');
+        });
+    }
+};

+ 1 - 1
routes/authRoutes/dashboard_franchisor.php

@@ -27,7 +27,7 @@
 
 Route::controller(StudentController::class)->prefix('student')->group(function () {
     Route::get('/franchisor/summary', 'franchisorSummary')->middleware('permission:dashboard,view');
-    Route::get('/franchisor/active', 'franchisorActive')->middleware('permission:dashboard,view');
+    Route::get('/franchisor/students', 'franchisorStudents')->middleware('permission:dashboard,view');
     Route::get('/franchisor/{id}', 'franchisorStudentDetail')->middleware('permission:dashboard,view');
 });
 

+ 4 - 9
tests/Unit/UnitSettingsTest.php

@@ -17,28 +17,25 @@ public function test_unit_request_validates_active_students_ranges(): void
 
         $validValidator = Validator::make([
             'active_students_min' => 10,
-            'active_students_medium' => 40,
             'active_students_max' => 90,
         ], $rules);
-        
+
         $this->assertFalse($validValidator->errors()->has('active_students_min'));
-        $this->assertFalse($validValidator->errors()->has('active_students_medium'));
         $this->assertFalse($validValidator->errors()->has('active_students_max'));
 
         $invalidValidator = Validator::make([
             'active_students_min' => -5, // Below 0
-            'active_students_medium' => 'string', // Not an integer
+            'active_students_max' => 'string', // Not an integer
         ], $rules);
-        
+
         $this->assertTrue($invalidValidator->errors()->has('active_students_min'));
-        $this->assertTrue($invalidValidator->errors()->has('active_students_medium'));
+        $this->assertTrue($invalidValidator->errors()->has('active_students_max'));
     }
 
     public function test_unit_resource_includes_active_students_ranges(): void
     {
         $unit = current(array_filter([new class extends Unit {
             public $active_students_min = 25;
-            public $active_students_medium = 55;
             public $active_students_max = 85;
             public $name = 'Teste';
             public $social_reason = 'Teste';
@@ -48,11 +45,9 @@ public function test_unit_resource_includes_active_students_ranges(): void
         $array = $resource->toArray(Request::create('/'));
 
         $this->assertArrayHasKey('active_students_min', $array);
-        $this->assertArrayHasKey('active_students_medium', $array);
         $this->assertArrayHasKey('active_students_max', $array);
 
         $this->assertSame(25, $array['active_students_min']);
-        $this->assertSame(55, $array['active_students_medium']);
         $this->assertSame(85, $array['active_students_max']);
     }
 }