Add Soft deletes to participants
continuous-integration/drone/push Build is failing Details

This commit is contained in:
philipp lang 2025-11-11 00:53:26 +01:00
parent 8b8f598507
commit 285662ba4f
5 changed files with 45 additions and 2 deletions

View File

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

View File

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

View File

@ -269,6 +269,15 @@ it('testItShowsPreventionState', function () {
->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])
->assertJsonCont('data', 0);
});
it('test it orders participants by value', function (array $values, array $sorting, array $expected) {
list($key, $direction) = $sorting;
$this->login()->loginNami()->withoutExceptionHandling();

View File

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