feat(accommodations): put a booked night on its check-in day

A road-trip stop is a day assignment: the rail, the server-side plan and the
map all build their stops from day_assignments and only look the stay up
afterwards, to hang check-in and check-out on one. A stay written without an
assignment was therefore invisible to every routing surface, so a hotel entered
in the day planner never reached the road-trip view and had to be entered a
second time as an ordinary place. The road-trip side has always written both
halves in one go; this is the day planner catching up, in the domain that
writes the stay.

Booking a night now also assigns its place to the check-in day, inside the
transaction that already writes the stay and its partner hotel reservation, and
types the place as a hotel stop when it carries no type of its own, so it reads
exactly like a night booked in the road trip. Only the check-in day gets a
stop; the later nights ride on the stay row. A place already planned for that
day gets no second stop and the booking claims none, so cancelling it cannot
delete a stop somebody placed by hand. Moving the booking moves its own stop,
deleting it takes its own stop back, and a trip re-date carries it along with
the stay. All four write surfaces (REST, plugin RPC and both MCP tools) run the
same write and announce the same events; the answers carry the stop too,
because the broadcast skips the socket that sent the request.

New nullable day_assignments.accommodation_id marks a stop as a booking's own.
It stays NULL for every existing row on purpose: everything planned before this
was planned by hand, and no backfill rewrites a finished trip. A stay booked
earlier picks up its stop the next time somebody saves it.

The booking form keeps writing stays on its own: that surface is gated on
reservation_edit and the day stop is day_edit work.
This commit is contained in:
Maurice
2026-09-13 01:13:25 +02:00
parent 3ab5ddaacc
commit f0e1da2d81
19 changed files with 628 additions and 83 deletions
+24
View File
@@ -170,6 +170,30 @@ describe('Reservations + accommodations e2e (real auth guard + temp SQLite, real
expect(badRefs.body).toEqual({ error: 'Place not found' });
});
it('201 create also puts the place on its check-in day, and the delete takes that stop back', async () => {
// The road-trip view builds its stops from day_assignments and only looks the stay
// up afterwards, so a booking without one never reaches the route: the complaint
// was having to enter the same hotel a second time as an ordinary place.
const placeId = Number(db.prepare('INSERT INTO places (trip_id, name) VALUES (?, ?)').run(tripId, 'Hotel Adlon').lastInsertRowid);
const dayId = Number(db.prepare('INSERT INTO days (trip_id, day_number, date) VALUES (?, 4, ?)').run(tripId, '2026-03-04').lastInsertRowid);
const create = await request(server)
.post(`/api/trips/${tripId}/accommodations`)
.set('Cookie', sessionCookie(1))
.send({ place_id: placeId, start_day_id: dayId, end_day_id: dayId });
expect(create.status).toBe(201);
// In the answer, not only on the socket: the broadcast skips the sender.
expect(create.body.assignment).toMatchObject({ day_id: dayId, place_id: placeId });
expect(db.prepare('SELECT stop_type FROM places WHERE id = ?').get(placeId)).toMatchObject({ stop_type: 'hotel' });
const del = await request(server)
.delete(`/api/trips/${tripId}/accommodations/${create.body.accommodation.id}`)
.set('Cookie', sessionCookie(1));
expect(del.status).toBe(200);
expect(del.body.removedAssignments).toEqual([{ id: create.body.assignment.id, dayId }]);
expect(db.prepare('SELECT id FROM day_assignments WHERE day_id = ?').all(dayId)).toEqual([]);
});
it('404 when trip not accessible (accommodations)', async () => {
canAccessTrip.mockReturnValue(undefined);
const res = await request(server).get(`/api/trips/${tripId}/accommodations`).set('Cookie', sessionCookie(1));