mts-booking-library 3.3.0 → 3.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -2,7 +2,7 @@ import { ErrorResponse } from "../types/ErrorResponse";
|
|
|
2
2
|
import { CreateUpdateCartRequest } from "../types/common/Cart";
|
|
3
3
|
import { EditPassengersDetailsRequest, GetBuyerPassengersDetailsResponse } from "../types/common/Person";
|
|
4
4
|
import { AddReductionRequest } from "../types/common/Reduction";
|
|
5
|
-
import { BusMatrix } from "../types/journeys/BusMatrix";
|
|
5
|
+
import { BusMatrix, SeatChange } from "../types/journeys/BusMatrix";
|
|
6
6
|
import { JourneyCart } from "../types/journeys/JourneyCart";
|
|
7
7
|
import { JourneySearchRequest, JourneySearchResult } from "../types/journeys/JourneySearch";
|
|
8
8
|
import { ReductionTrip } from "../types/journeys/Trip";
|
|
@@ -165,11 +165,24 @@ export declare class JourneyBooking extends Booking {
|
|
|
165
165
|
getAssignedSeats(tripId: number, options?: ApiCallOptions): Promise<ErrorResponse | number[]>;
|
|
166
166
|
/**
|
|
167
167
|
* @description This method shall be called when the user wants to change the assigned seats of a trip.
|
|
168
|
+
*
|
|
169
|
+
* Two shapes are supported. Callers should prefer `seatChanges` when
|
|
170
|
+
* the cart has more than one passenger on the trip — the BE pairs by
|
|
171
|
+
* {@link SeatChange.oldSeatId}, which uniquely identifies the cart's
|
|
172
|
+
* underlying TripBusLayoutCell. The legacy `newSeatsIds` form is a
|
|
173
|
+
* full positional snapshot of every passenger's new seat; the BE
|
|
174
|
+
* zips it against EF-ordered TripBusLayoutCells, which can reassign
|
|
175
|
+
* the wrong passenger when the two orderings disagree.
|
|
176
|
+
*
|
|
177
|
+
* Send only one of the two arguments per call. If both are present
|
|
178
|
+
* the BE prefers `seatChanges`.
|
|
168
179
|
* @param tripId The id of the trip for which the seats should be changed
|
|
169
|
-
* @param
|
|
180
|
+
* @param seatsOrChanges Either the legacy `newSeatsIds` array (every
|
|
181
|
+
* passenger's new seat, in order) or an explicit list of
|
|
182
|
+
* {@link SeatChange} pairs (only the seats that change).
|
|
170
183
|
* @returns An {@link ErrorResponse} object in case of error, true otherwise.
|
|
171
184
|
*/
|
|
172
|
-
changeSeatsOfTrip(tripId: number,
|
|
185
|
+
changeSeatsOfTrip(tripId: number, seatsOrChanges: number[] | SeatChange[], options?: ApiCallOptions): Promise<ErrorResponse | boolean>;
|
|
173
186
|
/**
|
|
174
187
|
* @description This method shall be called when the user wants to retrieve the trips in the cart, for adding a available reduction
|
|
175
188
|
* to a specific trip (rather than to the whole cart).
|
|
@@ -462,13 +462,26 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
|
462
462
|
};
|
|
463
463
|
/**
|
|
464
464
|
* @description This method shall be called when the user wants to change the assigned seats of a trip.
|
|
465
|
+
*
|
|
466
|
+
* Two shapes are supported. Callers should prefer `seatChanges` when
|
|
467
|
+
* the cart has more than one passenger on the trip — the BE pairs by
|
|
468
|
+
* {@link SeatChange.oldSeatId}, which uniquely identifies the cart's
|
|
469
|
+
* underlying TripBusLayoutCell. The legacy `newSeatsIds` form is a
|
|
470
|
+
* full positional snapshot of every passenger's new seat; the BE
|
|
471
|
+
* zips it against EF-ordered TripBusLayoutCells, which can reassign
|
|
472
|
+
* the wrong passenger when the two orderings disagree.
|
|
473
|
+
*
|
|
474
|
+
* Send only one of the two arguments per call. If both are present
|
|
475
|
+
* the BE prefers `seatChanges`.
|
|
465
476
|
* @param tripId The id of the trip for which the seats should be changed
|
|
466
|
-
* @param
|
|
477
|
+
* @param seatsOrChanges Either the legacy `newSeatsIds` array (every
|
|
478
|
+
* passenger's new seat, in order) or an explicit list of
|
|
479
|
+
* {@link SeatChange} pairs (only the seats that change).
|
|
467
480
|
* @returns An {@link ErrorResponse} object in case of error, true otherwise.
|
|
468
481
|
*/
|
|
469
|
-
JourneyBooking.prototype.changeSeatsOfTrip = function (tripId,
|
|
482
|
+
JourneyBooking.prototype.changeSeatsOfTrip = function (tripId, seatsOrChanges, options) {
|
|
470
483
|
return __awaiter(this, void 0, void 0, function () {
|
|
471
|
-
var seatSelectionStatus, url;
|
|
484
|
+
var seatSelectionStatus, usesExplicitShape, body, url;
|
|
472
485
|
var _this = this;
|
|
473
486
|
return __generator(this, function (_a) {
|
|
474
487
|
// First check that it is possible to call this API
|
|
@@ -479,12 +492,19 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
|
479
492
|
if (!seatSelectionStatus || !seatSelectionStatus[0]) {
|
|
480
493
|
throw Error("The status of the cart does not allow to call this API");
|
|
481
494
|
}
|
|
495
|
+
usesExplicitShape = seatsOrChanges.length > 0 && typeof seatsOrChanges[0] === "object";
|
|
496
|
+
body = {
|
|
497
|
+
tripId: tripId,
|
|
498
|
+
cartGuid: this.cart.guid
|
|
499
|
+
};
|
|
500
|
+
if (usesExplicitShape) {
|
|
501
|
+
body.seatChanges = seatsOrChanges;
|
|
502
|
+
}
|
|
503
|
+
else {
|
|
504
|
+
body.newSeatsIds = seatsOrChanges;
|
|
505
|
+
}
|
|
482
506
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/seats");
|
|
483
|
-
return [2 /*return*/, this.callPostApi(url, {
|
|
484
|
-
tripId: tripId,
|
|
485
|
-
newSeatsIds: newSeatsIds,
|
|
486
|
-
cartGuid: this.cart.guid
|
|
487
|
-
}, options).then(function (response) {
|
|
507
|
+
return [2 /*return*/, this.callPostApi(url, body, options).then(function (response) {
|
|
488
508
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
|
|
489
509
|
return response;
|
|
490
510
|
// Update the booking process status
|
package/lib/index.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ export { ErrorResponse, objectIsMTSErrorResponse } from "./types/ErrorResponse";
|
|
|
16
16
|
export { City } from "./types/common/City";
|
|
17
17
|
export { Extra, GetExtrasResponse, GetExtrasForBookingResponse } from "./types/common/Extra";
|
|
18
18
|
export * from "./types/common/dates";
|
|
19
|
-
export { BusLayoutCell, BusMatrix, BusCellTypes, SeatStatus } from "./types/journeys/BusMatrix";
|
|
19
|
+
export { BusLayoutCell, BusMatrix, BusCellTypes, SeatChange, SeatStatus } from "./types/journeys/BusMatrix";
|
|
20
20
|
export { JourneyCart, JourneyBookingType, TripBookingInfo } from "./types/journeys/JourneyCart";
|
|
21
21
|
export { JourneyInfo } from "./types/journeys/JourneyInfo";
|
|
22
22
|
export { JourneySearchRequest, JourneySearchResult, DEFAULT_JOURNEY_SEARCH } from "./types/journeys/JourneySearch";
|
|
@@ -18,6 +18,17 @@ export type BusLayoutCell = {
|
|
|
18
18
|
* - On the third dimension, the are the columns.
|
|
19
19
|
*/
|
|
20
20
|
export type BusMatrix = BusLayoutCell[][][];
|
|
21
|
+
/**
|
|
22
|
+
* Explicit (oldSeatId, newSeatId) pair for a single seat change in a
|
|
23
|
+
* cart. Used by `JourneyBooking.changeSeatsOfTrip` instead of the
|
|
24
|
+
* legacy positional `newSeatsIds` snapshot — the BE pairs by
|
|
25
|
+
* `oldSeatId`, so multi-passenger swaps no longer depend on array
|
|
26
|
+
* order and can never reassign the wrong passenger.
|
|
27
|
+
*/
|
|
28
|
+
export type SeatChange = {
|
|
29
|
+
oldSeatId: number;
|
|
30
|
+
newSeatId: number;
|
|
31
|
+
};
|
|
21
32
|
export declare enum BusCellTypes {
|
|
22
33
|
SEAT = "SEAT",
|
|
23
34
|
SELECTED_SEAT = "SELECTED_SEAT",
|