mts-booking-library 1.2.3 → 1.2.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -21,7 +21,7 @@ export declare class JourneyBooking extends Booking {
21
21
  */
22
22
  constructor(env: MTSEnvs, sub_key: string, onCartExpiration: () => void, debug?: boolean, language?: string, access_token?: string, sellerId?: number, resellerId?: number);
23
23
  getCart(): JourneyCart | undefined;
24
- private fetchAndSetCart;
24
+ fetchAndSetCart(cartId: number): Promise<void>;
25
25
  private createCartTimer;
26
26
  fetchCart(cartId: number): Promise<JourneyCart>;
27
27
  /**
@@ -88,3 +88,6 @@ export declare class JourneyBooking extends Booking {
88
88
  */
89
89
  changeSeatsOfTrip(tripId: number, newSeatsIds: number[]): Promise<ErrorResponse | any>;
90
90
  }
91
+ export declare namespace JourneyBooking {
92
+ const createBooking: (env: MTSEnvs, sub_key: string, onCartExpiration: () => void, debug: boolean, language: string, access_token?: string, sellerId?: number, resellerId?: number) => Promise<JourneyBooking>;
93
+ }
@@ -74,9 +74,10 @@ var JourneyBooking = /** @class */ (function (_super) {
74
74
  var _this =
75
75
  // Call Booking constructor
76
76
  _super.call(this, env, sub_key, onCartExpiration, booking_1.Booking.BookingTypes.MLP, debug, language, access_token, sellerId, resellerId) || this;
77
+ // Set cartId
77
78
  var cartId = localStorage.getItem("cartId");
78
79
  if (cartId) {
79
- _this.fetchAndSetCart(parseInt(cartId));
80
+ _this.cartId = parseInt(cartId);
80
81
  }
81
82
  return _this;
82
83
  }
@@ -87,24 +88,28 @@ var JourneyBooking = /** @class */ (function (_super) {
87
88
  return __awaiter(this, void 0, void 0, function () {
88
89
  var _this = this;
89
90
  return __generator(this, function (_a) {
90
- this.fetchCart(cartId).then(function (cart) {
91
- var cartDate = new Date(cart.bookingDueDate);
92
- if (cartDate > new Date()) {
93
- _this.cart = cart;
94
- _this.cartId = cart.id;
95
- _this.bookingDueDate = cartDate; // See Booking class
96
- // Fill the booking process status
97
- _this.bookingStepsToStatus = new Map(Object.entries(cart.stepsToStatus).map(function (_a) {
98
- var bookingStep = _a[0], values = _a[1];
99
- return [
100
- bookingStep,
101
- values
102
- ];
103
- }));
104
- _this.createCartTimer(cartDate);
105
- }
106
- });
107
- return [2 /*return*/];
91
+ switch (_a.label) {
92
+ case 0: return [4 /*yield*/, this.fetchCart(cartId).then(function (cart) {
93
+ var cartDate = new Date(cart.bookingDueDate);
94
+ if (cartDate > new Date()) {
95
+ _this.cart = cart;
96
+ _this.cartId = cart.id;
97
+ _this.bookingDueDate = cartDate; // See Booking class
98
+ // Fill the booking process status
99
+ _this.bookingStepsToStatus = new Map(Object.entries(cart.stepsToStatus).map(function (_a) {
100
+ var bookingStep = _a[0], values = _a[1];
101
+ return [
102
+ bookingStep,
103
+ values
104
+ ];
105
+ }));
106
+ _this.createCartTimer(cartDate);
107
+ }
108
+ })];
109
+ case 1:
110
+ _a.sent();
111
+ return [2 /*return*/];
112
+ }
108
113
  });
109
114
  });
110
115
  };
@@ -418,3 +423,26 @@ var JourneyBooking = /** @class */ (function (_super) {
418
423
  return JourneyBooking;
419
424
  }(booking_1.Booking));
420
425
  exports.JourneyBooking = JourneyBooking;
426
+ (function (JourneyBooking) {
427
+ var _this = this;
428
+ JourneyBooking.createBooking = function (env, sub_key, onCartExpiration, debug, language, access_token, sellerId, resellerId) { return __awaiter(_this, void 0, void 0, function () {
429
+ var booking, error_1;
430
+ return __generator(this, function (_a) {
431
+ switch (_a.label) {
432
+ case 0:
433
+ _a.trys.push([0, 3, , 4]);
434
+ booking = new JourneyBooking(env, sub_key, onCartExpiration, debug, language, access_token, sellerId, resellerId);
435
+ if (!booking.cartId) return [3 /*break*/, 2];
436
+ return [4 /*yield*/, booking.fetchAndSetCart(booking.cartId)];
437
+ case 1:
438
+ _a.sent();
439
+ _a.label = 2;
440
+ case 2: return [2 /*return*/, booking];
441
+ case 3:
442
+ error_1 = _a.sent();
443
+ throw new Error("Could not instantiate JourneyBooking");
444
+ case 4: return [2 /*return*/];
445
+ }
446
+ });
447
+ }); };
448
+ })(JourneyBooking || (exports.JourneyBooking = JourneyBooking = {}));
@@ -19,7 +19,7 @@ export declare class ServiceBooking extends Booking {
19
19
  */
20
20
  constructor(env: MTSEnvs, sub_key: string, onCartExpiration: () => void, debug?: boolean, language?: string, access_token?: string, sellerId?: number, resellerId?: number);
21
21
  getCart(): ServiceCart | undefined;
22
- private fetchAndSetCart;
22
+ fetchAndSetCart(cartId: number): Promise<void>;
23
23
  private createCartTimer;
24
24
  fetchCart(cartId: number): Promise<ServiceCart>;
25
25
  /**
@@ -47,3 +47,6 @@ export declare class ServiceBooking extends Booking {
47
47
  getServiceTrips(serviceId: number, date: Date): Promise<ErrorResponse | ServiceTrip[]>;
48
48
  createServiceCart(serviceCart: CreateServiceCartRequest): Promise<ErrorResponse | ServiceCart>;
49
49
  }
50
+ export declare namespace ServiceBooking {
51
+ const createBooking: (env: MTSEnvs, sub_key: string, onCartExpiration: () => void, debug: boolean, language: string, access_token?: string, sellerId?: number, resellerId?: number) => Promise<ServiceBooking>;
52
+ }
@@ -85,9 +85,10 @@ var ServiceBooking = /** @class */ (function (_super) {
85
85
  var _this =
86
86
  // Call Booking constructor
87
87
  _super.call(this, env, sub_key, onCartExpiration, booking_1.Booking.BookingTypes.SERVICE, debug, language, access_token, sellerId, resellerId) || this;
88
+ // Set cartId
88
89
  var cartId = localStorage.getItem("cartId");
89
90
  if (cartId) {
90
- _this.fetchAndSetCart(parseInt(cartId));
91
+ _this.cartId = parseInt(cartId);
91
92
  }
92
93
  return _this;
93
94
  }
@@ -98,24 +99,28 @@ var ServiceBooking = /** @class */ (function (_super) {
98
99
  return __awaiter(this, void 0, void 0, function () {
99
100
  var _this = this;
100
101
  return __generator(this, function (_a) {
101
- this.fetchCart(cartId).then(function (cart) {
102
- var cartDate = new Date(cart.bookingDueDate);
103
- if (cartDate > new Date()) {
104
- _this.cart = cart;
105
- _this.cartId = cart.id;
106
- _this.bookingDueDate = cartDate; // See Booking class
107
- // Fill the booking process status
108
- _this.bookingStepsToStatus = new Map(Object.entries(cart.stepsToStatus).map(function (_a) {
109
- var bookingStep = _a[0], values = _a[1];
110
- return [
111
- bookingStep,
112
- values
113
- ];
114
- }));
115
- _this.createCartTimer(cartDate);
116
- }
117
- });
118
- return [2 /*return*/];
102
+ switch (_a.label) {
103
+ case 0: return [4 /*yield*/, this.fetchCart(cartId).then(function (cart) {
104
+ var cartDate = new Date(cart.bookingDueDate);
105
+ if (cartDate > new Date()) {
106
+ _this.cart = cart;
107
+ _this.cartId = cart.id;
108
+ _this.bookingDueDate = cartDate; // See Booking class
109
+ // Fill the booking process status
110
+ _this.bookingStepsToStatus = new Map(Object.entries(cart.stepsToStatus).map(function (_a) {
111
+ var bookingStep = _a[0], values = _a[1];
112
+ return [
113
+ bookingStep,
114
+ values
115
+ ];
116
+ }));
117
+ _this.createCartTimer(cartDate);
118
+ }
119
+ })];
120
+ case 1:
121
+ _a.sent();
122
+ return [2 /*return*/];
123
+ }
119
124
  });
120
125
  });
121
126
  };
@@ -239,3 +244,26 @@ var ServiceBooking = /** @class */ (function (_super) {
239
244
  return ServiceBooking;
240
245
  }(booking_1.Booking));
241
246
  exports.ServiceBooking = ServiceBooking;
247
+ (function (ServiceBooking) {
248
+ var _this = this;
249
+ ServiceBooking.createBooking = function (env, sub_key, onCartExpiration, debug, language, access_token, sellerId, resellerId) { return __awaiter(_this, void 0, void 0, function () {
250
+ var booking, error_1;
251
+ return __generator(this, function (_a) {
252
+ switch (_a.label) {
253
+ case 0:
254
+ _a.trys.push([0, 3, , 4]);
255
+ booking = new ServiceBooking(env, sub_key, onCartExpiration, debug, language, access_token, sellerId, resellerId);
256
+ if (!booking.cartId) return [3 /*break*/, 2];
257
+ return [4 /*yield*/, booking.fetchAndSetCart(booking.cartId)];
258
+ case 1:
259
+ _a.sent();
260
+ _a.label = 2;
261
+ case 2: return [2 /*return*/, booking];
262
+ case 3:
263
+ error_1 = _a.sent();
264
+ throw new Error("Could not instantiate ServiceBooking");
265
+ case 4: return [2 /*return*/];
266
+ }
267
+ });
268
+ }); };
269
+ })(ServiceBooking || (exports.ServiceBooking = ServiceBooking = {}));
@@ -22,7 +22,7 @@ export declare class SubscriptionBooking extends Booking {
22
22
  */
23
23
  constructor(env: MTSEnvs, sub_key: string, onCartExpiration: () => void, debug?: boolean, language?: string, access_token?: string, sellerId?: number, resellerId?: number);
24
24
  getCart(): Cart | undefined;
25
- private fetchAndSetCart;
25
+ fetchAndSetCart(cartId: number): Promise<void>;
26
26
  private createCartTimer;
27
27
  fetchCart(cartId: number): Promise<Cart>;
28
28
  /**
@@ -90,6 +90,7 @@ export declare class SubscriptionBooking extends Booking {
90
90
  updateBuyerPassengersDetails(passengersDetails: EditPassengersDetailsRequest): Promise<ErrorResponse | any>;
91
91
  }
92
92
  export declare namespace SubscriptionBooking {
93
+ const createBooking: (env: MTSEnvs, sub_key: string, onCartExpiration: () => void, debug: boolean, language: string, access_token?: string, sellerId?: number, resellerId?: number) => Promise<SubscriptionBooking>;
93
94
  enum ValidityTypes {
94
95
  WORKING_WEEK = "WORKING_WEEK",
95
96
  WEEKLY = "WEEKLY",
@@ -74,9 +74,10 @@ var SubscriptionBooking = /** @class */ (function (_super) {
74
74
  var _this =
75
75
  // Call Booking constructor
76
76
  _super.call(this, env, sub_key, onCartExpiration, booking_1.Booking.BookingTypes.MLP_SUBSCRIPTION, debug, language, access_token, sellerId, resellerId) || this;
77
+ // Set cartId
77
78
  var cartId = localStorage.getItem("cartId");
78
79
  if (cartId) {
79
- _this.fetchAndSetCart(parseInt(cartId));
80
+ _this.cartId = parseInt(cartId);
80
81
  }
81
82
  return _this;
82
83
  }
@@ -87,24 +88,28 @@ var SubscriptionBooking = /** @class */ (function (_super) {
87
88
  return __awaiter(this, void 0, void 0, function () {
88
89
  var _this = this;
89
90
  return __generator(this, function (_a) {
90
- this.fetchCart(cartId).then(function (cart) {
91
- var cartDate = new Date(cart.bookingDueDate);
92
- if (cartDate > new Date()) {
93
- _this.cart = cart;
94
- _this.cartId = cart.id;
95
- _this.bookingDueDate = cartDate; // See Booking class
96
- // Fill the booking process status
97
- _this.bookingStepsToStatus = new Map(Object.entries(cart.stepsToStatus).map(function (_a) {
98
- var bookingStep = _a[0], values = _a[1];
99
- return [
100
- bookingStep,
101
- values
102
- ];
103
- }));
104
- _this.createCartTimer(cartDate);
105
- }
106
- });
107
- return [2 /*return*/];
91
+ switch (_a.label) {
92
+ case 0: return [4 /*yield*/, this.fetchCart(cartId).then(function (cart) {
93
+ var cartDate = new Date(cart.bookingDueDate);
94
+ if (cartDate > new Date()) {
95
+ _this.cart = cart;
96
+ _this.cartId = cart.id;
97
+ _this.bookingDueDate = cartDate; // See Booking class
98
+ // Fill the booking process status
99
+ _this.bookingStepsToStatus = new Map(Object.entries(cart.stepsToStatus).map(function (_a) {
100
+ var bookingStep = _a[0], values = _a[1];
101
+ return [
102
+ bookingStep,
103
+ values
104
+ ];
105
+ }));
106
+ _this.createCartTimer(cartDate);
107
+ }
108
+ })];
109
+ case 1:
110
+ _a.sent();
111
+ return [2 /*return*/];
112
+ }
108
113
  });
109
114
  });
110
115
  };
@@ -387,6 +392,27 @@ var SubscriptionBooking = /** @class */ (function (_super) {
387
392
  }(booking_1.Booking));
388
393
  exports.SubscriptionBooking = SubscriptionBooking;
389
394
  (function (SubscriptionBooking) {
395
+ var _this = this;
396
+ SubscriptionBooking.createBooking = function (env, sub_key, onCartExpiration, debug, language, access_token, sellerId, resellerId) { return __awaiter(_this, void 0, void 0, function () {
397
+ var booking, error_1;
398
+ return __generator(this, function (_a) {
399
+ switch (_a.label) {
400
+ case 0:
401
+ _a.trys.push([0, 3, , 4]);
402
+ booking = new SubscriptionBooking(env, sub_key, onCartExpiration, debug, language, access_token, sellerId, resellerId);
403
+ if (!booking.cartId) return [3 /*break*/, 2];
404
+ return [4 /*yield*/, booking.fetchAndSetCart(booking.cartId)];
405
+ case 1:
406
+ _a.sent();
407
+ _a.label = 2;
408
+ case 2: return [2 /*return*/, booking];
409
+ case 3:
410
+ error_1 = _a.sent();
411
+ throw new Error("Could not instantiate SubscriptionBooking");
412
+ case 4: return [2 /*return*/];
413
+ }
414
+ });
415
+ }); };
390
416
  var ValidityTypes;
391
417
  (function (ValidityTypes) {
392
418
  ValidityTypes["WORKING_WEEK"] = "WORKING_WEEK";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mts-booking-library",
3
- "version": "1.2.3",
3
+ "version": "1.2.4",
4
4
  "description": "Library for use MyTicketSolution Booking API",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",