mts-booking-library 1.2.6 → 1.2.8

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.
@@ -14,6 +14,17 @@ var __extends = (this && this.__extends) || (function () {
14
14
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
15
  };
16
16
  })();
17
+ var __assign = (this && this.__assign) || function () {
18
+ __assign = Object.assign || function(t) {
19
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
20
+ s = arguments[i];
21
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
+ t[p] = s[p];
23
+ }
24
+ return t;
25
+ };
26
+ return __assign.apply(this, arguments);
27
+ };
17
28
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
29
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
30
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -272,13 +283,13 @@ var JourneyBooking = /** @class */ (function (_super) {
272
283
  ];
273
284
  }));
274
285
  // Parse the return tariffs
275
- passenger.returnTariffs = new Map(Object.entries(passenger.returnTariffs).map(function (_a) {
286
+ passenger.returnTariffs = passenger.returnTariffs ? new Map(Object.entries(passenger.returnTariffs).map(function (_a) {
276
287
  var tripId = _a[0], tariffs = _a[1];
277
288
  return [
278
289
  +tripId,
279
290
  tariffs
280
291
  ];
281
- }));
292
+ })) : null;
282
293
  });
283
294
  return {
284
295
  buyerDataStatus: response.buyerDataStatus,
@@ -334,7 +345,7 @@ var JourneyBooking = /** @class */ (function (_super) {
334
345
  */
335
346
  JourneyBooking.prototype.updateBuyerPassengersDetails = function (passengersDetails) {
336
347
  return __awaiter(this, void 0, void 0, function () {
337
- var buyerPassengersDetails, url;
348
+ var buyerPassengersDetails, request, url;
338
349
  return __generator(this, function (_a) {
339
350
  // First check that it is possible to call this API
340
351
  if (!this.cart) {
@@ -344,8 +355,16 @@ var JourneyBooking = /** @class */ (function (_super) {
344
355
  if (!buyerPassengersDetails || !buyerPassengersDetails[0]) {
345
356
  throw Error("The status of the cart does not allow to call this API");
346
357
  }
358
+ request = __assign({}, passengersDetails);
359
+ passengersDetails.passengers.map(function (passenger, passengerIndex) {
360
+ var tripsToTariffsToJson = {};
361
+ passenger.tripsToTariffs.forEach(function (value, key) {
362
+ tripsToTariffsToJson[key] = value;
363
+ });
364
+ request.passengers[passengerIndex].tripsToTariffs = tripsToTariffsToJson;
365
+ });
347
366
  url = "".concat(this.config.API_ENDPOINT, "/booking/cart/").concat(this.cart.id, "/details");
348
- return [2 /*return*/, this.callPostApi(url, passengersDetails).then(function (response) {
367
+ return [2 /*return*/, this.callPostApi(url, request).then(function (response) {
349
368
  return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response;
350
369
  })];
351
370
  });
@@ -14,6 +14,17 @@ var __extends = (this && this.__extends) || (function () {
14
14
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
15
  };
16
16
  })();
17
+ var __assign = (this && this.__assign) || function () {
18
+ __assign = Object.assign || function(t) {
19
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
20
+ s = arguments[i];
21
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
+ t[p] = s[p];
23
+ }
24
+ return t;
25
+ };
26
+ return __assign.apply(this, arguments);
27
+ };
17
28
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
29
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
30
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -321,13 +332,13 @@ var SubscriptionBooking = /** @class */ (function (_super) {
321
332
  ];
322
333
  }));
323
334
  // Parse the return tariffs
324
- passenger.returnTariffs = new Map(Object.entries(passenger.returnTariffs).map(function (_a) {
335
+ passenger.returnTariffs = passenger.returnTariffs ? new Map(Object.entries(passenger.returnTariffs).map(function (_a) {
325
336
  var tripId = _a[0], tariffs = _a[1];
326
337
  return [
327
338
  +tripId,
328
339
  tariffs
329
340
  ];
330
- }));
341
+ })) : null;
331
342
  });
332
343
  return {
333
344
  buyerDataStatus: response.buyerDataStatus,
@@ -383,7 +394,7 @@ var SubscriptionBooking = /** @class */ (function (_super) {
383
394
  */
384
395
  SubscriptionBooking.prototype.updateBuyerPassengersDetails = function (passengersDetails) {
385
396
  return __awaiter(this, void 0, void 0, function () {
386
- var buyerPassengersDetails, url;
397
+ var buyerPassengersDetails, request, url;
387
398
  return __generator(this, function (_a) {
388
399
  // First check that it is possible to call this API
389
400
  if (!this.cart) {
@@ -393,8 +404,16 @@ var SubscriptionBooking = /** @class */ (function (_super) {
393
404
  if (!buyerPassengersDetails || !buyerPassengersDetails[0]) {
394
405
  throw Error("The status of the cart does not allow to call this API");
395
406
  }
407
+ request = __assign({}, passengersDetails);
408
+ passengersDetails.passengers.map(function (passenger, passengerIndex) {
409
+ var tripsToTariffsToJson = {};
410
+ passenger.tripsToTariffs.forEach(function (value, key) {
411
+ tripsToTariffsToJson[key] = value;
412
+ });
413
+ request.passengers[passengerIndex].tripsToTariffs = tripsToTariffsToJson;
414
+ });
396
415
  url = "".concat(this.config.API_ENDPOINT, "/booking/cart/").concat(this.cart.id, "/details");
397
- return [2 /*return*/, this.callPostApi(url, passengersDetails).then(function (response) {
416
+ return [2 /*return*/, this.callPostApi(url, request).then(function (response) {
398
417
  return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response;
399
418
  })];
400
419
  });
@@ -30,7 +30,7 @@ export declare const initializePerson: (person?: Person | undefined | null) => P
30
30
  */
31
31
  export type GetPassenger = Person & {
32
32
  outboundTariffs: Map<number, PassengerTariff[]>;
33
- returnTariffs: Map<number, PassengerTariff[]>;
33
+ returnTariffs: Map<number, PassengerTariff[]> | null;
34
34
  };
35
35
  export declare enum BuyerDataStatus {
36
36
  OPTIONAL = 0,
@@ -54,11 +54,10 @@ export type GetBuyerPassengersDetailsResponse = {
54
54
  };
55
55
  /**
56
56
  * @description Represents the type of the passengers array in {@link EditPassengersDetailsRequest}.
57
+ * Note that in the `tripsToTariffs` map, the key is the trip id and the value is the chosen tariff id.
57
58
  */
58
59
  export type EditPassengerRequestType = Person & {
59
- tripsToTariffs: {
60
- [tripId: number]: number;
61
- };
60
+ tripsToTariffs: Map<number, number>;
62
61
  };
63
62
  /**
64
63
  * @description Represents the passengers details.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mts-booking-library",
3
- "version": "1.2.6",
3
+ "version": "1.2.8",
4
4
  "description": "Library for use MyTicketSolution Booking API",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",