mts-booking-library 1.2.13 → 1.2.14

Sign up to get free protection for your applications and to get access to all the features.
@@ -289,6 +289,7 @@ var Booking = /** @class */ (function () {
289
289
  if (typeof response === "boolean" && response) {
290
290
  // Reduction was successfully added. Set payment method to CASH
291
291
  paymentMethodToSet = Payment_1.PaymentMethods.CASH;
292
+ return true;
292
293
  }
293
294
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
294
295
  return response;
@@ -503,7 +503,7 @@ var JourneyBooking = /** @class */ (function (_super) {
503
503
  if (!this.cart) {
504
504
  throw Error("Cart is not initialized yet");
505
505
  }
506
- url = "".concat(this.config.API_ENDPOINT, "/booking/cart/").concat(this.cart.id, "/payment/reduction/trips");
506
+ url = "".concat(this.config.API_ENDPOINT, "/booking/cart/").concat(this.cart.id, "/payment/reduction/trips?");
507
507
  return [2 /*return*/, this.callGetApi(url).then(function (response) {
508
508
  return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.trips;
509
509
  })];
@@ -57,6 +57,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
57
57
  exports.makeDelete = exports.makePost = exports.makeGet = void 0;
58
58
  var axios_1 = require("axios");
59
59
  var config_1 = require("../config");
60
+ var removeNullError = function (resData) {
61
+ var filteredResponse = {};
62
+ Object.keys(resData).filter(function (key) { return key !== "error"; })
63
+ .map(function (key) {
64
+ var _a;
65
+ return filteredResponse = __assign(__assign({}, filteredResponse), (_a = {}, _a[key] = resData[key], _a));
66
+ });
67
+ return filteredResponse;
68
+ };
60
69
  var makeGet = function (url) { return __awaiter(void 0, void 0, void 0, function () {
61
70
  var debug;
62
71
  return __generator(this, function (_a) {
@@ -65,7 +74,7 @@ var makeGet = function (url) { return __awaiter(void 0, void 0, void 0, function
65
74
  console.log("GET_RequestData", url);
66
75
  }
67
76
  return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
68
- var response_1, filteredResponse_1, error_1, resError, resError;
77
+ var response, filteredResponse, error_1, resError, resError;
69
78
  var _a, _b, _c;
70
79
  return __generator(this, function (_d) {
71
80
  switch (_d.label) {
@@ -75,17 +84,12 @@ var makeGet = function (url) { return __awaiter(void 0, void 0, void 0, function
75
84
  headers: __assign({ "Content-Type": "application/json", "Ocp-Apim-Subscription-Key": (0, config_1.getConfig)().OCP_SUBSCRIPTION_KEY }, ((0, config_1.getConfig)().ACCESS_TOKEN && { "Authorization": "Bearer ".concat((0, config_1.getConfig)().ACCESS_TOKEN) })),
76
85
  })];
77
86
  case 1:
78
- response_1 = _d.sent();
79
- filteredResponse_1 = {};
80
- Object.keys(response_1.data).filter(function (key) { return key !== "error"; })
81
- .map(function (key) {
82
- var _a;
83
- return filteredResponse_1 = __assign(__assign({}, filteredResponse_1), (_a = {}, _a[key] = response_1.data[key], _a));
84
- });
87
+ response = _d.sent();
88
+ filteredResponse = removeNullError(response.data);
85
89
  if (debug) {
86
- console.log("GET_ResponseData", url, filteredResponse_1);
90
+ console.log("GET_ResponseData", url, filteredResponse);
87
91
  }
88
- resolve(filteredResponse_1);
92
+ resolve(filteredResponse);
89
93
  return [3 /*break*/, 3];
90
94
  case 2:
91
95
  error_1 = _d.sent();
@@ -120,7 +124,7 @@ var makePost = function (url, data) { return __awaiter(void 0, void 0, void 0, f
120
124
  console.log("POST_RequestData", url, data);
121
125
  }
122
126
  return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
123
- var response, error_2, resError;
127
+ var response, filteredResponse, error_2, resError;
124
128
  var _a, _b, _c, _d, _e;
125
129
  return __generator(this, function (_f) {
126
130
  switch (_f.label) {
@@ -131,10 +135,11 @@ var makePost = function (url, data) { return __awaiter(void 0, void 0, void 0, f
131
135
  })];
132
136
  case 1:
133
137
  response = _f.sent();
138
+ filteredResponse = removeNullError(response.data);
134
139
  if (debug) {
135
- console.log("POST_ResponseData", url, response.data);
140
+ console.log("POST_ResponseData", url, filteredResponse);
136
141
  }
137
- resolve(response.data);
142
+ resolve(filteredResponse);
138
143
  return [3 /*break*/, 3];
139
144
  case 2:
140
145
  error_2 = _f.sent();
@@ -169,7 +174,7 @@ var makeDelete = function (url) { return __awaiter(void 0, void 0, void 0, funct
169
174
  console.log("DELETE_RequestData", url);
170
175
  }
171
176
  return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
172
- var response, error_3, resError;
177
+ var response, filteredResponse, error_3, resError;
173
178
  var _a, _b, _c, _d, _e;
174
179
  return __generator(this, function (_f) {
175
180
  switch (_f.label) {
@@ -180,10 +185,11 @@ var makeDelete = function (url) { return __awaiter(void 0, void 0, void 0, funct
180
185
  })];
181
186
  case 1:
182
187
  response = _f.sent();
188
+ filteredResponse = removeNullError(response.data);
183
189
  if (debug) {
184
- console.log("DELETE_ResponseData", url, response.data);
190
+ console.log("DELETE_ResponseData", url, filteredResponse);
185
191
  }
186
- resolve(response.data);
192
+ resolve(filteredResponse);
187
193
  return [3 /*break*/, 3];
188
194
  case 2:
189
195
  error_3 = _f.sent();
@@ -0,0 +1,8 @@
1
+ /**
2
+ * This method return the ISO string of the date without GMT. An ISO string looks like this: YYYY-MM-DDThh:mm:ss.mmmZ
3
+ * @param {Date | string} date the date to convert
4
+ * @param {boolean} [removeTimezone=true] if true, the timezone will be removed from the ISO string, meaning
5
+ * that the string will look like this: YYYY-MM-DDThh:mm:ss.mmm
6
+ * @returns {string} the ISO string
7
+ */
8
+ export declare const getISOStringWithoutGMT: (date: Date | string | null | undefined, removeTimezone?: boolean) => string | null;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getISOStringWithoutGMT = void 0;
4
+ /**
5
+ * This method return the ISO string of the date without GMT. An ISO string looks like this: YYYY-MM-DDThh:mm:ss.mmmZ
6
+ * @param {Date | string} date the date to convert
7
+ * @param {boolean} [removeTimezone=true] if true, the timezone will be removed from the ISO string, meaning
8
+ * that the string will look like this: YYYY-MM-DDThh:mm:ss.mmm
9
+ * @returns {string} the ISO string
10
+ */
11
+ var getISOStringWithoutGMT = function (date, removeTimezone) {
12
+ if (removeTimezone === void 0) { removeTimezone = true; }
13
+ if (!date)
14
+ return null;
15
+ var newDate = new Date(date);
16
+ var isoString = new Date(newDate.valueOf() - newDate.getTimezoneOffset() * 60000).toISOString();
17
+ return removeTimezone ? isoString.slice(0, -1) : isoString;
18
+ };
19
+ exports.getISOStringWithoutGMT = getISOStringWithoutGMT;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mts-booking-library",
3
- "version": "1.2.13",
3
+ "version": "1.2.14",
4
4
  "description": "Library for use MyTicketSolution Booking API",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -14,10 +14,10 @@
14
14
  },
15
15
  "license": "ISC",
16
16
  "devDependencies": {
17
- "@types/jest": "^29.5.10",
17
+ "@types/jest": "^29.5.11",
18
18
  "jest": "^29.7.0",
19
19
  "ts-jest": "^29.1.1",
20
- "typescript": "^5.3.2"
20
+ "typescript": "^5.3.3"
21
21
  },
22
22
  "files": [
23
23
  "lib/**/*"