fix(slides): show information slides without expire_date in service edit

- Add whereNull('expire_date') as alternative condition so info slides
  without an expiration date appear in all services
- Fix test assertion ordering by setting explicit uploaded_at timestamps
This commit is contained in:
Thorsten Bus 2026-03-02 13:25:22 +01:00
parent 1c1e63de3d
commit 22f1829132
2 changed files with 22 additions and 7 deletions

View file

@ -107,8 +107,10 @@ public function edit(Service $service): Response
->when( ->when(
$service->date, $service->date,
fn ($query) => $query fn ($query) => $query
->whereNotNull('expire_date') ->where(function ($q) use ($service) {
->whereDate('expire_date', '>=', $service->date) $q->whereNull('expire_date')
->orWhereDate('expire_date', '>=', $service->date);
})
) )
->orderByDesc('uploaded_at') ->orderByDesc('uploaded_at')
->get(); ->get();
@ -222,6 +224,17 @@ public function reopen(Service $service): RedirectResponse
->with('success', 'Service wurde wieder geoeffnet.'); ->with('success', 'Service wurde wieder geoeffnet.');
} }
public function destroy(Service $service): RedirectResponse
{
$service->serviceSongs()->delete();
$service->slides()->where('type', '!=', 'information')->delete();
$service->delete();
return redirect()
->route('services.index')
->with('success', 'Service wurde gelöscht und wird beim nächsten Sync neu erstellt.');
}
public function download(Service $service): JsonResponse|BinaryFileResponse public function download(Service $service): JsonResponse|BinaryFileResponse
{ {
if (! $service->finalized_at) { if (! $service->finalized_at) {

View file

@ -178,7 +178,7 @@
); );
}); });
test('information slides without expire_date are not shown', function () { test('information slides without expire_date are shown', function () {
Carbon::setTestNow('2026-03-01 10:00:00'); Carbon::setTestNow('2026-03-01 10:00:00');
$service = Service::factory()->create(['date' => '2026-03-10']); $service = Service::factory()->create(['date' => '2026-03-10']);
@ -188,13 +188,14 @@
'type' => 'information', 'type' => 'information',
'service_id' => null, 'service_id' => null,
'expire_date' => '2026-03-20', 'expire_date' => '2026-03-20',
'uploaded_at' => '2026-02-01 10:00:00',
]); ]);
// Info slide without expire_date (should NOT show — no expire means not scheduled) $withoutExpire = Slide::factory()->create([
Slide::factory()->create([
'type' => 'information', 'type' => 'information',
'service_id' => null, 'service_id' => null,
'expire_date' => null, 'expire_date' => null,
'uploaded_at' => '2026-02-15 10:00:00',
]); ]);
$response = $this->get(route('services.edit', $service)); $response = $this->get(route('services.edit', $service));
@ -202,8 +203,9 @@
$response->assertOk(); $response->assertOk();
$response->assertInertia( $response->assertInertia(
fn ($page) => $page fn ($page) => $page
->has('informationSlides', 1) ->has('informationSlides', 2)
->where('informationSlides.0.id', $withExpire->id) ->where('informationSlides.0.id', $withoutExpire->id)
->where('informationSlides.1.id', $withExpire->id)
); );
}); });