Add Soft deletes to participants

Fix tests
This commit is contained in:
philipp lang 2025-11-11 00:53:26 +01:00
parent f0ed9185ba
commit 8924774ed0
6 changed files with 46 additions and 3 deletions

View File

@ -15,7 +15,7 @@ class ParticipantDestroyAction
public function handle(int $participantId): void public function handle(int $participantId): void
{ {
Participant::findOrFail($participantId)->delete(); Participant::findOrFail($participantId)->update(['cancelled_at' => now()]);
} }
public function asController(Participant $participant): void public function asController(Participant $participant): void

View File

@ -54,6 +54,8 @@ class ParticipantFilterScope extends ScoutFilter
$filter->push('parent-id IS NULL'); $filter->push('parent-id IS NULL');
} }
$filter->push('cancelled_at IS NULL');
if ($this->parent !== null && $this->parent !== -1) { if ($this->parent !== null && $this->parent !== -1) {
$filter->push('parent-id = ' . $this->parent); $filter->push('parent-id = ' . $this->parent);
} }

View File

@ -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('participants', function (Blueprint $table) {
$table->datetime('cancelled_at')->nullable();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('participants', function (Blueprint $table) {
$table->dropColumn('cancelled_at');
});
}
};

@ -1 +1 @@
Subproject commit 7304963370ff64fb5accf08da4864981cc424301 Subproject commit f7b04591830ebdeaddf76236e4cbc87a8b3eec8f

View File

@ -269,6 +269,15 @@ it('testItShowsPreventionState', function () {
->assertJsonPath('data.0.prevention_items.0.tooltip', 'erweitertes Führungszeugnis nicht vorhanden'); ->assertJsonPath('data.0.prevention_items.0.tooltip', 'erweitertes Führungszeugnis nicht vorhanden');
}); });
it('doesnt show cancelled participants', function () {
$this->login()->loginNami()->withoutExceptionHandling();
$participant = Participant::factory()->for(Form::factory())->create(['cancelled_at' => now()]);
sleep(2);
$this->callFilter('form.participant.index', [], ['form' => $participant->form])
->assertJsonCount(0, 'data');
});
it('test it orders participants by value', function (array $values, array $sorting, array $expected) { it('test it orders participants by value', function (array $values, array $sorting, array $expected) {
list($key, $direction) = $sorting; list($key, $direction) = $sorting;
$this->login()->loginNami()->withoutExceptionHandling(); $this->login()->loginNami()->withoutExceptionHandling();

View File

@ -24,5 +24,9 @@ it('testItCanDestroyAParticipant', function () {
$this->deleteJson(route('participant.destroy', ['participant' => $form->participants->first()])) $this->deleteJson(route('participant.destroy', ['participant' => $form->participants->first()]))
->assertOk(); ->assertOk();
$this->assertDatabaseCount('participants', 0); $this->assertDatabaseCount('participants', 1);
$this->assertDatabaseHas('participants', [
'cancelled_at' => now(),
'id' => $form->participants->first()->id,
]);
}); });