@infrab4a/connect-angular 4.0.0-beta.30 → 4.0.0-beta.32

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,7 +1,7 @@
1
1
  import * as i0 from '@angular/core';
2
2
  import { InjectionToken, NgModule, PLATFORM_ID, Injectable, Inject } from '@angular/core';
3
3
  import * as i3 from '@infrab4a/connect';
4
- import { Authentication, AuthenticationFirebaseAuthService, Register, RegisterFirebaseAuthService, SignOut, RecoveryPassword, ProductsIndex, AxiosAdapter, UserBeautyProfileFirestoreRepository, Buy2WinFirestoreRepository, CategoryFirestoreRepository, CheckoutFirestoreRepository, CheckoutSubscriptionFirestoreRepository, CouponFirestoreRepository, CampaignHashtagFirestoreRepository, CampaignDashboardFirestoreRepository, SubscriptionEditionFirestoreRepository, HomeFirestoreRepository, LeadFirestoreRepository, LegacyOrderFirestoreRepository, ShopMenuFirestoreRepository, OrderFirestoreRepository, PaymentFirestoreRepository, ProductFirestoreRepository, ShopSettingsFirestoreRepository, SubscriptionPaymentFirestoreRepository, SubscriptionPlanFirestoreRepository, SubscriptionProductFirestoreRepository, SubscriptionFirestoreRepository, UserFirestoreRepository, UserAddressFirestoreRepository, UserPaymentMethodFirestoreRepository, ProductVariantFirestoreRepository, CategoryHasuraGraphQLRepository, ProductHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository, VariantHasuraGraphQLRepository, FilterOptionHasuraGraphQLRepository, FilterHasuraGraphQLRepository, Where, Shops, CheckoutTypes, CouponTypes, Exclusivities, isNil, NotFoundError, Checkout, pick, LineItem, RoundProductPricesHelper, Category, CheckoutSubscription, Product, RequiredArgumentError, add, Order } from '@infrab4a/connect';
4
+ import { Authentication, AuthenticationFirebaseAuthService, Register, RegisterFirebaseAuthService, SignOut, RecoveryPassword, ProductsIndex, AxiosAdapter, UserBeautyProfileFirestoreRepository, Buy2WinFirestoreRepository, CategoryFirestoreRepository, CheckoutFirestoreRepository, CheckoutSubscriptionFirestoreRepository, CouponFirestoreRepository, CampaignHashtagFirestoreRepository, CampaignDashboardFirestoreRepository, SubscriptionEditionFirestoreRepository, HomeFirestoreRepository, LeadFirestoreRepository, LegacyOrderFirestoreRepository, ShopMenuFirestoreRepository, OrderFirestoreRepository, PaymentFirestoreRepository, ProductFirestoreRepository, ShopSettingsFirestoreRepository, SubscriptionPaymentFirestoreRepository, SubscriptionPlanFirestoreRepository, SubscriptionProductFirestoreRepository, SubscriptionFirestoreRepository, UserFirestoreRepository, UserAddressFirestoreRepository, UserPaymentMethodFirestoreRepository, ProductVariantFirestoreRepository, CategoryHasuraGraphQLRepository, ProductHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository, VariantHasuraGraphQLRepository, FilterOptionHasuraGraphQLRepository, FilterHasuraGraphQLRepository, Where, Shops, CheckoutTypes, CouponTypes, Exclusivities, isNil, NotFoundError, Checkout, pick, LineItem, RoundProductPricesHelper, set, Category, CheckoutSubscription, Product, RequiredArgumentError, add, Order } from '@infrab4a/connect';
5
5
  import * as i1 from '@angular/fire/app';
6
6
  import { provideFirebaseApp, initializeApp } from '@angular/fire/app';
7
7
  import * as i1$1 from '@angular/fire/auth';
