mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-28 07:30:04 +00:00
fix(booking-import): treat a booking a forwarded mail added as already imported
The file and assistant import only looked for bookings the file import wrote, so the same booking arrived twice when it had come in by mail first.
This commit is contained in:
@@ -17,7 +17,7 @@ import { PlacesService } from '../places/places.service';
|
||||
import { RealtimeService } from '../realtime/realtime.service';
|
||||
import { withoutOrigin } from '../reservations/reservation-origin.contract';
|
||||
import { ReservationsService, type CreateAccommodation } from '../reservations/reservations.service';
|
||||
import { IMPORT_SOURCE, importExternalId } from './booking-origin';
|
||||
import { IMPORT_SOURCE, IMPORTED_SOURCES, importExternalId } from './booking-origin';
|
||||
import { KitineraryExtractorService } from './kitinerary-extractor.service';
|
||||
import { mapReservations } from './kitinerary-mapper';
|
||||
import type { ParsedBookingItem, KiReservation } from './kitinerary.types';
|
||||
@@ -406,10 +406,13 @@ export class BookingImportService {
|
||||
}
|
||||
}
|
||||
|
||||
/** Whether an earlier import already wrote the booking this key names into the trip. */
|
||||
/** Whether an earlier import, from a file or a forwarded mail, already wrote the booking this key names into the trip. */
|
||||
private async alreadyImported(tripId: string, externalId: string): Promise<boolean> {
|
||||
const id = await this.reservationsRepo.findIdByExternal(this.rowIdNum(tripId), IMPORT_SOURCE, externalId);
|
||||
return id !== undefined;
|
||||
const trip = this.rowIdNum(tripId);
|
||||
const ids = await Promise.all(
|
||||
IMPORTED_SOURCES.map((source) => this.reservationsRepo.findIdByExternal(trip, source, externalId)),
|
||||
);
|
||||
return ids.some((id) => id !== undefined);
|
||||
}
|
||||
|
||||
/** The place row a venue booking brings, geocoded first so the broadcast carries coordinates. */
|
||||
|
||||
@@ -3,6 +3,9 @@ import type { BookingImportPreviewItem } from '@trek/shared';
|
||||
/** The `external_source` of a booking written by the file import. */
|
||||
export const IMPORT_SOURCE = 'import';
|
||||
|
||||
/** The sources whose keys say a booking is in a trip already: the file import's and the mail import's (`mail`). */
|
||||
export const IMPORTED_SOURCES: readonly string[] = [IMPORT_SOURCE, 'mail'];
|
||||
|
||||
/** `external_id` is free text, but a key past this length is a document that is not a booking reference. */
|
||||
const MAX_EXTERNAL_ID = 200;
|
||||
|
||||
|
||||
@@ -675,6 +675,17 @@ describe('BookingImportService.confirm reports every item it did not create', ()
|
||||
expect(guardsStub.hasTripPermission).toHaveBeenLastCalledWith('reservation_edit', '5', 2);
|
||||
expect(reservations.createWithCostInTx).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('BOOKING-IMPORT-REPORT-005: a booking a forwarded mail already wrote into the trip is a duplicate too', async () => {
|
||||
const { svc, reservations } = makeReport(async () => ({}));
|
||||
findIdByExternal.mockResolvedValueOnce(undefined).mockResolvedValueOnce(4);
|
||||
|
||||
const res = await svc.confirm('5', 1, [flight as never], undefined);
|
||||
|
||||
expect(res).toEqual({ created: [], failed: [{ index: 0, reason: 'duplicate' }] });
|
||||
expect(findIdByExternal).toHaveBeenCalledWith(5, 'mail', 'ABC123|flight|2026-09-01|fra-nrt');
|
||||
expect(reservations.createWithCostInTx).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('BookingImportService: reading a forwarded mail', () => {
|
||||
|
||||
Reference in New Issue
Block a user