mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-27 23:27:31 +00:00
fix(booking-import): import a booking the document calls confirmed as confirmed
The mail import already wrote a booking as confirmed when its metadata held reservationStatus, but nothing ever filled that field: the KItinerary mapper dropped schema.org's reservationStatus, the AI reading was neither asked for it nor given it in its response schema (a schema-bound provider fills declared properties only), and the review form, the file import confirm path and the assistant's import card all started every booking as pending. The mapper now reads reservationStatus from every node, schema.org URL, bare ReservationConfirmed or a plain word alike, and keeps it in the item's metadata as TREK's word. The AI prompt and response schema ask for it. One shared helper turns it into the status a booking is saved with: confirmed when the document said so, pending otherwise, so a cancellation or an unknown value still lands as pending. The review form prefill, the mail import, the confirm path and the assistant card all use it. Closes #3238
This commit is contained in:
@@ -143,6 +143,11 @@ export const KI_RESERVATION_JSON_SCHEMA = {
|
||||
properties: {
|
||||
'@type': { type: 'string', enum: [...KI_RESERVATION_TYPES] },
|
||||
reservationNumber: { type: 'string' },
|
||||
// What the document says about the booking (#3238); left out when it says nothing.
|
||||
reservationStatus: {
|
||||
type: 'string',
|
||||
enum: ['ReservationConfirmed', 'ReservationPending', 'ReservationCancelled'],
|
||||
},
|
||||
// Hotel check-in/out, car pickup/dropoff, event/restaurant start/end —
|
||||
// plain ISO 8601 strings (no KDE QDateTime wrapper).
|
||||
checkinTime: { type: 'string' },
|
||||
|
||||
@@ -10,7 +10,9 @@ import {
|
||||
ROADTRIP_RESERVATION_TYPES,
|
||||
TRANSPORT_RESERVATION_TYPES,
|
||||
TRAVEL_RESERVATION_TYPES,
|
||||
importedReservationStatus,
|
||||
isTransportReservationType,
|
||||
readReservationStatus,
|
||||
reservationTypeInfo,
|
||||
} from './reservation-types';
|
||||
import { reservationSchema, reservationStatusSchema, reservationTypeSchema } from './reservation.schema';
|
||||
@@ -108,3 +110,30 @@ describe('reservation response type and status', () => {
|
||||
expect(reservationSchema.parse(row)).toMatchObject({ type: 'balloon' });
|
||||
});
|
||||
});
|
||||
|
||||
// #3238: the status a booking document states, and the one an import saves.
|
||||
describe('readReservationStatus / importedReservationStatus', () => {
|
||||
it('reads schema.org and plain spellings, and nothing else', () => {
|
||||
expect(readReservationStatus('http://schema.org/ReservationConfirmed')).toBe('confirmed');
|
||||
expect(readReservationStatus('https://schema.org/ReservationConfirmed')).toBe('confirmed');
|
||||
expect(readReservationStatus(' ReservationConfirmed ')).toBe('confirmed');
|
||||
expect(readReservationStatus('Confirmed')).toBe('confirmed');
|
||||
expect(readReservationStatus('http://schema.org/ReservationCancelled')).toBe('cancelled');
|
||||
expect(readReservationStatus('canceled')).toBe('cancelled');
|
||||
expect(readReservationStatus('ReservationHold')).toBe('pending');
|
||||
expect(readReservationStatus('ReservationPending')).toBe('pending');
|
||||
expect(readReservationStatus('unconfirmed')).toBeUndefined();
|
||||
expect(readReservationStatus('')).toBeUndefined();
|
||||
expect(readReservationStatus(null)).toBeUndefined();
|
||||
expect(readReservationStatus(1)).toBeUndefined();
|
||||
});
|
||||
|
||||
it('saves an import confirmed only when the document said so', () => {
|
||||
expect(importedReservationStatus({ reservationStatus: 'confirmed' })).toBe('confirmed');
|
||||
expect(importedReservationStatus({ reservationStatus: 'ReservationConfirmed' })).toBe('confirmed');
|
||||
expect(importedReservationStatus({ reservationStatus: 'cancelled' })).toBe('pending');
|
||||
expect(importedReservationStatus({})).toBe('pending');
|
||||
expect(importedReservationStatus(null)).toBe('pending');
|
||||
expect(importedReservationStatus(undefined)).toBe('pending');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -135,3 +135,31 @@ export function isTransportReservationType(type: string | null | undefined): boo
|
||||
/** The statuses a reservation can be in. A row without one reads as `pending`. */
|
||||
export const RESERVATION_STATUSES = ['pending', 'confirmed', 'cancelled'] as const;
|
||||
export type ReservationStatus = (typeof RESERVATION_STATUSES)[number];
|
||||
|
||||
/**
|
||||
* The status a booking document states, as TREK writes it: schema.org's
|
||||
* `ReservationConfirmed` (bare or as a schema.org URL) or a plain `confirmed`
|
||||
* is confirmed, a cancellation is cancelled, a booking held or pending is
|
||||
* pending. Anything else says nothing, so the caller keeps its own default.
|
||||
*/
|
||||
export function readReservationStatus(value: unknown): ReservationStatus | undefined {
|
||||
if (typeof value !== 'string') return undefined;
|
||||
const word = value
|
||||
.trim()
|
||||
.toLowerCase()
|
||||
.replace(/^https?:\/\/schema\.org\//, '')
|
||||
.replace(/^reservation/, '');
|
||||
if (word === 'confirmed') return 'confirmed';
|
||||
if (word === 'cancelled' || word === 'canceled') return 'cancelled';
|
||||
if (word === 'pending' || word === 'hold') return 'pending';
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* The status an imported booking is saved with (#3238): confirmed when the
|
||||
* document said so, pending otherwise. A cancellation is no status to add a
|
||||
* booking with, so it stays pending here; the mail import refuses it before.
|
||||
*/
|
||||
export function importedReservationStatus(metadata: Record<string, unknown> | null | undefined): ReservationStatus {
|
||||
return readReservationStatus(metadata?.reservationStatus) === 'confirmed' ? 'confirmed' : 'pending';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user