@infrab4a/connect-angular 4.17.1 → 4.17.3-beta.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.
- package/esm2020/services/cart.service.mjs +89 -36
- package/fesm2015/infrab4a-connect-angular.mjs +88 -34
- package/fesm2015/infrab4a-connect-angular.mjs.map +1 -1
- package/fesm2020/infrab4a-connect-angular.mjs +86 -35
- package/fesm2020/infrab4a-connect-angular.mjs.map +1 -1
- package/package.json +2 -2
- package/services/cart.service.d.ts +10 -5
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
2
|
import { NgModule, InjectionToken, PLATFORM_ID, Injectable, Inject } from '@angular/core';
|
|
3
|
-
import * as i1$
|
|
3
|
+
import * as i1$3 from '@angular/fire/app';
|
|
4
4
|
import { FirebaseApp, provideFirebaseApp, getApp, initializeApp } from '@angular/fire/app';
|
|
5
5
|
import * as i2 from '@angular/fire/storage';
|
|
6
6
|
import { Storage, provideStorage, getStorage } from '@angular/fire/storage';
|
|
@@ -14,9 +14,9 @@ import { Firestore, provideFirestore, initializeFirestore, memoryLocalCache, doc
|
|
|
14
14
|
import cookie from 'js-cookie';
|
|
15
15
|
import { of, from, combineLatest, throwError, Subject, iif, forkJoin } from 'rxjs';
|
|
16
16
|
import { map, mergeMap, catchError, concatMap, tap } from 'rxjs/operators';
|
|
17
|
+
import * as i3 from '@angular/common/http';
|
|
17
18
|
import { __decorate, __metadata } from 'tslib';
|
|
18
19
|
import { Type } from 'class-transformer';
|
|
19
|
-
import * as i1$3 from '@angular/common/http';
|
|
20
20
|
|
|
21
21
|
const ES_CONFIG = 'ES_CONFIG';
|
|
22
22
|
|
|
@@ -1418,15 +1418,18 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImpor
|
|
|
1418
1418
|
}] }]; } });
|
|
1419
1419
|
|
|
1420
1420
|
class CartService {
|
|
1421
|
-
constructor(authService, checkoutService, defaultShop, productRepository, categoryRepository, variantRepository, buy2WinRepository) {
|
|
1421
|
+
constructor(authService, checkoutService, defaultShop, firebaseOptions, productRepository, categoryRepository, variantRepository, buy2WinRepository, http) {
|
|
1422
1422
|
this.authService = authService;
|
|
1423
1423
|
this.checkoutService = checkoutService;
|
|
1424
1424
|
this.defaultShop = defaultShop;
|
|
1425
|
+
this.firebaseOptions = firebaseOptions;
|
|
1425
1426
|
this.productRepository = productRepository;
|
|
1426
1427
|
this.categoryRepository = categoryRepository;
|
|
1427
1428
|
this.variantRepository = variantRepository;
|
|
1428
1429
|
this.buy2WinRepository = buy2WinRepository;
|
|
1430
|
+
this.http = http;
|
|
1429
1431
|
this.cartSubject = new Subject();
|
|
1432
|
+
this.checkoutUrl = null;
|
|
1430
1433
|
this.updateLineItemInCart = (lineItem, quantity, checkout) => (isNil(checkout) ? this.checkoutService.getCheckout() : of(checkout)).pipe(concatMap((checkoutLoaded) => {
|
|
1431
1434
|
const items = [];
|
|
1432
1435
|
const index = checkoutLoaded.lineItems?.map((checkoutItem) => checkoutItem.id).indexOf(lineItem.id);
|
|
@@ -1504,17 +1507,80 @@ class CartService {
|
|
|
1504
1507
|
const currentItemAmount = currentItemQtd || 0;
|
|
1505
1508
|
return currentItemAmount + quantityToAdd > maxStock;
|
|
1506
1509
|
};
|
|
1510
|
+
this.checkoutUrl = `https://southamerica-east1-${this.firebaseOptions.projectId}.cloudfunctions.net`;
|
|
1511
|
+
}
|
|
1512
|
+
async addItem(item, quantity = 1) {
|
|
1513
|
+
return this.checkoutService.getCheckout().pipe(tap((checkout) => this.http.post(`${this.checkoutUrl}/checkoutAddItemToCart`, {
|
|
1514
|
+
checkoutId: checkout.id,
|
|
1515
|
+
productId: item.id,
|
|
1516
|
+
quantity,
|
|
1517
|
+
})), tap(() => this.checkoutService.getCheckout()), map((updatedCheckout) => this.generateCartObject(updatedCheckout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
|
|
1518
|
+
// return this.generateCartObject(checkoutUpdated.lineItems as LineItem[])
|
|
1519
|
+
// return from(this.checkoutService.getCheckout()).pipe(
|
|
1520
|
+
// concatMap(async (checkout) => await this.buildLineItem({ checkout, item, quantity: quantity || 1 })),
|
|
1521
|
+
// mergeMap(({ checkout, lineItem }) => this.updateLineItemInCart(lineItem, quantity || 1, checkout as Checkout)),
|
|
1522
|
+
// tap((cart) => this.cartSubject.next(cart)),
|
|
1523
|
+
// )
|
|
1524
|
+
}
|
|
1525
|
+
async decreaseItem(item) {
|
|
1526
|
+
return this.checkoutService.getCheckout().pipe(tap((checkout) => this.http.post(`${this.checkoutUrl}/checkoutDecreaseProductFromCart`, {
|
|
1527
|
+
checkoutId: checkout.id,
|
|
1528
|
+
productId: item.id,
|
|
1529
|
+
quantity: 1,
|
|
1530
|
+
})), tap(() => this.checkoutService.getCheckout()), map((updatedCheckout) => this.generateCartObject(updatedCheckout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
|
|
1531
|
+
// return this.checkoutService.getCheckout().pipe(
|
|
1532
|
+
// map((checkout) => {
|
|
1533
|
+
// const checkoutItem = checkout.lineItems?.find((lineItem) => lineItem.id === item.id)
|
|
1534
|
+
// if (!isNil(checkoutItem)) checkoutItem.quantity -= checkoutItem.quantity > 1 ? 1 : 0
|
|
1535
|
+
// return checkout
|
|
1536
|
+
// }),
|
|
1537
|
+
// concatMap((checkout) => this.checkoutService.updateCheckoutLineItems(checkout)),
|
|
1538
|
+
// map((checkout) => this.generateCartObject(checkout.lineItems)),
|
|
1539
|
+
// tap((cart) => this.cartSubject.next(cart)),
|
|
1540
|
+
// )
|
|
1507
1541
|
}
|
|
1508
|
-
|
|
1509
|
-
return
|
|
1542
|
+
removeItem(item) {
|
|
1543
|
+
return this.checkoutService.getCheckout().pipe(tap((checkout) => this.http.post(`${this.checkoutUrl}/checkoutRemoveProductFromCart`, {
|
|
1544
|
+
checkoutId: checkout.id,
|
|
1545
|
+
productId: item.id,
|
|
1546
|
+
})), tap(() => this.checkoutService.getCheckout()), map((updatedCheckout) => this.generateCartObject(updatedCheckout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
|
|
1547
|
+
// return this.checkoutService.getCheckout().pipe(
|
|
1548
|
+
// map((checkout) => {
|
|
1549
|
+
// const index = checkout.lineItems.findIndex((lineItem) => lineItem.id === item.id)
|
|
1550
|
+
// if (index >= 0) checkout.lineItems.splice(index, 1)
|
|
1551
|
+
// return checkout
|
|
1552
|
+
// }),
|
|
1553
|
+
// concatMap((checkout) => this.checkoutService.updateCheckoutLineItems(checkout)),
|
|
1554
|
+
// map((checkout) => this.generateCartObject(checkout.lineItems)),
|
|
1555
|
+
// tap((cart) => this.cartSubject.next(cart)),
|
|
1510
1556
|
}
|
|
1511
|
-
|
|
1512
|
-
return this.checkoutService.getCheckout().pipe(
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1557
|
+
updateUserCart(user) {
|
|
1558
|
+
return this.checkoutService.getCheckout().pipe(concatMap((checkout) => this.checkoutService.updateCheckoutUser(Checkout.toInstance({ ...checkout.toPlain(), user }))), tap(() => (this.user = user)), tap((checkout) => this.http.post(`${this.checkoutUrl}/checkoutUpdateUserCart`, {
|
|
1559
|
+
checkoutId: checkout.id,
|
|
1560
|
+
})), tap(() => this.checkoutService.getCheckout()), map((updatedCheckout) => this.generateCartObject(updatedCheckout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
|
|
1561
|
+
// return this.checkoutService.getCheckout().pipe(
|
|
1562
|
+
// concatMap((checkout) =>
|
|
1563
|
+
// this.checkoutService.updateCheckoutUser(Checkout.toInstance({ ...checkout.toPlain(), user })),
|
|
1564
|
+
// ),
|
|
1565
|
+
// concatMap(
|
|
1566
|
+
// async (checkout) =>
|
|
1567
|
+
// await this.checkoutService
|
|
1568
|
+
// .updateCheckoutLineItems(
|
|
1569
|
+
// Checkout.toInstance({
|
|
1570
|
+
// ...checkout.toPlain(),
|
|
1571
|
+
// lineItems: checkout.lineItems?.length
|
|
1572
|
+
// ? await Promise.all(
|
|
1573
|
+
// checkout.lineItems?.map(async (item) => (await this.buildLineItem({ checkout, item })).lineItem),
|
|
1574
|
+
// )
|
|
1575
|
+
// : [],
|
|
1576
|
+
// }),
|
|
1577
|
+
// )
|
|
1578
|
+
// .toPromise(),
|
|
1579
|
+
// ),
|
|
1580
|
+
// map((checkout) => this.generateCartObject(checkout.lineItems)),
|
|
1581
|
+
// tap((cart) => (this.user = user)),
|
|
1582
|
+
// tap((cart) => this.cartSubject.next(cart)),
|
|
1583
|
+
// )
|
|
1518
1584
|
}
|
|
1519
1585
|
getCart(checkout) {
|
|
1520
1586
|
this.buildCartFromCheckout(checkout).subscribe((cart) => this.cartSubject.next(cart));
|
|
@@ -1526,24 +1592,6 @@ class CartService {
|
|
|
1526
1592
|
getVariantPriceDiscount(item) {
|
|
1527
1593
|
return this.authService.getUser().pipe(concatMap((user) => iif(() => user.isSubscriber && !!item.price.subscriberPrice, of(item.price.subscriberPrice), of(item.price.price))), catchError(() => of(item.price.price)));
|
|
1528
1594
|
}
|
|
1529
|
-
removeItem(item) {
|
|
1530
|
-
return this.checkoutService.getCheckout().pipe(map((checkout) => {
|
|
1531
|
-
const index = checkout.lineItems.findIndex((lineItem) => lineItem.id === item.id);
|
|
1532
|
-
if (index >= 0)
|
|
1533
|
-
checkout.lineItems.splice(index, 1);
|
|
1534
|
-
return checkout;
|
|
1535
|
-
}), concatMap((checkout) => this.checkoutService.updateCheckoutLineItems(checkout)), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
|
|
1536
|
-
}
|
|
1537
|
-
updateUserCart(user) {
|
|
1538
|
-
return this.checkoutService.getCheckout().pipe(concatMap((checkout) => this.checkoutService.updateCheckoutUser(Checkout.toInstance({ ...checkout.toPlain(), user }))), concatMap(async (checkout) => await this.checkoutService
|
|
1539
|
-
.updateCheckoutLineItems(Checkout.toInstance({
|
|
1540
|
-
...checkout.toPlain(),
|
|
1541
|
-
lineItems: checkout.lineItems?.length
|
|
1542
|
-
? await Promise.all(checkout.lineItems?.map(async (item) => (await this.buildLineItem({ checkout, item })).lineItem))
|
|
1543
|
-
: [],
|
|
1544
|
-
}))
|
|
1545
|
-
.toPromise()), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => (this.user = user)), tap((cart) => this.cartSubject.next(cart)));
|
|
1546
|
-
}
|
|
1547
1595
|
clearCart() {
|
|
1548
1596
|
return this.checkoutService.getCheckout().pipe(map((checkout) => {
|
|
1549
1597
|
this.checkoutService.clearCheckoutFromSession();
|
|
@@ -1678,13 +1726,16 @@ class CartService {
|
|
|
1678
1726
|
});
|
|
1679
1727
|
}
|
|
1680
1728
|
}
|
|
1681
|
-
CartService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CartService, deps: [{ token: AuthService }, { token: CheckoutService }, { token: DEFAULT_SHOP }, { token: 'ProductRepository' }, { token: 'CategoryRepository' }, { token: 'VariantRepository' }, { token: 'Buy2WinRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1729
|
+
CartService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CartService, deps: [{ token: AuthService }, { token: CheckoutService }, { token: DEFAULT_SHOP }, { token: FIREBASE_OPTIONS }, { token: 'ProductRepository' }, { token: 'CategoryRepository' }, { token: 'VariantRepository' }, { token: 'Buy2WinRepository' }, { token: i3.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1682
1730
|
CartService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CartService });
|
|
1683
1731
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CartService, decorators: [{
|
|
1684
1732
|
type: Injectable
|
|
1685
1733
|
}], ctorParameters: function () { return [{ type: AuthService }, { type: CheckoutService }, { type: i1$2.Shops, decorators: [{
|
|
1686
1734
|
type: Inject,
|
|
1687
1735
|
args: [DEFAULT_SHOP]
|
|
1736
|
+
}] }, { type: undefined, decorators: [{
|
|
1737
|
+
type: Inject,
|
|
1738
|
+
args: [FIREBASE_OPTIONS]
|
|
1688
1739
|
}] }, { type: undefined, decorators: [{
|
|
1689
1740
|
type: Inject,
|
|
1690
1741
|
args: ['ProductRepository']
|
|
@@ -1697,7 +1748,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImpor
|
|
|
1697
1748
|
}] }, { type: i1$2.Buy2WinFirestoreRepository, decorators: [{
|
|
1698
1749
|
type: Inject,
|
|
1699
1750
|
args: ['Buy2WinRepository']
|
|
1700
|
-
}] }]; } });
|
|
1751
|
+
}] }, { type: i3.HttpClient }]; } });
|
|
1701
1752
|
|
|
1702
1753
|
class NewCategoryStructureAdapter {
|
|
1703
1754
|
constructor(categoryRepository) {
|
|
@@ -2618,11 +2669,11 @@ class ShippingService {
|
|
|
2618
2669
|
return false;
|
|
2619
2670
|
}
|
|
2620
2671
|
}
|
|
2621
|
-
ShippingService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: ShippingService, deps: [{ token:
|
|
2672
|
+
ShippingService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: ShippingService, deps: [{ token: i3.HttpClient }, { token: BACKEND_URL }, { token: HomeShopService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
2622
2673
|
ShippingService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: ShippingService });
|
|
2623
2674
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: ShippingService, decorators: [{
|
|
2624
2675
|
type: Injectable
|
|
2625
|
-
}], ctorParameters: function () { return [{ type:
|
|
2676
|
+
}], ctorParameters: function () { return [{ type: i3.HttpClient }, { type: undefined, decorators: [{
|
|
2626
2677
|
type: Inject,
|
|
2627
2678
|
args: [BACKEND_URL]
|
|
2628
2679
|
}] }, { type: HomeShopService }]; } });
|
|
@@ -2652,7 +2703,7 @@ class AngularConnectModule {
|
|
|
2652
2703
|
}
|
|
2653
2704
|
}
|
|
2654
2705
|
AngularConnectModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularConnectModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
2655
|
-
AngularConnectModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.1.0", ngImport: i0, type: AngularConnectModule, imports: [i1$
|
|
2706
|
+
AngularConnectModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.1.0", ngImport: i0, type: AngularConnectModule, imports: [i1$3.FirebaseAppModule, i2.StorageModule, AngularElasticSeachModule,
|
|
2656
2707
|
AngularVertexSeachModule,
|
|
2657
2708
|
AngularFirebaseAuthModule,
|
|
2658
2709
|
AngularFirestoreModule,
|