mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-29 08:00:06 +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:
@@ -4,7 +4,7 @@ import { rowsOf } from '../undo-snapshot';
|
||||
import { bookingCard, bookingItemOf, changedBetween } from './booking-item';
|
||||
import { idOf, rowOfReservation, rowOfStay, scopeOfCard, type BookingRow, type StaySource } from './booking-row';
|
||||
import { bookingRowOf, dateOf, stayRowOf } from './booking-trip';
|
||||
import type { BookingCard, CardMoney, TrekCard } from '@trek/shared';
|
||||
import { importedReservationStatus, type BookingCard, type CardMoney, type TrekCard } from '@trek/shared';
|
||||
|
||||
/**
|
||||
* The cards of held booking writes: what will be saved, drawn from the
|
||||
@@ -261,16 +261,19 @@ export function importedBookingCard(ctx: PreviewContext, args: ToolArgs): TrekCa
|
||||
const stay = recordOf(args._accommodation);
|
||||
const venue = recordOf(args._venue);
|
||||
const isStay = args.type === 'hotel' || args._accommodation !== undefined;
|
||||
const meta = recordOf(args.metadata);
|
||||
const row: BookingRow = {
|
||||
...blankRow(ctx.card.tripId),
|
||||
type: isStay ? 'hotel' : args.type,
|
||||
title: args.title,
|
||||
// Saved confirmed when the file said so (#3238); a booking it says nothing about shows no status.
|
||||
status: importedReservationStatus(meta) === 'confirmed' ? 'confirmed' : null,
|
||||
needsReview: args.needs_review === true,
|
||||
confirmation: args.confirmation_number,
|
||||
reservationTime: args.reservation_time,
|
||||
reservationEndTime: args.reservation_end_time,
|
||||
location: args.location ?? venue.name,
|
||||
meta: recordOf(args.metadata),
|
||||
meta,
|
||||
endpoints: rowsOf(args.endpoints),
|
||||
point: { lat: venue.lat, lng: venue.lng },
|
||||
stay: isStay
|
||||
|
||||
@@ -24,7 +24,7 @@ import type { ParsedBookingItem, KiReservation } from './kitinerary.types';
|
||||
import { UniqueConstraintViolationException } from '@mikro-orm/core';
|
||||
import { InjectRepository } from '@mikro-orm/nestjs';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { normalizePlaceWebsite, typeToCostCategory } from '@trek/shared';
|
||||
import { importedReservationStatus, normalizePlaceWebsite, typeToCostCategory } from '@trek/shared';
|
||||
import type {
|
||||
BookingImportPreviewItem,
|
||||
BookingImportPreviewResponse,
|
||||
@@ -520,6 +520,8 @@ export class BookingImportService {
|
||||
tripId,
|
||||
{
|
||||
...reservationData,
|
||||
// Confirmed when the document said so (#3238), like the mail import and the review form.
|
||||
status: importedReservationStatus(item.metadata),
|
||||
...origin,
|
||||
place_id: placeId,
|
||||
create_accommodation: createAccommodation && { ...createAccommodation, place_id: placeId },
|
||||
|
||||
@@ -21,6 +21,7 @@ import {
|
||||
haversineMetres,
|
||||
LEG_RESERVATION_TYPES,
|
||||
normalizeLocalDateTime,
|
||||
readReservationStatus,
|
||||
splitLocalDateTime,
|
||||
sumMinor,
|
||||
toMinor,
|
||||
@@ -730,9 +731,14 @@ function segmentDetail(r: KiReservation): {
|
||||
};
|
||||
}
|
||||
|
||||
/** Merge a node's seat/class/platform/price into its item's metadata. The item's own metadata wins. */
|
||||
/**
|
||||
* Merge a node's seat/class/platform/price and the status the document states
|
||||
* into its item's metadata. The item's own metadata wins. The status is the one
|
||||
* the mail import and the review form read (#3238), written as TREK's word.
|
||||
*/
|
||||
function applyCommonMeta(item: ParsedBookingItem, r: KiReservation): ParsedBookingItem {
|
||||
const detail = segmentDetail(r);
|
||||
const status = readReservationStatus(r.reservationStatus);
|
||||
const detail = { ...segmentDetail(r), ...(status ? { reservationStatus: status } : {}) };
|
||||
if (Object.keys(detail).length) item.metadata = { ...detail, ...(item.metadata ?? {}) };
|
||||
return item;
|
||||
}
|
||||
|
||||
@@ -147,6 +147,8 @@ export interface KiReservation {
|
||||
platform?: string;
|
||||
price?: number | string;
|
||||
priceCurrency?: string;
|
||||
/** schema.org's ReservationConfirmed, ReservationCancelled and the like, bare or as a URL. */
|
||||
reservationStatus?: string;
|
||||
[key: string]: unknown;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ export function reservationShapeRules(): string[] {
|
||||
'Each reservation is a schema.org JSON-LD object whose "@type" is one of:',
|
||||
KI_RESERVATION_TYPES.map((t) => ` - ${t}`).join('\n'),
|
||||
'Put the booking/confirmation code in "reservationNumber" on each reservation.',
|
||||
'When the document states the booking status, put it in "reservationStatus" on each reservation: "ReservationConfirmed", "ReservationPending" or "ReservationCancelled". Leave it out when the document does not say.',
|
||||
'All dates/times are plain ISO 8601 local strings, e.g. "2026-06-11T10:00:00" (no timezone wrapper objects).',
|
||||
'IMPORTANT: nest the type-specific fields INSIDE a "reservationFor" object — do NOT place them at the top level of the reservation.',
|
||||
'Populate "reservationFor" with the type-specific fields:',
|
||||
|
||||
@@ -20,6 +20,7 @@ import { parsePriceMinor } from './mail-money';
|
||||
import { InjectRepository } from '@mikro-orm/nestjs';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import {
|
||||
importedReservationStatus,
|
||||
normalizePlaceWebsite,
|
||||
typeToCostCategory,
|
||||
type BookingImportPreviewItem,
|
||||
@@ -285,7 +286,7 @@ export class MailIngestApplyService {
|
||||
return {
|
||||
title: fields.title,
|
||||
type: fields.type,
|
||||
status: statusOf(item),
|
||||
status: importedReservationStatus(item.metadata),
|
||||
reservation_time: fields.reservation_time ?? undefined,
|
||||
reservation_end_time: fields.reservation_end_time ?? undefined,
|
||||
location: fields.location ?? undefined,
|
||||
@@ -356,12 +357,6 @@ interface RemovedBooking {
|
||||
placeIds: number[];
|
||||
}
|
||||
|
||||
/** The status a booking is written with: confirmed when the mail said so, pending otherwise. */
|
||||
function statusOf(item: BookingImportPreviewItem): string {
|
||||
const status = item.metadata?.reservationStatus;
|
||||
return typeof status === 'string' && /confirm/i.test(status) ? 'confirmed' : 'pending';
|
||||
}
|
||||
|
||||
/** A hotel's stay: its days by check-in and check-out date, its times of day alone. */
|
||||
function stayOf(
|
||||
stay: NonNullable<BookingImportPreviewItem['_accommodation']>,
|
||||
|
||||
Reference in New Issue
Block a user