mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-28 07:30:04 +00:00
@
fix(dashboard): fix the upcoming widget dropping bookings, and give it the stays back Three things, all in the same widget. reservation_time holds two shapes. The booking form writes the datetime-local YYYY-MM-DDTHH:MM; day-anchored rows, the demo seed among them, hold a bare HH:MM. The query compared the column against an ISO timestamp as a string, where ":" sorts above "2": every booking from 20:00 on passed the filter and everything before it silently vanished, and the order ran off the same column. On the demo that is why the Broadway show shows and the ferry does not. The query now separates the date from the time before it filters, so a value with no date falls back to the day it hangs off instead of being read as one, and the order is by day and clock. The demo seed writes full timestamps, which is the shape every real write path already produces. Hotels came out of this list because a stay covers a range and a week in one would hold a slot for the whole week. Arriving and leaving do not: they are moments, and they are the two worth reminding someone of. Check-in and check-out now appear as their own entries, named after the stay place and falling back to the linked booking. The stay itself stays out. The two carry the accommodation id, so the list key had to take the type with it. An unconfirmed booking looked exactly like a confirmed one. The status was already in the payload and is now a badge, on both the desktop tool and the phone widget. @
This commit is contained in:
@@ -157,9 +157,11 @@ function seedExampleTrips(db: Database.Database, adminId: number, demoId: number
|
||||
insertBudget.run(t1, 'Food', 'Daily food budget', 52500, 2, 'Approx. 7,500 JPY/day');
|
||||
insertBudget.run(t1, 'Activities', 'Temple entries & experiences', 18000, 2, null);
|
||||
|
||||
// Reservations
|
||||
insertReservation.run(t1, t1days[0], 'Hotel Shinjuku Check-in', '15:00', 'SG-2026-78432', 'confirmed', 'hotel', 'Shinjuku, Tokyo');
|
||||
insertReservation.run(t1, t1days[3], 'Shinkansen Tokyo → Kyoto', '08:30', 'JR-NOZOMI-445', 'confirmed', 'transport', 'Tokyo Station');
|
||||
// Reservations. reservation_time carries the full date, the way the booking
|
||||
// form writes it: a bare clock time is a different shape, and readers that
|
||||
// compare the column against a timestamp cannot tell the two apart (#1934).
|
||||
insertReservation.run(t1, t1days[0], 'Hotel Shinjuku Check-in', '2026-04-15T15:00', 'SG-2026-78432', 'confirmed', 'hotel', 'Shinjuku, Tokyo');
|
||||
insertReservation.run(t1, t1days[3], 'Shinkansen Tokyo → Kyoto', '2026-04-18T08:30', 'JR-NOZOMI-445', 'confirmed', 'transport', 'Tokyo Station');
|
||||
|
||||
insertMember.run(t1, demoId, adminId);
|
||||
|
||||
@@ -213,7 +215,7 @@ function seedExampleTrips(db: Database.Database, adminId: number, demoId: number
|
||||
insertBudget.run(t2, 'Food', 'Restaurants & tapas', 300, 2, 'Approx. 75 EUR/day');
|
||||
insertBudget.run(t2, 'Activities', 'Sagrada Familia + Park Guell + Casa Batllo', 95, 2, 'Online tickets');
|
||||
|
||||
insertReservation.run(t2, t2days[1], 'Sagrada Familia Entry', '10:00', 'SF-2026-11234', 'confirmed', 'activity', 'Eixample, Barcelona');
|
||||
insertReservation.run(t2, t2days[1], 'Sagrada Familia Entry', '2026-05-22T10:00', 'SF-2026-11234', 'confirmed', 'activity', 'Eixample, Barcelona');
|
||||
|
||||
insertMember.run(t2, demoId, adminId);
|
||||
|
||||
@@ -279,9 +281,9 @@ function seedExampleTrips(db: Database.Database, adminId: number, demoId: number
|
||||
insertBudget.run(t3, 'Activities', 'Statue of Liberty + Empire State + Top of the Rock + Met', 180, 2, 'CityPASS');
|
||||
insertBudget.run(t3, 'Entertainment', 'Broadway show tickets', 300, 2, 'Hamilton or Wicked');
|
||||
|
||||
insertReservation.run(t3, t3days[0], 'The Plaza Hotel Check-in', '15:00', 'PZ-2026-55891', 'confirmed', 'hotel', '768 5th Ave, New York');
|
||||
insertReservation.run(t3, t3days[0], 'Broadway Show', '20:00', 'BW-HAM-2026-1192', 'pending', 'activity', 'Richard Rodgers Theatre');
|
||||
insertReservation.run(t3, t3days[1], 'Statue of Liberty Ferry', '08:30', 'SOL-2026-3347', 'confirmed', 'transport', 'Battery Park');
|
||||
insertReservation.run(t3, t3days[0], 'The Plaza Hotel Check-in', '2026-09-18T15:00', 'PZ-2026-55891', 'confirmed', 'hotel', '768 5th Ave, New York');
|
||||
insertReservation.run(t3, t3days[0], 'Broadway Show', '2026-09-18T20:00', 'BW-HAM-2026-1192', 'pending', 'activity', 'Richard Rodgers Theatre');
|
||||
insertReservation.run(t3, t3days[1], 'Statue of Liberty Ferry', '2026-09-19T08:30', 'SOL-2026-3347', 'confirmed', 'transport', 'Battery Park');
|
||||
|
||||
insertMember.run(t3, demoId, adminId);
|
||||
|
||||
|
||||
@@ -105,6 +105,17 @@ export interface UpdateReservationData {
|
||||
needs_review?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* True when `reservation_time` actually carries a date and not just a bare
|
||||
* `HH:MM`. Both shapes reach this column — the booking form writes the
|
||||
* datetime-local `YYYY-MM-DDTHH:MM`, while day-anchored rows (the demo seed
|
||||
* among them) hold only a time — and comparing the two against an ISO
|
||||
* timestamp as strings silently sorts `'20:00'` above `'2026-…'` while
|
||||
* dropping `'08:30'` below it, which is how half a trip's bookings vanished
|
||||
* from the dashboard widget (#1934).
|
||||
*/
|
||||
const DATED = "r.reservation_time GLOB '[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]*'";
|
||||
|
||||
type AccommodationTimesMeta = {
|
||||
check_in_time?: string | null;
|
||||
check_in_end_time?: string | null;
|
||||
@@ -404,26 +415,77 @@ export class ReservationsService {
|
||||
const now = new Date().toISOString();
|
||||
|
||||
const reservations = this.db.all<Record<string, unknown>>(`
|
||||
SELECT r.id, r.trip_id, r.title, r.type, r.status, r.location,
|
||||
r.reservation_time, r.confirmation_number,
|
||||
t.title as trip_title, t.cover_image as trip_cover,
|
||||
d.date as day_date, p.name as place_name, p.image_url as place_image
|
||||
FROM reservations r
|
||||
JOIN trips t ON t.id = r.trip_id
|
||||
LEFT JOIN trip_members tm ON tm.trip_id = t.id AND tm.user_id = ?
|
||||
LEFT JOIN days d ON r.day_id = d.id
|
||||
LEFT JOIN places p ON r.place_id = p.id
|
||||
WHERE (t.user_id = ? OR tm.user_id IS NOT NULL)
|
||||
AND t.is_archived = 0
|
||||
AND r.status != 'cancelled'
|
||||
AND COALESCE(r.type, '') != 'hotel'
|
||||
AND (
|
||||
(r.reservation_time IS NOT NULL AND r.reservation_time >= ?)
|
||||
OR (r.reservation_time IS NULL AND d.date IS NOT NULL AND d.date >= ?)
|
||||
)
|
||||
ORDER BY COALESCE(r.reservation_time, d.date) ASC
|
||||
WITH visible_trips AS (
|
||||
SELECT t.id, t.title, t.cover_image
|
||||
FROM trips t
|
||||
LEFT JOIN trip_members tm ON tm.trip_id = t.id AND tm.user_id = ?
|
||||
WHERE (t.user_id = ? OR tm.user_id IS NOT NULL) AND t.is_archived = 0
|
||||
),
|
||||
-- One row per candidate with its date and time already separated, so the
|
||||
-- filter and the sort below never have to guess what reservation_time holds.
|
||||
entries AS (
|
||||
SELECT r.id, r.trip_id, r.title, r.type, r.status, r.location,
|
||||
r.reservation_time, r.confirmation_number,
|
||||
tr.title as trip_title, tr.cover_image as trip_cover,
|
||||
d.date as day_date, p.name as place_name, p.image_url as place_image,
|
||||
CASE WHEN ${DATED} THEN substr(r.reservation_time, 1, 10) ELSE d.date END as at_date,
|
||||
CASE WHEN ${DATED} THEN substr(r.reservation_time, 12) ELSE r.reservation_time END as at_time
|
||||
FROM reservations r
|
||||
JOIN visible_trips tr ON tr.id = r.trip_id
|
||||
LEFT JOIN days d ON r.day_id = d.id
|
||||
LEFT JOIN places p ON r.place_id = p.id
|
||||
WHERE r.status != 'cancelled'
|
||||
AND COALESCE(r.type, '') != 'hotel'
|
||||
|
||||
UNION ALL
|
||||
|
||||
-- Check-in and check-out as their own moments (#1934). The stay itself is
|
||||
-- still left out: it covers a range, and a week in one hotel would hold a
|
||||
-- slot in a six-entry widget for the whole week. Arriving and leaving are
|
||||
-- points in time, which is exactly what this widget is for, and they are
|
||||
-- the two the traveller needs reminding of.
|
||||
SELECT a.id, a.trip_id,
|
||||
COALESCE(p.name, (SELECT res.title FROM reservations res
|
||||
WHERE CAST(res.accommodation_id AS INTEGER) = a.id
|
||||
AND res.status != 'cancelled'
|
||||
ORDER BY res.id LIMIT 1), tr.title) as title,
|
||||
'checkin' as type, 'confirmed' as status, NULL as location,
|
||||
CASE WHEN a.check_in IS NOT NULL THEN d.date || 'T' || a.check_in END as reservation_time,
|
||||
a.confirmation as confirmation_number,
|
||||
tr.title as trip_title, tr.cover_image as trip_cover,
|
||||
d.date as day_date, p.name as place_name, p.image_url as place_image,
|
||||
d.date as at_date, a.check_in as at_time
|
||||
FROM day_accommodations a
|
||||
JOIN visible_trips tr ON tr.id = a.trip_id
|
||||
JOIN days d ON d.id = a.start_day_id
|
||||
LEFT JOIN places p ON p.id = a.place_id
|
||||
|
||||
UNION ALL
|
||||
|
||||
SELECT a.id, a.trip_id,
|
||||
COALESCE(p.name, (SELECT res.title FROM reservations res
|
||||
WHERE CAST(res.accommodation_id AS INTEGER) = a.id
|
||||
AND res.status != 'cancelled'
|
||||
ORDER BY res.id LIMIT 1), tr.title) as title,
|
||||
'checkout' as type, 'confirmed' as status, NULL as location,
|
||||
CASE WHEN a.check_out IS NOT NULL THEN d.date || 'T' || a.check_out END as reservation_time,
|
||||
a.confirmation as confirmation_number,
|
||||
tr.title as trip_title, tr.cover_image as trip_cover,
|
||||
d.date as day_date, p.name as place_name, p.image_url as place_image,
|
||||
d.date as at_date, a.check_out as at_time
|
||||
FROM day_accommodations a
|
||||
JOIN visible_trips tr ON tr.id = a.trip_id
|
||||
JOIN days d ON d.id = a.end_day_id
|
||||
LEFT JOIN places p ON p.id = a.place_id
|
||||
)
|
||||
SELECT id, trip_id, title, type, status, location, reservation_time,
|
||||
confirmation_number, trip_title, trip_cover, day_date, place_name, place_image
|
||||
FROM entries
|
||||
WHERE at_date IS NOT NULL
|
||||
AND (at_date > ? OR (at_date = ? AND COALESCE(at_time, '23:59') >= ?))
|
||||
ORDER BY at_date ASC, COALESCE(at_time, '00:00') ASC, id ASC
|
||||
LIMIT ?
|
||||
`, userId, userId, now, today, limit);
|
||||
`, userId, userId, today, today, now.slice(11, 16), limit);
|
||||
|
||||
return reservations;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user