From ea7f7fd9f381041b92132374754adb3866f16cff Mon Sep 17 00:00:00 2001 From: Maurice Date: Wed, 17 Jun 2026 22:32:03 +0200 Subject: [PATCH] fix(planner): derive a booking day from its date when none is set (#1237) The client always sends day_id on a reservation update, so the server only derived it from reservation_time when the field was absent. A non-transport booking saved without a selected day (Book tab) therefore got day_id null and vanished from the Plan, even though its date matched a day. Derive the day from reservation_time whenever day_id is null, mirroring create. --- server/src/services/reservationService.ts | 15 +++++++++++---- server/tests/integration/reservations.test.ts | 15 +++++++++++++++ 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/server/src/services/reservationService.ts b/server/src/services/reservationService.ts index 5385c6a9..4084220e 100644 --- a/server/src/services/reservationService.ts +++ b/server/src/services/reservationService.ts @@ -364,12 +364,19 @@ export function updateReservation(id: string | number, tripId: string | number, // otherwise derive from the (possibly updated) reservation_time so the // planner renders the booking on the correct day. let nextDayId: number | null; - if (day_id !== undefined) { - nextDayId = day_id || null; - } else if (reservation_time !== undefined && resolvedType !== 'hotel') { + if (day_id != null) { + // Explicit day from the client (e.g. moved on the planner). + nextDayId = day_id; + } else if (resolvedType !== 'hotel' && nextReservationTime) { + // No day set but we have a date — pin it to the matching day so the booking + // still shows in the Plan (covers bookings saved without a selected day, and + // the case where an earlier edit cleared day_id). nextDayId = resolveDayIdFromTime(tripId, nextReservationTime); - } else { + } else if (day_id === undefined) { + // Field absent and nothing to derive from — keep whatever it had. nextDayId = current.day_id ?? null; + } else { + nextDayId = null; } let nextEndDayId: number | null; diff --git a/server/tests/integration/reservations.test.ts b/server/tests/integration/reservations.test.ts index b86a28d5..9ff7fcc4 100644 --- a/server/tests/integration/reservations.test.ts +++ b/server/tests/integration/reservations.test.ts @@ -185,6 +185,21 @@ describe('Update reservation', () => { expect(res.body.reservation.confirmation_number).toBe('ABC123'); }); + it('RESV-004b — PUT with day_id null derives day_id from reservation_time so it stays in the Plan (#1237)', async () => { + const { user } = createUser(testDb); + const trip = createTrip(testDb, user.id); + createDay(testDb, trip.id, { date: '2025-09-01' }); + const day2 = createDay(testDb, trip.id, { date: '2025-09-02' }); + const resv = createReservation(testDb, trip.id, { title: 'Event', type: 'event' }); + + const res = await request(app) + .put(`/api/trips/${trip.id}/reservations/${resv.id}`) + .set('Cookie', authCookie(user.id)) + .send({ title: 'Event', type: 'event', day_id: null, reservation_time: '2025-09-02' }); + expect(res.status).toBe(200); + expect(res.body.reservation.day_id).toBe(day2.id); + }); + it('RESV-004 — PUT on non-existent reservation returns 404', async () => { const { user } = createUser(testDb); const trip = createTrip(testDb, user.id);