@infrab4a/connect-angular 3.4.0-beta.2 → 3.4.0-beta.4

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.
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('rxjs'), require('rxjs/operators'), require('@angular/fire/auth'), require('@infrab4a/connect'), require('js-cookie'), require('ts-custom-error'), require('@angular/fire/firestore'), require('@angular/common/http'), require('@angular/fire')) :
3
- typeof define === 'function' && define.amd ? define('@infrab4a/connect-angular', ['exports', '@angular/core', 'rxjs', 'rxjs/operators', '@angular/fire/auth', '@infrab4a/connect', 'js-cookie', 'ts-custom-error', '@angular/fire/firestore', '@angular/common/http', '@angular/fire'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.infrab4a = global.infrab4a || {}, global.infrab4a["connect-angular"] = {}), global.ng.core, global.rxjs, global.rxjs.operators, global.ng.fire.auth, global["@infrab4a/connect"], global["js-cookie"], global["ts-custom-error"], global.ng.fire.firestore, global.ng.common.http, global.ng.fire));
5
- })(this, (function (exports, i0, rxjs, operators, i1, i1$1, cookie, tsCustomError, i1$2, i1$3, fire) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('rxjs'), require('rxjs/operators'), require('@angular/fire/auth'), require('@infrab4a/connect'), require('js-cookie'), require('ts-custom-error'), require('@angular/fire/firestore'), require('@infrab4a/connect/src'), require('@angular/common/http'), require('@angular/fire')) :
3
+ typeof define === 'function' && define.amd ? define('@infrab4a/connect-angular', ['exports', '@angular/core', 'rxjs', 'rxjs/operators', '@angular/fire/auth', '@infrab4a/connect', 'js-cookie', 'ts-custom-error', '@angular/fire/firestore', '@infrab4a/connect/src', '@angular/common/http', '@angular/fire'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.infrab4a = global.infrab4a || {}, global.infrab4a["connect-angular"] = {}), global.ng.core, global.rxjs, global.rxjs.operators, global.ng.fire.auth, global["@infrab4a/connect"], global["js-cookie"], global["ts-custom-error"], global.ng.fire.firestore, global.src, global.ng.common.http, global.ng.fire));
5
+ })(this, (function (exports, i0, rxjs, operators, i1, i1$1, cookie, tsCustomError, i1$2, src, i1$3, fire) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
@@ -1223,51 +1223,90 @@
1223
1223
  } });
1224
1224
 
