mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-22 13:10:29 +00:00
fix(reservations): keep day_id on partial updates of time-only bookings
A partial update that left day_id out (a notes-only PUT, an MCP update_reservation or update_transport call) re-derived the day from the stored reservation_time whenever one was set. A time-only value such as "12:00" resolves to no day, so the booking's day_id was written as null and it vanished from its day in the planner. The end_day_id branch did the same when a time-only reservation_end_time was sent. The day is now derived only when the time carries a date that resolves to a trip day; otherwise an omitted day_id or end_day_id keeps the stored value. A dated time still re-pins the day, an explicit day_id null still clears it, and a cleared end time still clears end_day_id. REST and both MCP update tools share updateInTx, so the fix covers all three. Tests: service unit cases (RESV-SVC-044..048), an e2e case per behaviour on PUT /api/trips/:tripId/reservations/:id, and an update_reservation MCP case, all seeded with the ORM factories. Fixes #3025
This commit is contained in:
@@ -132,7 +132,7 @@ export interface UpdateReservationData {
|
||||
confirmation_number?: string;
|
||||
notes?: string;
|
||||
url?: string;
|
||||
day_id?: number;
|
||||
day_id?: number | null;
|
||||
end_day_id?: number | null;
|
||||
place_id?: number;
|
||||
assignment_id?: number;
|
||||
@@ -944,32 +944,23 @@ export class ReservationsService {
|
||||
? null
|
||||
: (reservation_end_time !== undefined ? (reservation_end_time || null) : current.reservation_end_time);
|
||||
|
||||
// day_id / end_day_id: honour an explicit value from the client,
|
||||
// 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 != 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).
|
||||
// day_id / end_day_id: an explicit value from the client wins (e.g. moved on the
|
||||
// planner), and an explicit null clears. Otherwise a dated time pins the booking to
|
||||
// its day, which also covers one saved without a day or an earlier edit that cleared
|
||||
// it. A time-only value ("12:00") names no day, so an update that leaves the field
|
||||
// out keeps the stored day rather than reading the miss as "clear it".
|
||||
let nextDayId: number | null = day_id ?? null;
|
||||
if (day_id == null && resolvedType !== 'hotel') {
|
||||
nextDayId = await this.resolveDayIdFromTime(tripId, nextReservationTime);
|
||||
} else if (day_id === undefined) {
|
||||
// Field absent and nothing to derive from — keep whatever it had.
|
||||
nextDayId = current.day_id ?? null;
|
||||
} else {
|
||||
nextDayId = null;
|
||||
}
|
||||
if (nextDayId == null && day_id === undefined) nextDayId = current.day_id ?? null;
|
||||
|
||||
let nextEndDayId: number | null;
|
||||
if (end_day_id !== undefined) {
|
||||
nextEndDayId = end_day_id ?? null;
|
||||
} else if (reservation_end_time !== undefined && resolvedType !== 'hotel') {
|
||||
nextEndDayId = await this.resolveDayIdFromTime(tripId, nextReservationEndTime);
|
||||
} else {
|
||||
nextEndDayId = current.end_day_id ?? null;
|
||||
let nextEndDayId: number | null = end_day_id === undefined ? (current.end_day_id ?? null) : end_day_id;
|
||||
if (end_day_id === undefined && reservation_end_time !== undefined && resolvedType !== 'hotel') {
|
||||
// A cleared end time clears the end day; a new one moves it unless it is time-only.
|
||||
nextEndDayId = nextReservationEndTime
|
||||
? ((await this.resolveDayIdFromTime(tripId, nextReservationEndTime)) ?? nextEndDayId)
|
||||
: null;
|
||||
}
|
||||
|
||||
nextDayId = await this.resolvedOrNull('days', nextDayId);
|
||||
|
||||
Reference in New Issue
Block a user