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);