@@ -1398,13 +1398,37 @@ class CatalogService {
1398
1398
  constructor(productRepository, categoryRepository) {
1399
1399
  this.productRepository = productRepository;
1400
1400
  this.categoryRepository = categoryRepository;
1401
- this.buildFilterQuery = (category, filters) => { };
1401
+ this.buildFilterQuery = ({ clubDiscount, brands, prices, gender, }) => {
1402
+ const filters = {};
1403
+ if (clubDiscount?.length)
1404
+ set(filters, 'price.subscriberDiscountPercentage', { operator: Where.IN, value: clubDiscount });
1405
+ if (brands?.length)
1406
+ filters.brand = { operator: Where.IN, value: brands };
1407
+ if (gender?.length)
1408
+ filters.tags = {
1409
+ operator: Where.IN,
1410
+ value: gender
1411
+ .map((genderOptions) => genderOptions === 'female' ? 'feminino' : genderOptions === 'male' ? 'masculino' : null)
1412
+ .filter(Boolean),
1413
+ };
1414
+ if (prices?.min || prices?.max)
1415
+ set(filters, prices.subscriberPrice ? 'price.subscriberPrice' : 'price.price', [
1416
+ ...(prices.min ? [{ operator: Where.GTE, value: prices.min }] : []),
1417
+ ...(prices.max ? [{ operator: Where.LTE, value: prices.max }] : []),
1418
+ ]);
1419
+ return filters;
1420
+ };
1402
1421
  this.buildSortQuery = (sort) => {
1403
- const query = {
1404
- stock: 'desc',
1405
- gender: 'asc',
1406
- };
1407
- return query;
1422
+ if (!sort || sort === 'most-relevant')
1423
+ return {};
1424
+ if (sort === 'best-sellers')
1425
+ return { shoppingCount: 'desc' };
1426
+ if (sort === 'biggest-price')
1427
+ return { price: 'desc' };
1428
+ if (sort === 'lowest-price')
1429
+ return { price: 'asc' };
1430
+ if (sort === 'best-rating')
1431
+ return { rate: 'desc' };
1408
1432
  };
1409
1433
  this.buildLimitQuery = (options) => {
1410
1434
  const limit = options?.perPage || 20;
@@ -1415,7 +1439,7 @@ class CatalogService {
1415
1439
  };
1416
1440
  }
1417
1441
  async fetchProducts(category, options) {
1418
- const productsIds = category.products.length
1442
+ const productsIds = category.products?.length
1419
1443
  ? category.products
1420
1444
  : await this.categoryRepository.get({ id: category.id }).then((categoryFound) => categoryFound.products);
1421
1445
  const limits = this.buildLimitQuery(options);
@@ -1424,10 +1448,20 @@ class CatalogService {
1424
1448
  filters: {
1425
1449
  id: { operator: Where.IN, value: productsIds },
1426
1450
  published: true,
1451
+ ...this.buildFilterQuery(options?.filters || {}),
1427
1452
  },
1453
+ ...(options?.sort ? { orderBy: this.buildSortQuery(options?.sort) } : {}),
1428
1454
  limits,
1455
+ options: { minimal: ['price'], maximum: ['price'] },
1429
1456
  })
1430
- .then(({ data, count: total }) => ({ products: data, pages: Math.ceil(total / limits.limit), total }));
1457
+ .then(({ data, count: total, maximum, minimal }) => ({
1458
+ products: { data, total },
1459
+ pages: Math.ceil(total / limits.limit),
1460
+ prices: {
1461
+ price: { min: minimal.price.price, max: maximum.price.price },
1462
+ subscriberPrice: { min: minimal.price.subscriberPrice, max: maximum.price.subscriberPrice },
1463
+ },
1464
+ }));
1431
1465
  }
1432
1466
  }
1433
1467
  CatalogService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CatalogService, deps: [{ token: 'ProductRepository' }, { token: 'CategoryRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
@@ -1443,9 +1477,28 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImpor
1443
1477
  }] }]; } });
1444
1478
 
1445
1479
  class CategoryService {
1446
- constructor(categoryFilterRepository) {
1480
+ constructor(productRepository, categoryRepository, categoryFilterRepository) {
1481
+ this.productRepository = productRepository;
1482
+ this.categoryRepository = categoryRepository;
1447
1483
  this.categoryFilterRepository = categoryFilterRepository;
1448
1484
  }
1485
+ async fetchBrands(category) {
1486
+ const productsIds = category.products?.length
1487
+ ? category.products
1488
+ : await this.categoryRepository.get({ id: category.id }).then((categoryFound) => categoryFound.products);
1489
+ const brands = await this.productRepository
1490
+ .find({
1491
+ filters: {
1492
+ id: { operator: Where.IN, value: productsIds },
1493
+ published: true,
1494
+ },
1495
+ fields: ['brand'],
1496
+ })
1497
+ .then(({ data }) => Object.keys(data.map((product) => product.brand).reduce((brands, brand) => ({ ...brands, [brand]: true }), {})));
1498
+ return this.categoryRepository
1499
+ .find({ filters: { brandCategory: true }, orderBy: { name: 'asc' } })
1500
+ .then(({ data }) => data.filter((category) => brands.includes(category.conditions.brand)));
1501
+ }
1449
1502
  async fetchSubCategories(category) {
1450
1503
  return [];
1451
1504
  }
@@ -1460,11 +1513,17 @@ class CategoryService {
1460
1513
  : categoryFilters;
1461
1514
  }
1462
1515
  }
1463
- CategoryService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CategoryService, deps: [{ token: 'CategoryFilterRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
1516
+ CategoryService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CategoryService, deps: [{ token: 'ProductRepository' }, { token: 'CategoryRepository' }, { token: 'CategoryFilterRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
1464
1517
  CategoryService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CategoryService });
1465
1518
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CategoryService, decorators: [{
1466
1519
  type: Injectable
1467
1520
  }], ctorParameters: function () { return [{ type: undefined, decorators: [{
1521
+ type: Inject,
1522
+ args: ['ProductRepository']
1523
+ }] }, { type: undefined, decorators: [{
1524
+ type: Inject,
1525
+ args: ['CategoryRepository']
1526
+ }] }, { type: undefined, decorators: [{
1468
1527
  type: Inject,
1469
1528
  args: ['CategoryFilterRepository']
1470
1529
  }] }]; } });