@infrab4a/connect-angular 5.1.0 → 6.0.0-alpha.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/eslint.config.js +18 -0
- package/index.ts +1 -0
- package/karma.conf.js +32 -0
- package/ng-package.json +8 -0
- package/package.json +10 -28
- package/project.json +37 -0
- package/src/angular-connect.module.ts +256 -0
- package/src/angular-elastic-search.module.ts +23 -0
- package/src/angular-firebase-auth.module.ts +101 -0
- package/src/angular-firestore.module.ts +371 -0
- package/src/angular-hasura-graphql.module.ts +219 -0
- package/src/angular-vertex-search.module.ts +23 -0
- package/src/consts/backend-url.const.ts +1 -0
- package/src/consts/category-structure.ts +1 -0
- package/src/consts/default-shop.const.ts +1 -0
- package/src/consts/es-config.const.ts +1 -0
- package/src/consts/firebase-const.ts +5 -0
- package/src/consts/hasura-options.const.ts +1 -0
- package/src/consts/index.ts +8 -0
- package/src/consts/persistence.const.ts +1 -0
- package/src/consts/storage-base-url.const.ts +1 -0
- package/src/consts/vertex-config.const.ts +1 -0
- package/src/helpers/index.ts +1 -0
- package/src/helpers/mobile-operation-system-checker.helper.ts +10 -0
- package/src/index.ts +6 -0
- package/src/interfaces/catalog-strategies.interface.ts +36 -0
- package/src/interfaces/category-facades.interface.ts +7 -0
- package/src/interfaces/index.ts +2 -0
- package/src/persistence/cookie-data-persistence.ts +21 -0
- package/src/persistence/data-persistence.ts +7 -0
- package/src/persistence/index.ts +2 -0
- package/src/services/auth.service.ts +39 -0
- package/src/services/cart/cart-services.facade.ts +14 -0
- package/src/services/cart/index.ts +1 -0
- package/src/services/cart.service.ts +124 -0
- package/src/services/catalog/adapters/category-structure.adapter.ts +5 -0
- package/src/services/catalog/adapters/index.ts +3 -0
- package/src/services/catalog/adapters/new-category-structure.adapter.ts +42 -0
- package/src/services/catalog/adapters/old-category-structure.adapter.ts +17 -0
- package/src/services/catalog/catalog.service.ts +153 -0
- package/src/services/catalog/category.service.ts +52 -0
- package/src/services/catalog/context/catalog-search.context.ts +61 -0
- package/src/services/catalog/enums/index.ts +1 -0
- package/src/services/catalog/enums/product-sorts.enum.ts +9 -0
- package/src/services/catalog/facades/catalog-service.facade.ts +32 -0
- package/src/services/catalog/facades/catalog-strategies.facade.ts +12 -0
- package/src/services/catalog/facades/category-repository.facade.ts +10 -0
- package/src/services/catalog/facades/category-service.facade.ts +25 -0
- package/src/services/catalog/facades/index.ts +5 -0
- package/src/services/catalog/facades/product-catalog.facade.ts +13 -0
- package/src/services/catalog/helpers/brand-manager.helper.ts +63 -0
- package/src/services/catalog/helpers/catalog-filter.helper.ts +50 -0
- package/src/services/catalog/helpers/catalog-sort.helper.ts +54 -0
- package/src/services/catalog/helpers/index.ts +4 -0
- package/src/services/catalog/helpers/product-fields.helper.ts +35 -0
- package/src/services/catalog/index.ts +7 -0
- package/src/services/catalog/models/category-with-tree.model.ts +7 -0
- package/src/services/catalog/models/index.ts +1 -0
- package/src/services/catalog/services/catalog-helpers.service.ts +35 -0
- package/src/services/catalog/services/catalog-operations.facade.ts +24 -0
- package/src/services/catalog/services/catalog-repository.service.ts +20 -0
- package/src/services/catalog/services/index.ts +4 -0
- package/src/services/catalog/services/product-management.facade.ts +20 -0
- package/src/services/catalog/strategies/category-search.strategy.ts +172 -0
- package/src/services/catalog/strategies/index.ts +3 -0
- package/src/services/catalog/strategies/profile-search.strategy.ts +51 -0
- package/src/services/catalog/strategies/term-search.strategy.ts +178 -0
- package/src/services/catalog/strategies/types/strategy-params.type.ts +58 -0
- package/src/services/catalog/types/fetch-products-options.type.ts +10 -0
- package/src/services/catalog/types/fetch-products-params.type.ts +27 -0
- package/src/services/catalog/types/fetch-products-response.type.ts +11 -0
- package/src/services/catalog/types/index.ts +5 -0
- package/src/services/catalog/types/method-params.type.ts +21 -0
- package/src/services/catalog/types/product-sort.type.ts +3 -0
- package/src/services/catalog/wishlist.service.ts +368 -0
- package/src/services/checkout/checkout-dependencies.facade.ts +13 -0
- package/src/services/checkout/checkout-repositories.facade.ts +10 -0
- package/src/services/checkout/index.ts +2 -0
- package/src/services/checkout-subscription.service.ts +76 -0
- package/src/services/checkout.service.ts +196 -0
- package/src/services/coupon/coupon-repositories.facade.ts +11 -0
- package/src/services/coupon/index.ts +1 -0
- package/src/services/coupon/types/coupon-params.type.ts +15 -0
- package/src/services/coupon.service.ts +347 -0
- package/src/services/errors/group-invalid-coupon.error.ts +9 -0
- package/src/services/errors/index.ts +2 -0
- package/src/services/errors/invalid-coupon.error.ts +7 -0
- package/src/services/helpers/index.ts +1 -0
- package/src/services/helpers/util.helper.ts +17 -0
- package/src/services/home-shop/home-shop-repositories.facade.ts +11 -0
- package/src/services/home-shop/index.ts +1 -0
- package/src/services/home-shop.service.ts +196 -0
- package/src/services/index.ts +9 -0
- package/src/services/order.service.ts +23 -0
- package/src/services/shared/configuration.facade.ts +21 -0
- package/src/services/shared/index.ts +1 -0
- package/src/services/types/index.ts +2 -0
- package/src/services/types/required-checkout-data.type.ts +3 -0
- package/src/services/types/required-checkout-subscription-data.type.ts +3 -0
- package/src/types/firebase-app-config.type.ts +1 -0
- package/src/types/index.ts +1 -0
- package/tsconfig.json +17 -0
- package/tsconfig.lib.json +13 -0
- package/tsconfig.lib.prod.json +13 -0
- package/tsconfig.spec.json +17 -0
- package/angular-connect.module.d.ts +0 -26
- package/angular-elastic-search.module.d.ts +0 -9
- package/angular-firebase-auth.module.d.ts +0 -11
- package/angular-firestore.module.d.ts +0 -18
- package/angular-hasura-graphql.module.d.ts +0 -16
- package/consts/backend-url.const.d.ts +0 -1
- package/consts/category-structure.d.ts +0 -1
- package/consts/default-shop.const.d.ts +0 -1
- package/consts/es-config.const.d.ts +0 -1
- package/consts/firebase-const.d.ts +0 -3
- package/consts/hasura-options.const.d.ts +0 -1
- package/consts/index.d.ts +0 -7
- package/consts/persistence.const.d.ts +0 -1
- package/consts/storage-base-url.const.d.ts +0 -1
- package/esm2020/angular-connect.module.mjs +0 -115
- package/esm2020/angular-elastic-search.module.mjs +0 -34
- package/esm2020/angular-firebase-auth.module.mjs +0 -115
- package/esm2020/angular-firestore.module.mjs +0 -504
- package/esm2020/angular-hasura-graphql.module.mjs +0 -265
- package/esm2020/consts/backend-url.const.mjs +0 -2
- package/esm2020/consts/category-structure.mjs +0 -2
- package/esm2020/consts/default-shop.const.mjs +0 -2
- package/esm2020/consts/es-config.const.mjs +0 -2
- package/esm2020/consts/firebase-const.mjs +0 -4
- package/esm2020/consts/hasura-options.const.mjs +0 -2
- package/esm2020/consts/index.mjs +0 -8
- package/esm2020/consts/persistence.const.mjs +0 -2
- package/esm2020/consts/storage-base-url.const.mjs +0 -2
- package/esm2020/helpers/index.mjs +0 -2
- package/esm2020/helpers/mobile-operation-system-checker.helper.mjs +0 -7
- package/esm2020/index.mjs +0 -7
- package/esm2020/infrab4a-connect-angular.mjs +0 -5
- package/esm2020/persistence/cookie-data-persistence.mjs +0 -22
- package/esm2020/persistence/data-persistence.mjs +0 -2
- package/esm2020/persistence/index.mjs +0 -3
- package/esm2020/services/auth.service.mjs +0 -37
- package/esm2020/services/cart.service.mjs +0 -281
- package/esm2020/services/catalog/adapters/category-structure.adapter.mjs +0 -2
- package/esm2020/services/catalog/adapters/index.mjs +0 -4
- package/esm2020/services/catalog/adapters/new-category-structure.adapter.mjs +0 -43
- package/esm2020/services/catalog/adapters/old-category-structure.adapter.mjs +0 -23
- package/esm2020/services/catalog/catalog.service.mjs +0 -194
- package/esm2020/services/catalog/category.service.mjs +0 -51
- package/esm2020/services/catalog/enums/index.mjs +0 -2
- package/esm2020/services/catalog/enums/product-sorts.enum.mjs +0 -11
- package/esm2020/services/catalog/index.mjs +0 -8
- package/esm2020/services/catalog/models/category-with-tree.model.mjs +0 -10
- package/esm2020/services/catalog/models/index.mjs +0 -2
- package/esm2020/services/catalog/types/index.mjs +0 -2
- package/esm2020/services/catalog/types/product-sort.type.mjs +0 -2
- package/esm2020/services/catalog/wishlist.service.mjs +0 -115
- package/esm2020/services/checkout-subscription.service.mjs +0 -50
- package/esm2020/services/checkout.service.mjs +0 -68
- package/esm2020/services/coupon.service.mjs +0 -235
- package/esm2020/services/helpers/index.mjs +0 -2
- package/esm2020/services/helpers/util.helper.mjs +0 -18
- package/esm2020/services/home-shop.service.mjs +0 -125
- package/esm2020/services/index.mjs +0 -11
- package/esm2020/services/order.service.mjs +0 -30
- package/esm2020/services/shipping.service.mjs +0 -96
- package/esm2020/services/types/index.mjs +0 -3
- package/esm2020/services/types/required-checkout-data.type.mjs +0 -2
- package/esm2020/services/types/required-checkout-subscription-data.type.mjs +0 -2
- package/esm2020/services/types/shipping-methods.type.mjs +0 -2
- package/esm2020/types/firebase-app-config.type.mjs +0 -2
- package/esm2020/types/index.mjs +0 -2
- package/fesm2015/infrab4a-connect-angular.mjs +0 -2417
- package/fesm2015/infrab4a-connect-angular.mjs.map +0 -1
- package/fesm2020/infrab4a-connect-angular.mjs +0 -2352
- package/fesm2020/infrab4a-connect-angular.mjs.map +0 -1
- package/helpers/index.d.ts +0 -1
- package/helpers/mobile-operation-system-checker.helper.d.ts +0 -3
- package/index.d.ts +0 -6
- package/persistence/cookie-data-persistence.d.ts +0 -10
- package/persistence/data-persistence.d.ts +0 -6
- package/persistence/index.d.ts +0 -2
- package/services/auth.service.d.ts +0 -18
- package/services/cart.service.d.ts +0 -42
- package/services/catalog/adapters/category-structure.adapter.d.ts +0 -4
- package/services/catalog/adapters/index.d.ts +0 -3
- package/services/catalog/adapters/new-category-structure.adapter.d.ts +0 -12
- package/services/catalog/adapters/old-category-structure.adapter.d.ts +0 -10
- package/services/catalog/catalog.service.d.ts +0 -86
- package/services/catalog/category.service.d.ts +0 -20
- package/services/catalog/enums/index.d.ts +0 -1
- package/services/catalog/enums/product-sorts.enum.d.ts +0 -9
- package/services/catalog/index.d.ts +0 -7
- package/services/catalog/models/category-with-tree.model.d.ts +0 -4
- package/services/catalog/models/index.d.ts +0 -1
- package/services/catalog/types/index.d.ts +0 -1
- package/services/catalog/types/product-sort.type.d.ts +0 -2
- package/services/catalog/wishlist.service.d.ts +0 -38
- package/services/checkout-subscription.service.d.ts +0 -19
- package/services/checkout.service.d.ts +0 -24
- package/services/coupon.service.d.ts +0 -29
- package/services/helpers/index.d.ts +0 -1
- package/services/helpers/util.helper.d.ts +0 -3
- package/services/home-shop.service.d.ts +0 -26
- package/services/index.d.ts +0 -10
- package/services/order.service.d.ts +0 -13
- package/services/shipping.service.d.ts +0 -19
- package/services/types/index.d.ts +0 -2
- package/services/types/required-checkout-data.type.d.ts +0 -2
- package/services/types/required-checkout-subscription-data.type.d.ts +0 -2
- package/services/types/shipping-methods.type.d.ts +0 -12
- package/types/firebase-app-config.type.d.ts +0 -1
- package/types/index.d.ts +0 -1
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { Injectable } from '@angular/core'
|
|
2
|
+
import {
|
|
3
|
+
Product,
|
|
4
|
+
ProductSearch,
|
|
5
|
+
RepositoryCacheOptions,
|
|
6
|
+
RepositoryFindResult,
|
|
7
|
+
Shops,
|
|
8
|
+
Where,
|
|
9
|
+
isEmpty,
|
|
10
|
+
} from '@infrab4a/connect'
|
|
11
|
+
|
|
12
|
+
import { CatalogSearchParams, CatalogSearchStrategy } from '../../../interfaces'
|
|
13
|
+
import { CatalogHelpersService, CatalogRepositoryService } from '../services'
|
|
14
|
+
|
|
15
|
+
import {
|
|
16
|
+
SortByTermRelevanceParams,
|
|
17
|
+
TermSearchDefaultParams,
|
|
18
|
+
TermSearchMostRelevantParams,
|
|
19
|
+
} from './types/strategy-params.type'
|
|
20
|
+
|
|
21
|
+
@Injectable()
|
|
22
|
+
export class TermSearchStrategy implements CatalogSearchStrategy {
|
|
23
|
+
private productsByTerm: Record<string, string[]> = {}
|
|
24
|
+
|
|
25
|
+
constructor(
|
|
26
|
+
private readonly repositoryService: CatalogRepositoryService,
|
|
27
|
+
private readonly helpersService: CatalogHelpersService,
|
|
28
|
+
) {}
|
|
29
|
+
|
|
30
|
+
async search(
|
|
31
|
+
params: CatalogSearchParams,
|
|
32
|
+
shop: Shops,
|
|
33
|
+
_optionsCache?: { cache?: RepositoryCacheOptions },
|
|
34
|
+
): Promise<RepositoryFindResult<Product>> {
|
|
35
|
+
const { term, filters, limits, sort, mainGender } = params
|
|
36
|
+
|
|
37
|
+
if (!term) {
|
|
38
|
+
throw new Error('Term is required for TermSearchStrategy')
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const productIds = await this.findCatalogIdsBySearch(term, shop)
|
|
42
|
+
|
|
43
|
+
if (sort === 'most-relevant') {
|
|
44
|
+
return this.searchWithMostRelevant({
|
|
45
|
+
productIds,
|
|
46
|
+
filters,
|
|
47
|
+
limits,
|
|
48
|
+
shop,
|
|
49
|
+
mainGender,
|
|
50
|
+
})
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return this.searchDefault({
|
|
54
|
+
productIds,
|
|
55
|
+
filters,
|
|
56
|
+
limits,
|
|
57
|
+
shop,
|
|
58
|
+
mainGender,
|
|
59
|
+
fields: this.helpersService.getFieldsHelper().getStandardFields(),
|
|
60
|
+
})
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
private async searchWithMostRelevant(params: TermSearchMostRelevantParams): Promise<RepositoryFindResult<Product>> {
|
|
64
|
+
const { productIds, filters, shop, mainGender } = params
|
|
65
|
+
const productCatalog = this.repositoryService.getProductCatalog()
|
|
66
|
+
const filterHelper = this.helpersService.getFilterHelper()
|
|
67
|
+
|
|
68
|
+
const totalResult = await productCatalog.productRepository.findCatalog(
|
|
69
|
+
{
|
|
70
|
+
fields: ['id', 'stock', 'gender'],
|
|
71
|
+
filters: {
|
|
72
|
+
id: { operator: Where.IN, value: productIds },
|
|
73
|
+
published: { operator: Where.EQUALS, value: true },
|
|
74
|
+
...filterHelper.buildFilterQuery(filters || {}),
|
|
75
|
+
},
|
|
76
|
+
options: {
|
|
77
|
+
minimal: ['price'],
|
|
78
|
+
maximum: ['price'],
|
|
79
|
+
...(isEmpty(filters?.brands) ? { distinct: ['brand'] } : {}),
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
mainGender || (shop === Shops.MENSMARKET ? 'male' : 'female'),
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
return this.sortByTermRelevance({
|
|
86
|
+
productIds,
|
|
87
|
+
totalResult,
|
|
88
|
+
limits: params.limits,
|
|
89
|
+
filters,
|
|
90
|
+
fieldsHelper: this.helpersService.getFieldsHelper(),
|
|
91
|
+
})
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
private async searchDefault(params: TermSearchDefaultParams): Promise<RepositoryFindResult<Product>> {
|
|
95
|
+
const { productIds, filters, limits, shop, mainGender, fields } = params
|
|
96
|
+
const productCatalog = this.repositoryService.getProductCatalog()
|
|
97
|
+
const filterHelper = this.helpersService.getFilterHelper()
|
|
98
|
+
|
|
99
|
+
return productCatalog.productRepository.findCatalog(
|
|
100
|
+
{
|
|
101
|
+
fields,
|
|
102
|
+
filters: {
|
|
103
|
+
id: { operator: Where.IN, value: productIds },
|
|
104
|
+
published: { operator: Where.EQUALS, value: true },
|
|
105
|
+
...filterHelper.buildFilterQuery(filters || {}),
|
|
106
|
+
},
|
|
107
|
+
limits,
|
|
108
|
+
options: {
|
|
109
|
+
minimal: ['price'],
|
|
110
|
+
maximum: ['price'],
|
|
111
|
+
distinct: ['brand'],
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
mainGender || (shop === Shops.MENSMARKET ? 'male' : 'female'),
|
|
115
|
+
)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
private sortByTermRelevance(params: SortByTermRelevanceParams) {
|
|
119
|
+
const { productIds, totalResult, limits, filters, fieldsHelper } = params
|
|
120
|
+
const defaultGender = filters?.gender?.at(0) || 'male'
|
|
121
|
+
const stockData = totalResult.data.filter((product: any) => product.stock.quantity > 0)
|
|
122
|
+
const stockOut = totalResult.data.filter((product: any) => product.stock.quantity <= 0)
|
|
123
|
+
|
|
124
|
+
const productIdsStockGender = productIds.filter((product) =>
|
|
125
|
+
stockData.some(
|
|
126
|
+
(result: any) =>
|
|
127
|
+
result.id === product && (result.gender?.includes(defaultGender) || result.gender?.includes('unisex')),
|
|
128
|
+
),
|
|
129
|
+
)
|
|
130
|
+
|
|
131
|
+
const productIdsStockNotGender = productIds.filter((product) =>
|
|
132
|
+
stockData.some(
|
|
133
|
+
(result: any) =>
|
|
134
|
+
result.id === product && !result.gender?.includes(defaultGender) && !result.gender?.includes('unisex'),
|
|
135
|
+
),
|
|
136
|
+
)
|
|
137
|
+
|
|
138
|
+
const productIdsStock = productIdsStockGender.concat(productIdsStockNotGender)
|
|
139
|
+
const productIdsStockOut = productIds.filter((product) => stockOut.some((result: any) => result.id === product))
|
|
140
|
+
|
|
141
|
+
const limitedProductId = productIdsStock
|
|
142
|
+
.concat(productIdsStockOut)
|
|
143
|
+
.slice(limits.offset, limits.offset + limits.limit)
|
|
144
|
+
|
|
145
|
+
const orderedId = productIds.filter((product) => limitedProductId.includes(product))
|
|
146
|
+
|
|
147
|
+
return this.getDetailedProducts(orderedId, totalResult, fieldsHelper)
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
private async getDetailedProducts(orderedId: string[], totalResult: any, fieldsHelper: any) {
|
|
151
|
+
const productCatalog = this.repositoryService.getProductCatalog()
|
|
152
|
+
const fields = fieldsHelper.getStandardFields()
|
|
153
|
+
const productResult = await productCatalog.productRepository.findCatalog({
|
|
154
|
+
filters: {
|
|
155
|
+
id: { operator: Where.IN, value: orderedId },
|
|
156
|
+
},
|
|
157
|
+
fields,
|
|
158
|
+
})
|
|
159
|
+
|
|
160
|
+
return {
|
|
161
|
+
data: orderedId.map((id) => productResult.data.find((product) => product.id === id)).filter(Boolean),
|
|
162
|
+
count: totalResult.count,
|
|
163
|
+
maximum: totalResult.maximum,
|
|
164
|
+
minimal: totalResult.minimal,
|
|
165
|
+
distinct: totalResult.distinct,
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
private async findCatalogIdsBySearch(term: string, shop: Shops): Promise<string[]> {
|
|
170
|
+
if (this.productsByTerm[term]) return this.productsByTerm[term]
|
|
171
|
+
|
|
172
|
+
const productServices = this.repositoryService.getProductServices()
|
|
173
|
+
|
|
174
|
+
return (this.productsByTerm[term] = await productServices.productSearch
|
|
175
|
+
.search<ProductSearch>(term, 999, shop === Shops.GLAMSHOP ? 'female' : 'male')
|
|
176
|
+
.then((products) => [...new Set(products.map((product) => product.id))]))
|
|
177
|
+
}
|
|
178
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { RepositoryCacheOptions, Shops } from '@infrab4a/connect'
|
|
2
|
+
|
|
3
|
+
export type SearchWithMostRelevantParams = {
|
|
4
|
+
category: any
|
|
5
|
+
filters: any
|
|
6
|
+
limits: any
|
|
7
|
+
shop: Shops
|
|
8
|
+
mainGender: any
|
|
9
|
+
optionsCache: { cache?: RepositoryCacheOptions } | undefined
|
|
10
|
+
fields: any
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export type SearchDefaultParams = {
|
|
14
|
+
category: any
|
|
15
|
+
filters: any
|
|
16
|
+
limits: any
|
|
17
|
+
shop: Shops
|
|
18
|
+
mainGender: any
|
|
19
|
+
sort: any
|
|
20
|
+
optionsCache: { cache?: RepositoryCacheOptions } | undefined
|
|
21
|
+
fields: any
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export type FindAndSortByMostRelevantParams = {
|
|
25
|
+
mostRelevants: string[]
|
|
26
|
+
productIds: string[]
|
|
27
|
+
filters: any
|
|
28
|
+
limits: any
|
|
29
|
+
shop: Shops
|
|
30
|
+
mainGender: any
|
|
31
|
+
optionsCache: { cache?: RepositoryCacheOptions } | undefined
|
|
32
|
+
fields: any
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export type TermSearchMostRelevantParams = {
|
|
36
|
+
productIds: string[]
|
|
37
|
+
filters: any
|
|
38
|
+
limits: any
|
|
39
|
+
mainGender: any
|
|
40
|
+
shop: Shops
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export type TermSearchDefaultParams = {
|
|
44
|
+
productIds: string[]
|
|
45
|
+
filters: any
|
|
46
|
+
limits: any
|
|
47
|
+
mainGender: any
|
|
48
|
+
shop: Shops
|
|
49
|
+
fields: any
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export type SortByTermRelevanceParams = {
|
|
53
|
+
productIds: string[]
|
|
54
|
+
totalResult: any
|
|
55
|
+
limits: any
|
|
56
|
+
filters: any
|
|
57
|
+
fieldsHelper: any
|
|
58
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Category } from '@infrab4a/connect'
|
|
2
|
+
|
|
3
|
+
import { CatalogFilters } from '../../../interfaces'
|
|
4
|
+
|
|
5
|
+
import { FetchProductsOptions } from './fetch-products-options.type'
|
|
6
|
+
|
|
7
|
+
export type FetchProductsMainParams<T extends Category> = {
|
|
8
|
+
category?: T
|
|
9
|
+
profile?: string[]
|
|
10
|
+
term?: string
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export type FetchProductsParams<T extends Category> = FetchProductsOptions &
|
|
14
|
+
(
|
|
15
|
+
| {
|
|
16
|
+
category: FetchProductsMainParams<T>['category']
|
|
17
|
+
filters?: CatalogFilters & { customOptions?: never }
|
|
18
|
+
}
|
|
19
|
+
| {
|
|
20
|
+
profile: FetchProductsMainParams<T>['profile']
|
|
21
|
+
filters?: CatalogFilters & { customOptions?: never; tags?: never }
|
|
22
|
+
}
|
|
23
|
+
| {
|
|
24
|
+
term: FetchProductsMainParams<T>['term']
|
|
25
|
+
filters?: CatalogFilters & { customOptions?: never }
|
|
26
|
+
}
|
|
27
|
+
)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Product } from '@infrab4a/connect'
|
|
2
|
+
|
|
3
|
+
export type FetchProductsResponse = {
|
|
4
|
+
products: { data: Product[]; total: number }
|
|
5
|
+
pages: number
|
|
6
|
+
prices: {
|
|
7
|
+
price: { min: number; max: number }
|
|
8
|
+
subscriberPrice: { min: number; max: number }
|
|
9
|
+
}
|
|
10
|
+
brands?: string[]
|
|
11
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Category, Product, Shops } from '@infrab4a/connect'
|
|
2
|
+
|
|
3
|
+
import { CatalogSearchParams } from '../../../interfaces'
|
|
4
|
+
|
|
5
|
+
import { FetchProductsParams } from './fetch-products-params.type'
|
|
6
|
+
|
|
7
|
+
export type StockNotificationParams = {
|
|
8
|
+
shop: Shops
|
|
9
|
+
productId: string
|
|
10
|
+
name: string
|
|
11
|
+
email: string
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type BuildResponseParams<T extends Category = Category> = {
|
|
15
|
+
data: Product[]
|
|
16
|
+
total: number
|
|
17
|
+
maximum: any
|
|
18
|
+
minimal: any
|
|
19
|
+
searchParams: CatalogSearchParams
|
|
20
|
+
options: FetchProductsParams<T>
|
|
21
|
+
}
|
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
import { Inject, Injectable } from '@angular/core'
|
|
2
|
+
import {
|
|
3
|
+
LogRepository,
|
|
4
|
+
PersonType,
|
|
5
|
+
PersonTypes,
|
|
6
|
+
Product,
|
|
7
|
+
Shops,
|
|
8
|
+
Wishlist,
|
|
9
|
+
WishlistLogType,
|
|
10
|
+
WishlistRepository,
|
|
11
|
+
} from '@infrab4a/connect'
|
|
12
|
+
|
|
13
|
+
import { DEFAULT_SHOP } from '../../consts'
|
|
14
|
+
|
|
15
|
+
import { CatalogService } from './catalog.service'
|
|
16
|
+
import { CategoryService } from './category.service'
|
|
17
|
+
import { CatalogServiceFacade, CategoryServiceFacade } from './facades'
|
|
18
|
+
|
|
19
|
+
@Injectable()
|
|
20
|
+
export class WishlistService {
|
|
21
|
+
private catalogService: CatalogService
|
|
22
|
+
private categoryService: CategoryService
|
|
23
|
+
|
|
24
|
+
constructor(
|
|
25
|
+
@Inject('WishlistRepository') private readonly wishlistRepository: WishlistRepository,
|
|
26
|
+
@Inject(DEFAULT_SHOP) private readonly shop: Shops,
|
|
27
|
+
@Inject('LogRepository') private readonly logRepository: LogRepository,
|
|
28
|
+
) {}
|
|
29
|
+
|
|
30
|
+
initializeServices(catalogServiceFacade: CatalogServiceFacade, categoryServiceFacade: CategoryServiceFacade): void {
|
|
31
|
+
this.catalogService = catalogServiceFacade.getCatalogService()
|
|
32
|
+
this.categoryService = categoryServiceFacade.getCategoryService()
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
getCatalogService() {
|
|
36
|
+
return this.catalogService
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
getCategoryService() {
|
|
40
|
+
return this.categoryService
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async create({
|
|
44
|
+
personId,
|
|
45
|
+
title,
|
|
46
|
+
description,
|
|
47
|
+
published,
|
|
48
|
+
userFullName,
|
|
49
|
+
userPhoto,
|
|
50
|
+
theme,
|
|
51
|
+
bannerUrl,
|
|
52
|
+
personType,
|
|
53
|
+
personIsSubscriber,
|
|
54
|
+
}: {
|
|
55
|
+
personId: string
|
|
56
|
+
title: string
|
|
57
|
+
description: string
|
|
58
|
+
published: boolean
|
|
59
|
+
userFullName: string
|
|
60
|
+
userPhoto?: string
|
|
61
|
+
theme?: string
|
|
62
|
+
bannerUrl?: string
|
|
63
|
+
personType?: PersonType
|
|
64
|
+
personIsSubscriber?: boolean
|
|
65
|
+
}): Promise<Wishlist> {
|
|
66
|
+
const wishlistData = this.buildWishlistData({
|
|
67
|
+
title,
|
|
68
|
+
description,
|
|
69
|
+
published,
|
|
70
|
+
userFullName,
|
|
71
|
+
userPhoto,
|
|
72
|
+
theme,
|
|
73
|
+
bannerUrl,
|
|
74
|
+
personType,
|
|
75
|
+
personIsSubscriber,
|
|
76
|
+
personId,
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
const existingWishlist = await this.findExistingWishlistByPersonId(personId)
|
|
80
|
+
|
|
81
|
+
await this.createWishlistLog(WishlistLogType.CREATE, wishlistData as Wishlist)
|
|
82
|
+
|
|
83
|
+
if (existingWishlist) return existingWishlist
|
|
84
|
+
|
|
85
|
+
return this.createNewWishlist(wishlistData)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
private buildWishlistData({
|
|
89
|
+
title,
|
|
90
|
+
description,
|
|
91
|
+
published,
|
|
92
|
+
userFullName,
|
|
93
|
+
userPhoto,
|
|
94
|
+
theme,
|
|
95
|
+
bannerUrl,
|
|
96
|
+
personType,
|
|
97
|
+
personIsSubscriber,
|
|
98
|
+
personId,
|
|
99
|
+
}: {
|
|
100
|
+
title: string
|
|
101
|
+
description: string
|
|
102
|
+
published: boolean
|
|
103
|
+
userFullName: string
|
|
104
|
+
userPhoto?: string
|
|
105
|
+
theme?: string
|
|
106
|
+
bannerUrl?: string
|
|
107
|
+
personType?: PersonType
|
|
108
|
+
personIsSubscriber?: boolean
|
|
109
|
+
personId: string
|
|
110
|
+
}) {
|
|
111
|
+
return {
|
|
112
|
+
slug: '',
|
|
113
|
+
name: title,
|
|
114
|
+
description,
|
|
115
|
+
metadatas: [
|
|
116
|
+
{
|
|
117
|
+
shop: this.shop,
|
|
118
|
+
title: `${userFullName} - ${title}`,
|
|
119
|
+
description: `${userFullName} - ${description}`,
|
|
120
|
+
},
|
|
121
|
+
],
|
|
122
|
+
shop: this.shop,
|
|
123
|
+
shops: [this.shop],
|
|
124
|
+
personId,
|
|
125
|
+
personName: userFullName,
|
|
126
|
+
personPhoto: userPhoto,
|
|
127
|
+
brandCategory: false,
|
|
128
|
+
published,
|
|
129
|
+
theme,
|
|
130
|
+
bannerUrl,
|
|
131
|
+
personType: personType ?? PersonTypes.NONE,
|
|
132
|
+
personIsSubscriber: personIsSubscriber ?? false,
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
private async findExistingWishlistByPersonId(personId: string): Promise<Wishlist | null> {
|
|
137
|
+
const hasWishlist = await this.wishlistRepository
|
|
138
|
+
.find({
|
|
139
|
+
filters: {
|
|
140
|
+
personId,
|
|
141
|
+
},
|
|
142
|
+
options: {
|
|
143
|
+
enableCount: false,
|
|
144
|
+
},
|
|
145
|
+
orderBy: {
|
|
146
|
+
id: 'asc',
|
|
147
|
+
},
|
|
148
|
+
})
|
|
149
|
+
.then((res) => res.data)
|
|
150
|
+
|
|
151
|
+
return hasWishlist.length ? hasWishlist.at(0) : null
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
private async createNewWishlist(data: any): Promise<Wishlist> {
|
|
155
|
+
const newWishlist = await this.wishlistRepository.create(data)
|
|
156
|
+
|
|
157
|
+
await this.wishlistRepository.update({ id: newWishlist.id, slug: newWishlist.id })
|
|
158
|
+
|
|
159
|
+
return Wishlist.toInstance({ ...newWishlist.toPlain(), slug: newWishlist.id })
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
async update({
|
|
163
|
+
id,
|
|
164
|
+
title,
|
|
165
|
+
description,
|
|
166
|
+
published,
|
|
167
|
+
userFullName,
|
|
168
|
+
userPhoto,
|
|
169
|
+
theme,
|
|
170
|
+
bannerUrl,
|
|
171
|
+
personType,
|
|
172
|
+
personIsSubscriber,
|
|
173
|
+
}: {
|
|
174
|
+
id: string
|
|
175
|
+
title: string
|
|
176
|
+
description: string
|
|
177
|
+
published: boolean
|
|
178
|
+
userFullName: string
|
|
179
|
+
userPhoto?: string
|
|
180
|
+
theme?: string
|
|
181
|
+
bannerUrl?: string
|
|
182
|
+
personType?: PersonType
|
|
183
|
+
personIsSubscriber?: boolean
|
|
184
|
+
}): Promise<Wishlist> {
|
|
185
|
+
const data = {
|
|
186
|
+
id,
|
|
187
|
+
name: title,
|
|
188
|
+
description,
|
|
189
|
+
published,
|
|
190
|
+
metadatas: [
|
|
191
|
+
{
|
|
192
|
+
shop: this.shop,
|
|
193
|
+
title: `${userFullName} - ${title}`,
|
|
194
|
+
description: `${userFullName} - ${description}`,
|
|
195
|
+
},
|
|
196
|
+
],
|
|
197
|
+
personName: userFullName,
|
|
198
|
+
personPhoto: userPhoto,
|
|
199
|
+
theme,
|
|
200
|
+
bannerUrl,
|
|
201
|
+
personType: personType ?? PersonTypes.NONE,
|
|
202
|
+
personIsSubscriber: personIsSubscriber ?? false,
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
await this.createWishlistLog(WishlistLogType.UPDATE, data as Wishlist)
|
|
206
|
+
|
|
207
|
+
return this.wishlistRepository.update(data)
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
async delete(wishlistId: string): Promise<void> {
|
|
211
|
+
const wishlist = await this.findById(wishlistId)
|
|
212
|
+
|
|
213
|
+
await this.createWishlistLog(WishlistLogType.DELETE, wishlist)
|
|
214
|
+
|
|
215
|
+
return this.wishlistRepository.delete({ id: wishlistId })
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
getWishlistBySlug(slug: string): Promise<Wishlist> {
|
|
219
|
+
const [id] = slug.split('-')
|
|
220
|
+
|
|
221
|
+
if (+id) return this.wishlistRepository.get({ id })
|
|
222
|
+
|
|
223
|
+
return this.wishlistRepository.getWishlistBySlug(slug)
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
getWishlistsByPerson(personId: string): Promise<Wishlist[]> {
|
|
227
|
+
return this.wishlistRepository.getWishlistByPerson(personId)
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
async addProduct(wishlistId: string, productId: string): Promise<Wishlist> {
|
|
231
|
+
const wishlist = await this.wishlistRepository.get({ id: wishlistId })
|
|
232
|
+
const hasProduct = wishlist.products.some((p) => p == productId)
|
|
233
|
+
|
|
234
|
+
const wishlistData = await this.findById(wishlistId)
|
|
235
|
+
const productData = await this.findProductById(productId)
|
|
236
|
+
|
|
237
|
+
await this.createWishlistLog(WishlistLogType.ADD_PRODUCT, wishlistData, productData)
|
|
238
|
+
|
|
239
|
+
if (!hasProduct) {
|
|
240
|
+
wishlist.products = [...wishlist.products, productId]
|
|
241
|
+
await this.wishlistRepository.addProduct(wishlistId, productId)
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
return wishlist
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
async removeProduct(wishlistId: string, productId: string): Promise<Wishlist> {
|
|
248
|
+
const wishlist = await this.wishlistRepository.get({ id: wishlistId })
|
|
249
|
+
const productIndex = wishlist.products.findIndex((p) => p == productId)
|
|
250
|
+
|
|
251
|
+
if (productIndex != -1) {
|
|
252
|
+
wishlist.products.splice(productIndex, 1)
|
|
253
|
+
const wishlistData = await this.findById(wishlistId)
|
|
254
|
+
const productData = await this.findProductById(productId)
|
|
255
|
+
|
|
256
|
+
await this.createWishlistLog(WishlistLogType.REMOVE_PRODUCT, wishlistData, productData)
|
|
257
|
+
await this.wishlistRepository.removeProduct(wishlistId, productId)
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
return wishlist
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
private async findById(id: string): Promise<Wishlist> {
|
|
264
|
+
return this.wishlistRepository
|
|
265
|
+
.find({
|
|
266
|
+
fields: ['id', 'name', 'description', 'personId', 'personIsSubscriber', 'personType', 'personName'],
|
|
267
|
+
filters: {
|
|
268
|
+
id,
|
|
269
|
+
},
|
|
270
|
+
})
|
|
271
|
+
.then((res) => res.data.at(0))
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
private async findProductById(id: string): Promise<Product> {
|
|
275
|
+
if (!this.catalogService) {
|
|
276
|
+
throw new Error('CatalogService not initialized. Call initializeServices first.')
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
// Acessar o ProductRepository através do CatalogHelpersService
|
|
280
|
+
const helpersService = this.catalogService['helpersService'] as any
|
|
281
|
+
const productServices = helpersService.getProductServices()
|
|
282
|
+
|
|
283
|
+
return productServices.productRepository
|
|
284
|
+
.find({
|
|
285
|
+
fields: ['id', 'sku', 'EAN', 'name', 'brand'],
|
|
286
|
+
filters: {
|
|
287
|
+
id,
|
|
288
|
+
},
|
|
289
|
+
})
|
|
290
|
+
.then((res) => res.data.at(0))
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
private async createWishlistLog(type: WishlistLogType, wishlist: Wishlist, product?: Product) {
|
|
294
|
+
switch (type) {
|
|
295
|
+
case WishlistLogType.CREATE:
|
|
296
|
+
case WishlistLogType.UPDATE:
|
|
297
|
+
case WishlistLogType.DELETE:
|
|
298
|
+
await this.createWishlistOperationLog(type, wishlist)
|
|
299
|
+
break
|
|
300
|
+
|
|
301
|
+
case WishlistLogType.ADD_PRODUCT:
|
|
302
|
+
case WishlistLogType.REMOVE_PRODUCT:
|
|
303
|
+
await this.createWishlistProductLog(type, wishlist, product)
|
|
304
|
+
break
|
|
305
|
+
|
|
306
|
+
default:
|
|
307
|
+
break
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
private async createWishlistOperationLog(type: WishlistLogType, wishlist: Wishlist): Promise<void> {
|
|
312
|
+
const operation = this.getOperationTypeFromWishlistLogType(type)
|
|
313
|
+
|
|
314
|
+
await this.logRepository.create({
|
|
315
|
+
collection: 'wishlist',
|
|
316
|
+
date: new Date(),
|
|
317
|
+
operation,
|
|
318
|
+
documentId: wishlist.id,
|
|
319
|
+
document: this.buildWishlistLogDocument(wishlist, type),
|
|
320
|
+
})
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
private async createWishlistProductLog(type: WishlistLogType, wishlist: Wishlist, product: Product): Promise<void> {
|
|
324
|
+
await this.logRepository.create({
|
|
325
|
+
collection: 'wishlist',
|
|
326
|
+
date: new Date(),
|
|
327
|
+
operation: 'UPDATE',
|
|
328
|
+
documentId: wishlist.id,
|
|
329
|
+
document: {
|
|
330
|
+
...this.buildWishlistLogDocument(wishlist, type),
|
|
331
|
+
...this.buildProductLogData(product),
|
|
332
|
+
},
|
|
333
|
+
})
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
private getOperationTypeFromWishlistLogType(type: WishlistLogType): 'CREATE' | 'UPDATE' | 'DELETE' {
|
|
337
|
+
if (type === WishlistLogType.CREATE) return 'CREATE'
|
|
338
|
+
|
|
339
|
+
if (type === WishlistLogType.UPDATE) return 'UPDATE'
|
|
340
|
+
|
|
341
|
+
return 'DELETE'
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
private buildWishlistLogDocument(wishlist: Wishlist, type: WishlistLogType) {
|
|
345
|
+
return {
|
|
346
|
+
id: wishlist.id,
|
|
347
|
+
shop: this.shop,
|
|
348
|
+
name: wishlist.name,
|
|
349
|
+
description: wishlist.description,
|
|
350
|
+
published: wishlist.published,
|
|
351
|
+
type: type,
|
|
352
|
+
personType: wishlist.personType,
|
|
353
|
+
personId: wishlist.personId,
|
|
354
|
+
personName: wishlist.personName,
|
|
355
|
+
personIsSubscriber: wishlist.personIsSubscriber,
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
private buildProductLogData(product: Product) {
|
|
360
|
+
return {
|
|
361
|
+
productId: product.id,
|
|
362
|
+
productEAN: product.EAN,
|
|
363
|
+
productSKU: product.sku,
|
|
364
|
+
productName: product.name,
|
|
365
|
+
productBrand: product.brand,
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { HttpClient } from '@angular/common/http'
|
|
2
|
+
import { Inject, Injectable } from '@angular/core'
|
|
3
|
+
|
|
4
|
+
import { PERSISTENCE_PROVIDER } from '../../consts'
|
|
5
|
+
import { DataPersistence } from '../../persistence'
|
|
6
|
+
|
|
7
|
+
@Injectable()
|
|
8
|
+
export class CheckoutDependenciesFacade {
|
|
9
|
+
constructor(
|
|
10
|
+
@Inject(PERSISTENCE_PROVIDER) public readonly dataPersistence: DataPersistence,
|
|
11
|
+
public readonly httpClient: HttpClient,
|
|
12
|
+
) {}
|
|
13
|
+
}
|