mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-05 02:14:05 +00:00
fix(accommodations): a booking that moves carries its stop instead of rebuilding it
Correcting a booking's date deleted the day stop it had mirrored and inserted a fresh one. A day stop is not just a day and a place: its participants and any road-trip day boundary hang off its id by ON DELETE CASCADE, and its note, its hour and its end-of-day flag live in its own columns. All of it went, silently, for an edit that only meant to move the night one day on. The row is carried across now, seated by its check-in the same way an insert would be, and the delete-and-insert is kept only for the case where the target day already holds that place under a stop of the traveller's own. Three more holes in the same mirror, found alongside it: Dropping a night while keeping the place cleared accommodation_id server side and told nobody. Days hides a stop that carries a booking id, so on every other screen the place stayed invisible on a day it was standing on. A night is seated by its check-in, which renumbers the stops around it, and nothing said so. The day that changed now sends its order along. Deleting a place cancelled the nights booked there, which takes each night's partner booking and that booking's expense with it, and announced neither. The Bookings list kept the reservation and the Costs total kept the money until a reload, and an expense linked by reservation_id is not one the place-linked sweep finds. Also: day_assignments.accommodation_id went in as a bare INTEGER, so shortening a trip past a booking's last night cascaded the booking away and left the stop pointing at nothing, hidden from Days for good while the route still drove to it. Migration 234 clears the ones already out there and adds a trigger, which SQLite fires even when the booking went down with a cascade. And a duplicated trip now carries the stop's booking id, the booking's check-in window and a place's fill_percent, none of which the copy took along.
This commit is contained in:
@@ -4,6 +4,10 @@ import type { Assignment } from '../types'
|
||||
/** The day-plan half of what an accommodation write answers with. */
|
||||
export interface StayStopsResult {
|
||||
assignment?: Assignment | null
|
||||
/** The booking's own stop, carried to the day the booking now covers. */
|
||||
movedAssignment?: { assignment: Assignment; oldDayId: number } | null
|
||||
/** Stops the booking let go of but left standing (a night dropped, the place kept). */
|
||||
updatedAssignments?: Assignment[]
|
||||
removedAssignments?: { id: number; dayId: number }[]
|
||||
}
|
||||
|
||||
@@ -24,4 +28,11 @@ export function applyStayStops(result: StayStopsResult | null | undefined): void
|
||||
handleRemoteEvent({ type: 'assignment:deleted', assignmentId: removed.id, dayId: removed.dayId })
|
||||
}
|
||||
if (result.assignment) handleRemoteEvent({ type: 'assignment:created', assignment: result.assignment })
|
||||
if (result.movedAssignment) {
|
||||
const { assignment, oldDayId } = result.movedAssignment
|
||||
handleRemoteEvent({ type: 'assignment:moved', assignment, oldDayId, newDayId: assignment.day_id })
|
||||
}
|
||||
for (const updated of result.updatedAssignments ?? []) {
|
||||
handleRemoteEvent({ type: 'assignment:updated', assignment: updated })
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user