mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-25 22:27:32 +00:00
fix(mail-ingest): keep a booking that fails the item shape in the inbox
Such a booking made the whole mail fail and retry instead of waiting to be filled in by hand. A reference read as a number is now read as its text.
This commit is contained in:
@@ -295,7 +295,8 @@ export class MailIngestProcessService {
|
||||
messageId: message.id,
|
||||
userId: message.user_id,
|
||||
position: booking.position,
|
||||
itemJson: encodeJson(MAIL_INGEST_ITEM, booking.draft.item),
|
||||
// A booking that fails the shape waits as the mail alone, to be filled in by hand.
|
||||
itemJson: booking.verdict.checks.schema === 'fail' ? null : encodeJson(MAIL_INGEST_ITEM, booking.draft.item),
|
||||
source: booking.draft.source,
|
||||
checksJson: encodeJson(MAIL_INGEST_CHECKS, booking.verdict.checks),
|
||||
uncertainFields: encodeJson(
|
||||
|
||||
@@ -74,7 +74,8 @@ export class MailIngestReadingService {
|
||||
trips: readonly TripOption[];
|
||||
now: Date;
|
||||
}): Promise<MailReading> {
|
||||
const { mail, machine, person, prefs, trips, now } = args;
|
||||
const { mail, person, prefs, trips, now } = args;
|
||||
const machine = args.machine.map(withTextReference);
|
||||
const skipped = await this.aiSkipped(person.id, prefs, now);
|
||||
const refs = trips.map((trip, i) => ({ trip, ref: `t${i + 1}` }));
|
||||
const reading = skipped
|
||||
@@ -134,7 +135,7 @@ export class MailIngestReadingService {
|
||||
bookings.map((booking) => this.bookingImport.mapAiReservations(booking.reservations, 'mail')),
|
||||
);
|
||||
return bookings
|
||||
.flatMap((booking, i) => mapped[i].map((item) => ({ booking, item })))
|
||||
.flatMap((booking, i) => mapped[i].map((item) => ({ booking, item: withTextReference(item) })))
|
||||
.slice(0, MAIL_INGEST_LIMITS.storedBookings)
|
||||
.map(({ booking, item }) => {
|
||||
const match = machine.find((candidate) => sameBooking(candidate, item));
|
||||
@@ -166,6 +167,12 @@ function fromMachine(item: BookingImportPreviewItem): MailDraft {
|
||||
};
|
||||
}
|
||||
|
||||
/** A reference a reader gave as a number, as the text it is. */
|
||||
function withTextReference(item: BookingImportPreviewItem): BookingImportPreviewItem {
|
||||
const reference: unknown = item.confirmation_number;
|
||||
return typeof reference === 'number' ? { ...item, confirmation_number: String(reference) } : item;
|
||||
}
|
||||
|
||||
/** A booking as a hint for the AI: what it is, when, its reference and route, no more. */
|
||||
function hintOf(item: BookingImportPreviewItem): Record<string, unknown> {
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user