1225
1225
  var ShippingService = /** @class */ (function () {
1226
- function ShippingService(http, apiUrl) {
1226
+ function ShippingService(http, homeService, apiUrl) {
1227
1227
  this.http = http;
1228
+ this.homeService = homeService;
1228
1229
  this.apiUrl = apiUrl;
1229
1230
  }
1230
- ShippingService.prototype.getMensShippingMethods = function (zip, weightGrams, totalPrice, personId, subscriptionPlan) {
1231
+ ShippingService.prototype.getMensShippingMethods = function (zip, weightGrams, totalPrice, personId, shop, subscriptionPlan) {
1232
+ var _this = this;
1233
+ rxjs.combineLatest([
1234
+ this.homeService.getHomeData(),
1235
+ this.http.get(this.apiUrl + "open/checkshippingcompany?personId=" + personId + "&postalCode=" + zip + "&weightGrams=" + weightGrams)
1236
+ ]).pipe(operators.map(function (datas, shippings) { return console.log('combineLatest', datas, shippings); }));
1231
1237
  return this.http.get(this.apiUrl + "open/checkshippingcompany?personId=" + personId + "&postalCode=" + zip + "&weightGrams=" + weightGrams)
1232
- .pipe(operators.map(function (data) { return data.result; }), operators.map(function (shippingMethods) {
1233
- var shippingMethodsResponse = [];
1234
- if (!shippingMethods.length)
1235
- return [];
1236
- if (totalPrice >= 200) {
1237
- return shippingMethods.map(function (s) {
1238
- if (s.serviceName !== 'Same Day')
1239
- return Object.assign(Object.assign({}, s), { totalPrice: 0 });
1240
- else
1241
- return s;
1242
- });
1243
- }
1244
- if (subscriptionPlan && subscriptionPlan == 'SELECT') {
1245
- return shippingMethods.map(function (s) {
1246
- if (s.serviceName !== 'Same Day')
1247
- return Object.assign(Object.assign({}, s), { totalPrice: 0 });
1248
- else
1249
- return s;
1250
- });
1251
- }
1252
- if (subscriptionPlan && subscriptionPlan == 'PRIME') {
1253
- return shippingMethods.map(function (s) {
1254
- if (s.serviceName !== 'Same Day')
1255
- return Object.assign(Object.assign({}, s), { totalPrice: s.totalPrice / 2 });
1256
- else
1257
- return s;
1258
- });
1259
- }
1260
- return shippingMethodsResponse;
1261
- }));
1238
+ .pipe(operators.map(function (data) { return data.result; }), operators.map(function (shippingMethods) { return __awaiter(_this, void 0, void 0, function () {
1239
+ var shippingMethodsResponse, datas;
1240
+ return __generator(this, function (_a) {
1241
+ switch (_a.label) {
1242
+ case 0:
1243
+ shippingMethodsResponse = shippingMethods;
1244
+ console.log('shippingMethods', shippingMethods);
1245
+ if (!shippingMethods.length)
1246
+ return [2 /*return*/, []];
1247
+ return [4 /*yield*/, this.homeService.getHomeData().toPromise().then(function (data) { return data.sameDayNotAvaliable; })];
1248
+ case 1:
1249
+ datas = _a.sent();
1250
+ if (this.isHolidays(datas)) {
1251
+ shippingMethodsResponse = shippingMethods.filter(function (method) { return method.ShippingCompanyName !== 'Same Day'; });
1252
+ }
1253
+ if (totalPrice >= 200 || this.isFreeShippingBySubscription(shop, subscriptionPlan)) {
1254
+ return [2 /*return*/, shippingMethodsResponse.map(function (s) {
1255
+ if (s.serviceName !== 'Same Day')
1256
+ return Object.assign(Object.assign({}, s), { totalPrice: 0 });
1257
+ else
1258
+ return s;
1259
+ })];
1260
+ }
1261
+ if (this.isFreeShippingBySubscription(shop, subscriptionPlan)) {
1262
+ return [2 /*return*/, shippingMethodsResponse.map(function (s) {
1263
+ if (s.serviceName !== 'Same Day')
1264
+ return Object.assign(Object.assign({}, s), { totalPrice: s.totalPrice / 2 });
1265
+ else
1266
+ return s;
1267
+ })];
1268
+ }
1269
+ return [2 /*return*/, shippingMethodsResponse];
1270
+ }
1271
+ });
1272
+ }); }));
1273
+ };
1274
+ ShippingService.prototype.isFreeShippingBySubscription = function (shop, subscriptionPlan) {
1275
+ if (!subscriptionPlan)
1276
+ return false;
1277
+ if (shop == src.Shops.MENSMARKET && subscriptionPlan == 'SELECT') {
1278
+ return true;
1279
+ }
1280
+ return false;
1281
+ };
1282
+ ShippingService.prototype.isHalfShippingBySubscription = function (shop, subscriptionPlan) {
1283
+ if (!subscriptionPlan)
1284
+ return false;
1285
+ if (shop == src.Shops.MENSMARKET && subscriptionPlan == 'PRIME') {
1286
+ return true;
1287
+ }
1288
+ return false;
1289
+ };
1290
+ ShippingService.prototype.isHolidays = function (datas) {
1291
+ var today = new Date();
1292
+ for (var key in datas) {
1293
+ var start = new Date(today.getFullYear() + "-" + datas[key].beginDate);
1294
+ var end = new Date(today.getFullYear() + "-" + datas[key].endDate);
1295
+ if (start > end)
1296
+ end = new Date(today.getFullYear() + 1 + "-" + datas[key].endDate);
1297
+ if (today >= start && today <= end)
1298
+ return true;
1299
+ }
1300
+ return false;
1262
1301
  };
1263
1302
  return ShippingService;
1264
1303
  }());
1265
- ShippingService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0__namespace, type: ShippingService, deps: [{ token: i1__namespace$3.HttpClient }, { token: API_URL }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
1304
+ ShippingService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0__namespace, type: ShippingService, deps: [{ token: i1__namespace$3.HttpClient }, { token: HomeShopService }, { token: API_URL }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
1266
1305
  ShippingService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0__namespace, type: ShippingService });
1267
1306
  i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0__namespace, type: ShippingService, decorators: [{
1268
1307
  type: i0.Injectable
1269
1308
  }], ctorParameters: function () {
1270
- return [{ type: i1__namespace$3.HttpClient }, { type: undefined, decorators: [{
1309
+ return [{ type: i1__namespace$3.HttpClient }, { type: HomeShopService }, { type: undefined, decorators: [{
1271
1310
  type: i0.Inject,
1272
1311
  args: [API_URL]
1273
1312
  }] }];