@infrab4a/connect-angular 5.8.3 → 5.8.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.
- 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 +4 -24
- package/project.json +37 -0
- package/src/angular-connect.module.ts +270 -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 +407 -0
- package/src/angular-hasura-graphql.module.ts +268 -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 +56 -0
- package/src/services/catalog/context/catalog-search.context.ts +59 -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/{services/catalog/facades/index.d.ts → src/services/catalog/facades/index.ts} +5 -5
- package/src/services/catalog/facades/product-catalog.facade.ts +13 -0
- package/src/services/catalog/helpers/brand-manager.helper.ts +69 -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 +39 -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/{services/catalog/services/index.d.ts → src/services/catalog/services/index.ts} +4 -4
- package/src/services/catalog/services/product-management.facade.ts +20 -0
- package/src/services/catalog/strategies/category-search.strategy.ts +168 -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 +163 -0
- package/src/services/catalog/strategies/types/strategy-params.type.ts +59 -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 +364 -0
- package/src/services/checkout/checkout-dependencies.facade.ts +13 -0
- package/src/services/checkout/checkout-repositories.facade.ts +10 -0
- package/{services/checkout/index.d.ts → src/services/checkout/index.ts} +2 -2
- package/src/services/checkout-subscription.service.ts +76 -0
- package/src/services/checkout.service.ts +213 -0
- package/src/services/coupon/coupon-repositories.facade.ts +11 -0
- package/{services/coupon/index.d.ts → src/services/coupon/index.ts} +1 -1
- 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/{services/home-shop/index.d.ts → src/services/home-shop/index.ts} +1 -1
- package/src/services/home-shop.service.ts +210 -0
- package/src/services/index.ts +12 -0
- package/src/services/order-product-review.service.ts +135 -0
- package/src/services/order-recurrence.service.ts +115 -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 +4 -0
- package/src/services/types/pending-product-review.type.ts +12 -0
- package/src/services/types/product-review-create.type.ts +15 -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 -36
- 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 -17
- package/angular-hasura-graphql.module.d.ts +0 -14
- package/angular-vertex-search.module.d.ts +0 -9
- 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 -4
- package/consts/hasura-options.const.d.ts +0 -1
- package/consts/index.d.ts +0 -8
- package/consts/persistence.const.d.ts +0 -1
- package/consts/storage-base-url.const.d.ts +0 -1
- package/consts/vertex-config.const.d.ts +0 -1
- package/esm2020/angular-connect.module.mjs +0 -293
- package/esm2020/angular-elastic-search.module.mjs +0 -34
- package/esm2020/angular-firebase-auth.module.mjs +0 -141
- package/esm2020/angular-firestore.module.mjs +0 -597
- package/esm2020/angular-hasura-graphql.module.mjs +0 -421
- package/esm2020/angular-vertex-search.module.mjs +0 -34
- 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 -5
- package/esm2020/consts/hasura-options.const.mjs +0 -2
- package/esm2020/consts/index.mjs +0 -9
- package/esm2020/consts/persistence.const.mjs +0 -2
- package/esm2020/consts/storage-base-url.const.mjs +0 -2
- package/esm2020/consts/vertex-config.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/interfaces/catalog-strategies.interface.mjs +0 -2
- package/esm2020/interfaces/category-facades.interface.mjs +0 -2
- package/esm2020/interfaces/index.mjs +0 -3
- 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/cart-services.facade.mjs +0 -21
- package/esm2020/services/cart/index.mjs +0 -2
- package/esm2020/services/cart.service.mjs +0 -73
- 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 -111
- package/esm2020/services/catalog/category.service.mjs +0 -42
- package/esm2020/services/catalog/context/catalog-search.context.mjs +0 -40
- package/esm2020/services/catalog/enums/index.mjs +0 -2
- package/esm2020/services/catalog/enums/product-sorts.enum.mjs +0 -11
- package/esm2020/services/catalog/facades/catalog-service.facade.mjs +0 -32
- package/esm2020/services/catalog/facades/catalog-strategies.facade.mjs +0 -17
- package/esm2020/services/catalog/facades/category-repository.facade.mjs +0 -20
- package/esm2020/services/catalog/facades/category-service.facade.mjs +0 -30
- package/esm2020/services/catalog/facades/index.mjs +0 -6
- package/esm2020/services/catalog/facades/product-catalog.facade.mjs +0 -21
- package/esm2020/services/catalog/helpers/brand-manager.helper.mjs +0 -62
- package/esm2020/services/catalog/helpers/catalog-filter.helper.mjs +0 -44
- package/esm2020/services/catalog/helpers/catalog-sort.helper.mjs +0 -52
- package/esm2020/services/catalog/helpers/index.mjs +0 -5
- package/esm2020/services/catalog/helpers/product-fields.helper.mjs +0 -43
- 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/services/catalog-helpers.service.mjs +0 -33
- package/esm2020/services/catalog/services/catalog-operations.facade.mjs +0 -26
- package/esm2020/services/catalog/services/catalog-repository.service.mjs +0 -25
- package/esm2020/services/catalog/services/index.mjs +0 -5
- package/esm2020/services/catalog/services/product-management.facade.mjs +0 -25
- package/esm2020/services/catalog/strategies/category-search.strategy.mjs +0 -133
- package/esm2020/services/catalog/strategies/index.mjs +0 -4
- package/esm2020/services/catalog/strategies/profile-search.strategy.mjs +0 -42
- package/esm2020/services/catalog/strategies/term-search.strategy.mjs +0 -126
- package/esm2020/services/catalog/strategies/types/strategy-params.type.mjs +0 -2
- package/esm2020/services/catalog/types/fetch-products-options.type.mjs +0 -2
- package/esm2020/services/catalog/types/fetch-products-params.type.mjs +0 -2
- package/esm2020/services/catalog/types/fetch-products-response.type.mjs +0 -2
- package/esm2020/services/catalog/types/index.mjs +0 -6
- package/esm2020/services/catalog/types/method-params.type.mjs +0 -2
- package/esm2020/services/catalog/types/product-sort.type.mjs +0 -2
- package/esm2020/services/catalog/wishlist.service.mjs +0 -258
- package/esm2020/services/checkout/checkout-dependencies.facade.mjs +0 -20
- package/esm2020/services/checkout/checkout-repositories.facade.mjs +0 -20
- package/esm2020/services/checkout/index.mjs +0 -3
- package/esm2020/services/checkout-subscription.service.mjs +0 -55
- package/esm2020/services/checkout.service.mjs +0 -120
- package/esm2020/services/coupon/coupon-repositories.facade.mjs +0 -24
- package/esm2020/services/coupon/index.mjs +0 -2
- package/esm2020/services/coupon/types/coupon-params.type.mjs +0 -2
- package/esm2020/services/coupon.service.mjs +0 -248
- package/esm2020/services/helpers/index.mjs +0 -2
- package/esm2020/services/helpers/util.helper.mjs +0 -18
- package/esm2020/services/home-shop/home-shop-repositories.facade.mjs +0 -24
- package/esm2020/services/home-shop/index.mjs +0 -2
- package/esm2020/services/home-shop.service.mjs +0 -119
- package/esm2020/services/index.mjs +0 -12
- package/esm2020/services/order-product-review.service.mjs +0 -126
- package/esm2020/services/order-recurrence.service.mjs +0 -83
- package/esm2020/services/order.service.mjs +0 -30
- package/esm2020/services/shared/configuration.facade.mjs +0 -29
- package/esm2020/services/shared/index.mjs +0 -2
- package/esm2020/services/types/index.mjs +0 -5
- package/esm2020/services/types/pending-product-review.type.mjs +0 -2
- package/esm2020/services/types/product-review-create.type.mjs +0 -2
- 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/types/firebase-app-config.type.mjs +0 -2
- package/esm2020/types/index.mjs +0 -2
- package/fesm2015/infrab4a-connect-angular.mjs +0 -3746
- package/fesm2015/infrab4a-connect-angular.mjs.map +0 -1
- package/fesm2020/infrab4a-connect-angular.mjs +0 -3648
- 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/interfaces/catalog-strategies.interface.d.ts +0 -31
- package/interfaces/category-facades.interface.d.ts +0 -6
- package/interfaces/index.d.ts +0 -2
- 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/cart-services.facade.d.ts +0 -12
- package/services/cart/index.d.ts +0 -1
- package/services/cart.service.d.ts +0 -26
- 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 -24
- package/services/catalog/category.service.d.ts +0 -23
- package/services/catalog/context/catalog-search.context.d.ts +0 -14
- package/services/catalog/enums/index.d.ts +0 -1
- package/services/catalog/enums/product-sorts.enum.d.ts +0 -9
- package/services/catalog/facades/catalog-service.facade.d.ts +0 -15
- package/services/catalog/facades/catalog-strategies.facade.d.ts +0 -10
- package/services/catalog/facades/category-repository.facade.d.ts +0 -9
- package/services/catalog/facades/category-service.facade.d.ts +0 -15
- package/services/catalog/facades/product-catalog.facade.d.ts +0 -10
- package/services/catalog/helpers/brand-manager.helper.d.ts +0 -14
- package/services/catalog/helpers/catalog-filter.helper.d.ts +0 -8
- package/services/catalog/helpers/catalog-sort.helper.d.ts +0 -7
- package/services/catalog/helpers/index.d.ts +0 -4
- package/services/catalog/helpers/product-fields.helper.d.ts +0 -7
- 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/services/catalog-helpers.service.d.ts +0 -17
- package/services/catalog/services/catalog-operations.facade.d.ts +0 -13
- package/services/catalog/services/catalog-repository.service.d.ts +0 -12
- package/services/catalog/services/product-management.facade.d.ts +0 -12
- package/services/catalog/strategies/category-search.strategy.d.ts +0 -19
- package/services/catalog/strategies/index.d.ts +0 -3
- package/services/catalog/strategies/profile-search.strategy.d.ts +0 -14
- package/services/catalog/strategies/term-search.strategy.d.ts +0 -20
- package/services/catalog/strategies/types/strategy-params.type.d.ts +0 -59
- package/services/catalog/types/fetch-products-options.type.d.ts +0 -8
- package/services/catalog/types/fetch-products-params.type.d.ts +0 -25
- package/services/catalog/types/fetch-products-response.type.d.ts +0 -19
- package/services/catalog/types/index.d.ts +0 -5
- package/services/catalog/types/method-params.type.d.ts +0 -17
- package/services/catalog/types/product-sort.type.d.ts +0 -2
- package/services/catalog/wishlist.service.d.ts +0 -60
- package/services/checkout/checkout-dependencies.facade.d.ts +0 -10
- package/services/checkout/checkout-repositories.facade.d.ts +0 -9
- package/services/checkout-subscription.service.d.ts +0 -19
- package/services/checkout.service.d.ts +0 -31
- package/services/coupon/coupon-repositories.facade.d.ts +0 -10
- package/services/coupon/types/coupon-params.type.d.ts +0 -13
- package/services/coupon.service.d.ts +0 -36
- package/services/helpers/index.d.ts +0 -1
- package/services/helpers/util.helper.d.ts +0 -3
- package/services/home-shop/home-shop-repositories.facade.d.ts +0 -10
- package/services/home-shop.service.d.ts +0 -26
- package/services/index.d.ts +0 -11
- package/services/order-product-review.service.d.ts +0 -18
- package/services/order-recurrence.service.d.ts +0 -37
- package/services/order.service.d.ts +0 -13
- package/services/shared/configuration.facade.d.ts +0 -12
- package/services/shared/index.d.ts +0 -1
- package/services/types/index.d.ts +0 -4
- package/services/types/pending-product-review.type.d.ts +0 -12
- package/services/types/product-review-create.type.d.ts +0 -14
- package/services/types/required-checkout-data.type.d.ts +0 -2
- package/services/types/required-checkout-subscription-data.type.d.ts +0 -2
- package/types/firebase-app-config.type.d.ts +0 -1
- package/types/index.d.ts +0 -1
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
import { Inject, Injectable } from '@angular/core'
|
|
2
|
+
import {
|
|
3
|
+
LogRepository,
|
|
4
|
+
PersonType,
|
|
5
|
+
PersonTypes,
|
|
6
|
+
Product,
|
|
7
|
+
ProductCatalogRepository,
|
|
8
|
+
ProductRepository,
|
|
9
|
+
Shops,
|
|
10
|
+
Wishlist,
|
|
11
|
+
WishlistLogType,
|
|
12
|
+
WishlistRepository,
|
|
13
|
+
} from '@infrab4a/connect'
|
|
14
|
+
|
|
15
|
+
import { DEFAULT_SHOP } from '../../consts'
|
|
16
|
+
|
|
17
|
+
import { CatalogService } from './catalog.service'
|
|
18
|
+
import { CategoryService } from './category.service'
|
|
19
|
+
import { CatalogServiceFacade, CategoryServiceFacade } from './facades'
|
|
20
|
+
|
|
21
|
+
@Injectable()
|
|
22
|
+
export class WishlistService {
|
|
23
|
+
private catalogService: CatalogService
|
|
24
|
+
private categoryService: CategoryService
|
|
25
|
+
|
|
26
|
+
constructor(
|
|
27
|
+
@Inject('WishlistRepository') private readonly wishlistRepository: WishlistRepository,
|
|
28
|
+
@Inject('ProductRepository') private readonly productRepository: ProductRepository,
|
|
29
|
+
@Inject('ProductCatalogRepository') private readonly productCatalogRepository: ProductCatalogRepository,
|
|
30
|
+
@Inject('LogRepository') private readonly logRepository: LogRepository,
|
|
31
|
+
@Inject(DEFAULT_SHOP) private readonly shop: Shops,
|
|
32
|
+
) {}
|
|
33
|
+
|
|
34
|
+
initializeServices(catalogServiceFacade: CatalogServiceFacade, categoryServiceFacade: CategoryServiceFacade): void {
|
|
35
|
+
this.catalogService = catalogServiceFacade.getCatalogService()
|
|
36
|
+
this.categoryService = categoryServiceFacade.getCategoryService()
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
getCatalogService() {
|
|
40
|
+
return this.catalogService
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
getCategoryService() {
|
|
44
|
+
return this.categoryService
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async create({
|
|
48
|
+
personId,
|
|
49
|
+
title,
|
|
50
|
+
description,
|
|
51
|
+
published,
|
|
52
|
+
userFullName,
|
|
53
|
+
userPhoto,
|
|
54
|
+
theme,
|
|
55
|
+
bannerUrl,
|
|
56
|
+
personType,
|
|
57
|
+
personIsSubscriber,
|
|
58
|
+
}: {
|
|
59
|
+
personId: string
|
|
60
|
+
title: string
|
|
61
|
+
description: string
|
|
62
|
+
published: boolean
|
|
63
|
+
userFullName: string
|
|
64
|
+
userPhoto?: string
|
|
65
|
+
theme?: string
|
|
66
|
+
bannerUrl?: string
|
|
67
|
+
personType?: PersonType
|
|
68
|
+
personIsSubscriber?: boolean
|
|
69
|
+
}): Promise<Wishlist> {
|
|
70
|
+
const wishlistData = this.buildWishlistData({
|
|
71
|
+
title,
|
|
72
|
+
description,
|
|
73
|
+
published,
|
|
74
|
+
userFullName,
|
|
75
|
+
userPhoto,
|
|
76
|
+
theme,
|
|
77
|
+
bannerUrl,
|
|
78
|
+
personType,
|
|
79
|
+
personIsSubscriber,
|
|
80
|
+
personId,
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
const existingWishlist = await this.findExistingWishlistByPersonId(personId)
|
|
84
|
+
|
|
85
|
+
await this.createWishlistLog(WishlistLogType.CREATE, wishlistData as Wishlist)
|
|
86
|
+
|
|
87
|
+
if (existingWishlist) return existingWishlist
|
|
88
|
+
|
|
89
|
+
return this.createNewWishlist(wishlistData)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
private buildWishlistData({
|
|
93
|
+
title,
|
|
94
|
+
description,
|
|
95
|
+
published,
|
|
96
|
+
userFullName,
|
|
97
|
+
userPhoto,
|
|
98
|
+
theme,
|
|
99
|
+
bannerUrl,
|
|
100
|
+
personType,
|
|
101
|
+
personIsSubscriber,
|
|
102
|
+
personId,
|
|
103
|
+
}: {
|
|
104
|
+
title: string
|
|
105
|
+
description: string
|
|
106
|
+
published: boolean
|
|
107
|
+
userFullName: string
|
|
108
|
+
userPhoto?: string
|
|
109
|
+
theme?: string
|
|
110
|
+
bannerUrl?: string
|
|
111
|
+
personType?: PersonType
|
|
112
|
+
personIsSubscriber?: boolean
|
|
113
|
+
personId: string
|
|
114
|
+
}) {
|
|
115
|
+
return {
|
|
116
|
+
slug: '',
|
|
117
|
+
name: title,
|
|
118
|
+
description,
|
|
119
|
+
metadatas: [
|
|
120
|
+
{
|
|
121
|
+
shop: this.shop,
|
|
122
|
+
title: `${userFullName} - ${title}`,
|
|
123
|
+
description: `${userFullName} - ${description}`,
|
|
124
|
+
},
|
|
125
|
+
],
|
|
126
|
+
shop: this.shop,
|
|
127
|
+
shops: [this.shop],
|
|
128
|
+
personId,
|
|
129
|
+
personName: userFullName,
|
|
130
|
+
personPhoto: userPhoto,
|
|
131
|
+
brandCategory: false,
|
|
132
|
+
published,
|
|
133
|
+
theme,
|
|
134
|
+
bannerUrl,
|
|
135
|
+
personType: personType ?? PersonTypes.NONE,
|
|
136
|
+
personIsSubscriber: personIsSubscriber ?? false,
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
private async findExistingWishlistByPersonId(personId: string): Promise<Wishlist | null> {
|
|
141
|
+
const hasWishlist = await this.wishlistRepository
|
|
142
|
+
.find({
|
|
143
|
+
filters: {
|
|
144
|
+
personId,
|
|
145
|
+
},
|
|
146
|
+
options: {
|
|
147
|
+
enableCount: false,
|
|
148
|
+
},
|
|
149
|
+
orderBy: {
|
|
150
|
+
id: 'asc',
|
|
151
|
+
},
|
|
152
|
+
})
|
|
153
|
+
.then((res) => res.data)
|
|
154
|
+
|
|
155
|
+
return hasWishlist.length ? hasWishlist.at(0) : null
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
private async createNewWishlist(data: any): Promise<Wishlist> {
|
|
159
|
+
const newWishlist = await this.wishlistRepository.create(data)
|
|
160
|
+
|
|
161
|
+
await this.wishlistRepository.update({ id: newWishlist.id, slug: newWishlist.id })
|
|
162
|
+
|
|
163
|
+
return Wishlist.toInstance({ ...newWishlist.toPlain(), slug: newWishlist.id })
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
async update({
|
|
167
|
+
id,
|
|
168
|
+
title,
|
|
169
|
+
description,
|
|
170
|
+
published,
|
|
171
|
+
userFullName,
|
|
172
|
+
userPhoto,
|
|
173
|
+
theme,
|
|
174
|
+
bannerUrl,
|
|
175
|
+
personType,
|
|
176
|
+
personIsSubscriber,
|
|
177
|
+
}: {
|
|
178
|
+
id: string
|
|
179
|
+
title: string
|
|
180
|
+
description: string
|
|
181
|
+
published: boolean
|
|
182
|
+
userFullName: string
|
|
183
|
+
userPhoto?: string
|
|
184
|
+
theme?: string
|
|
185
|
+
bannerUrl?: string
|
|
186
|
+
personType?: PersonType
|
|
187
|
+
personIsSubscriber?: boolean
|
|
188
|
+
}): Promise<Wishlist> {
|
|
189
|
+
const data = {
|
|
190
|
+
id,
|
|
191
|
+
name: title,
|
|
192
|
+
description,
|
|
193
|
+
published,
|
|
194
|
+
metadatas: [
|
|
195
|
+
{
|
|
196
|
+
shop: this.shop,
|
|
197
|
+
title: `${userFullName} - ${title}`,
|
|
198
|
+
description: `${userFullName} - ${description}`,
|
|
199
|
+
},
|
|
200
|
+
],
|
|
201
|
+
personName: userFullName,
|
|
202
|
+
personPhoto: userPhoto,
|
|
203
|
+
theme,
|
|
204
|
+
bannerUrl,
|
|
205
|
+
personType: personType ?? PersonTypes.NONE,
|
|
206
|
+
personIsSubscriber: personIsSubscriber ?? false,
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
await this.createWishlistLog(WishlistLogType.UPDATE, data as Wishlist)
|
|
210
|
+
|
|
211
|
+
return this.wishlistRepository.update(data)
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
async delete(wishlistId: string): Promise<void> {
|
|
215
|
+
const wishlist = await this.findById(wishlistId)
|
|
216
|
+
|
|
217
|
+
await this.createWishlistLog(WishlistLogType.DELETE, wishlist)
|
|
218
|
+
|
|
219
|
+
return this.wishlistRepository.delete({ id: wishlistId })
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
getWishlistBySlug(slug: string): Promise<Wishlist> {
|
|
223
|
+
const [id] = slug.split('-')
|
|
224
|
+
|
|
225
|
+
if (+id) return this.wishlistRepository.get({ id })
|
|
226
|
+
|
|
227
|
+
return this.wishlistRepository.getWishlistBySlug(slug)
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
getWishlistsByPerson(personId: string): Promise<Wishlist[]> {
|
|
231
|
+
return this.wishlistRepository.getWishlistByPerson(personId)
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
async addProduct(wishlistId: string, productId: string): Promise<Wishlist> {
|
|
235
|
+
const wishlist = await this.wishlistRepository.get({ id: wishlistId })
|
|
236
|
+
const hasProduct = wishlist.products.some((p) => p == productId)
|
|
237
|
+
|
|
238
|
+
const wishlistData = await this.findById(wishlistId)
|
|
239
|
+
const productData = await this.findProductById(productId)
|
|
240
|
+
|
|
241
|
+
await this.createWishlistLog(WishlistLogType.ADD_PRODUCT, wishlistData, productData)
|
|
242
|
+
|
|
243
|
+
if (!hasProduct) {
|
|
244
|
+
wishlist.products = [...wishlist.products, productId]
|
|
245
|
+
await this.wishlistRepository.addProduct(wishlistId, productId)
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
return wishlist
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
async removeProduct(wishlistId: string, productId: string): Promise<Wishlist> {
|
|
252
|
+
const wishlist = await this.wishlistRepository.get({ id: wishlistId })
|
|
253
|
+
const productIndex = wishlist.products.findIndex((p) => p == productId)
|
|
254
|
+
|
|
255
|
+
if (productIndex != -1) {
|
|
256
|
+
wishlist.products.splice(productIndex, 1)
|
|
257
|
+
const wishlistData = await this.findById(wishlistId)
|
|
258
|
+
const productData = await this.findProductById(productId)
|
|
259
|
+
|
|
260
|
+
await this.createWishlistLog(WishlistLogType.REMOVE_PRODUCT, wishlistData, productData)
|
|
261
|
+
await this.wishlistRepository.removeProduct(wishlistId, productId)
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
return wishlist
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
private async findById(id: string): Promise<Wishlist> {
|
|
268
|
+
return this.wishlistRepository
|
|
269
|
+
.find({
|
|
270
|
+
fields: ['id', 'name', 'description', 'personId', 'personIsSubscriber', 'personType', 'personName'],
|
|
271
|
+
filters: {
|
|
272
|
+
id,
|
|
273
|
+
},
|
|
274
|
+
})
|
|
275
|
+
.then((res) => res.data.at(0))
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
private async findProductById(id: string): Promise<Product> {
|
|
279
|
+
return this.productCatalogRepository
|
|
280
|
+
.find({
|
|
281
|
+
fields: ['id', 'sku', 'EAN', 'name', 'brand'],
|
|
282
|
+
filters: {
|
|
283
|
+
id,
|
|
284
|
+
},
|
|
285
|
+
})
|
|
286
|
+
.then((res) => res.data.at(0))
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
private async createWishlistLog(type: WishlistLogType, wishlist: Wishlist, product?: Product) {
|
|
290
|
+
switch (type) {
|
|
291
|
+
case WishlistLogType.CREATE:
|
|
292
|
+
case WishlistLogType.UPDATE:
|
|
293
|
+
case WishlistLogType.DELETE:
|
|
294
|
+
await this.createWishlistOperationLog(type, wishlist)
|
|
295
|
+
break
|
|
296
|
+
|
|
297
|
+
case WishlistLogType.ADD_PRODUCT:
|
|
298
|
+
case WishlistLogType.REMOVE_PRODUCT:
|
|
299
|
+
await this.createWishlistProductLog(type, wishlist, product)
|
|
300
|
+
break
|
|
301
|
+
|
|
302
|
+
default:
|
|
303
|
+
break
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
private async createWishlistOperationLog(type: WishlistLogType, wishlist: Wishlist): Promise<void> {
|
|
308
|
+
const operation = this.getOperationTypeFromWishlistLogType(type)
|
|
309
|
+
|
|
310
|
+
await this.logRepository.create({
|
|
311
|
+
collection: 'wishlist',
|
|
312
|
+
date: new Date(),
|
|
313
|
+
operation,
|
|
314
|
+
documentId: wishlist.id,
|
|
315
|
+
document: this.buildWishlistLogDocument(wishlist, type),
|
|
316
|
+
})
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
private async createWishlistProductLog(type: WishlistLogType, wishlist: Wishlist, product: Product): Promise<void> {
|
|
320
|
+
await this.logRepository.create({
|
|
321
|
+
collection: 'wishlist',
|
|
322
|
+
date: new Date(),
|
|
323
|
+
operation: 'UPDATE',
|
|
324
|
+
documentId: wishlist.id,
|
|
325
|
+
document: {
|
|
326
|
+
...this.buildWishlistLogDocument(wishlist, type),
|
|
327
|
+
...this.buildProductLogData(product),
|
|
328
|
+
},
|
|
329
|
+
})
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
private getOperationTypeFromWishlistLogType(type: WishlistLogType): 'CREATE' | 'UPDATE' | 'DELETE' {
|
|
333
|
+
if (type === WishlistLogType.CREATE) return 'CREATE'
|
|
334
|
+
|
|
335
|
+
if (type === WishlistLogType.UPDATE) return 'UPDATE'
|
|
336
|
+
|
|
337
|
+
return 'DELETE'
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
private buildWishlistLogDocument(wishlist: Wishlist, type: WishlistLogType) {
|
|
341
|
+
return {
|
|
342
|
+
id: wishlist.id,
|
|
343
|
+
shop: this.shop,
|
|
344
|
+
name: wishlist.name,
|
|
345
|
+
description: wishlist.description,
|
|
346
|
+
published: wishlist.published,
|
|
347
|
+
type: type,
|
|
348
|
+
personType: wishlist.personType,
|
|
349
|
+
personId: wishlist.personId,
|
|
350
|
+
personName: wishlist.personName,
|
|
351
|
+
personIsSubscriber: wishlist.personIsSubscriber,
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
private buildProductLogData(product: Product) {
|
|
356
|
+
return {
|
|
357
|
+
productId: product.id,
|
|
358
|
+
productEAN: product.EAN,
|
|
359
|
+
productSKU: product.sku,
|
|
360
|
+
productName: product.name,
|
|
361
|
+
productBrand: product.brand,
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Inject, Injectable } from '@angular/core'
|
|
2
|
+
import { CheckoutRepository, UserRepository } from '@infrab4a/connect'
|
|
3
|
+
|
|
4
|
+
@Injectable()
|
|
5
|
+
export class CheckoutRepositoriesFacade {
|
|
6
|
+
constructor(
|
|
7
|
+
@Inject('CheckoutRepository') public readonly checkoutRepository: CheckoutRepository,
|
|
8
|
+
@Inject('UserRepository') public readonly userRepository: UserRepository,
|
|
9
|
+
) {}
|
|
10
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { CheckoutRepositoriesFacade } from './checkout-repositories.facade'
|
|
2
|
-
export { CheckoutDependenciesFacade } from './checkout-dependencies.facade'
|
|
1
|
+
export { CheckoutRepositoriesFacade } from './checkout-repositories.facade'
|
|
2
|
+
export { CheckoutDependenciesFacade } from './checkout-dependencies.facade'
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { Inject, Injectable } from '@angular/core'
|
|
2
|
+
import {
|
|
3
|
+
CheckoutSubscription,
|
|
4
|
+
CheckoutSubscriptionRepository,
|
|
5
|
+
CheckoutTypes,
|
|
6
|
+
Coupon,
|
|
7
|
+
isNil,
|
|
8
|
+
pick,
|
|
9
|
+
} from '@infrab4a/connect'
|
|
10
|
+
import { Observable } from 'rxjs'
|
|
11
|
+
import { concatMap } from 'rxjs/operators'
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
import { PERSISTENCE_PROVIDER } from '../consts'
|
|
15
|
+
import { DataPersistence } from '../persistence'
|
|
16
|
+
|
|
17
|
+
import { RequiredCheckoutSubscriptionData } from './types'
|
|
18
|
+
import { CouponService } from './coupon.service'
|
|
19
|
+
|
|
20
|
+
@Injectable()
|
|
21
|
+
export class CheckoutSubscriptionService {
|
|
22
|
+
constructor(
|
|
23
|
+
@Inject('CheckoutSubscriptionRepository')
|
|
24
|
+
private readonly checkoutSubscriptionRepository: CheckoutSubscriptionRepository,
|
|
25
|
+
@Inject(PERSISTENCE_PROVIDER) private readonly dataPersistence: DataPersistence,
|
|
26
|
+
private readonly couponService: CouponService,
|
|
27
|
+
) {}
|
|
28
|
+
|
|
29
|
+
getCheckoutSubscription(checkoutData?: RequiredCheckoutSubscriptionData): Observable<CheckoutSubscription> {
|
|
30
|
+
return this.dataPersistence
|
|
31
|
+
.get('checkoutSubscriptionId')
|
|
32
|
+
.pipe(
|
|
33
|
+
concatMap((id) =>
|
|
34
|
+
!isNil(id) ? this.checkoutSubscriptionRepository.get({ id }) : this.createCheckoutSubscription(checkoutData),
|
|
35
|
+
),
|
|
36
|
+
)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
clearCheckoutSubscriptionFromSession(): Observable<void> {
|
|
40
|
+
return this.dataPersistence.remove('checkoutSubscriptionId')
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
checkCoupon(nickname: string, _userEmail: string): Observable<Coupon> {
|
|
44
|
+
return this.getCheckoutSubscription().pipe(
|
|
45
|
+
concatMap((checkout) =>
|
|
46
|
+
this.couponService
|
|
47
|
+
.checkCoupon({
|
|
48
|
+
nickname,
|
|
49
|
+
checkoutType: CheckoutTypes.SUBSCRIPTION,
|
|
50
|
+
checkout,
|
|
51
|
+
plan: checkout.subscriptionPlan.name,
|
|
52
|
+
})
|
|
53
|
+
.pipe(),
|
|
54
|
+
),
|
|
55
|
+
)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
calcDiscountSubscription(coupon: Coupon) {
|
|
59
|
+
return this.getCheckoutSubscription().pipe(
|
|
60
|
+
concatMap((checkout) => this.couponService.calcDiscountSubscription(coupon, checkout).pipe()),
|
|
61
|
+
)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
private async createCheckoutSubscription(
|
|
65
|
+
checkoutData?: RequiredCheckoutSubscriptionData,
|
|
66
|
+
): Promise<CheckoutSubscription> {
|
|
67
|
+
const checkout = await this.checkoutSubscriptionRepository.create({
|
|
68
|
+
createdAt: new Date(),
|
|
69
|
+
...CheckoutSubscription.toInstance(pick(checkoutData, ['user', 'shop'])).toPlain(),
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
await this.dataPersistence.set('checkoutSubscriptionId', checkout.id).toPromise()
|
|
73
|
+
|
|
74
|
+
return checkout
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { Injectable } from '@angular/core'
|
|
2
|
+
import {
|
|
3
|
+
Checkout,
|
|
4
|
+
CheckoutPayloadRequest,
|
|
5
|
+
CheckoutResponse,
|
|
6
|
+
CheckoutStockValidation,
|
|
7
|
+
CheckoutTypes,
|
|
8
|
+
Coupon,
|
|
9
|
+
isNil,
|
|
10
|
+
NotFoundError,
|
|
11
|
+
pick,
|
|
12
|
+
ShippingMethodResponse,
|
|
13
|
+
ShippingProductRequest,
|
|
14
|
+
User,
|
|
15
|
+
UserAddress,
|
|
16
|
+
} from '@infrab4a/connect'
|
|
17
|
+
import { from, Observable, of, throwError } from 'rxjs'
|
|
18
|
+
import { concatMap, map } from 'rxjs/operators'
|
|
19
|
+
|
|
20
|
+
import { CheckoutDependenciesFacade, CheckoutRepositoriesFacade } from './checkout'
|
|
21
|
+
import { ConfigurationFacade } from './shared'
|
|
22
|
+
import { RequiredCheckoutData } from './types'
|
|
23
|
+
|
|
24
|
+
@Injectable()
|
|
25
|
+
export class CheckoutService {
|
|
26
|
+
private checkoutUrl: string = null
|
|
27
|
+
|
|
28
|
+
constructor(
|
|
29
|
+
private readonly repositoriesFacade: CheckoutRepositoriesFacade,
|
|
30
|
+
private readonly dependenciesFacade: CheckoutDependenciesFacade,
|
|
31
|
+
private readonly configurationFacade: ConfigurationFacade,
|
|
32
|
+
) {
|
|
33
|
+
this.checkoutUrl = this.configurationFacade.getCheckoutUrl()
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
getCheckout(checkoutData?: RequiredCheckoutData): Observable<Checkout> {
|
|
37
|
+
return this.dependenciesFacade.dataPersistence
|
|
38
|
+
.get('checkoutId')
|
|
39
|
+
.pipe(
|
|
40
|
+
concatMap((id) =>
|
|
41
|
+
!isNil(id) ? this.repositoriesFacade.checkoutRepository.get({ id }) : this.createCheckout(checkoutData),
|
|
42
|
+
),
|
|
43
|
+
)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
getUserByCheckout(checkoutId: string): Observable<User> {
|
|
47
|
+
return from(this.repositoriesFacade.checkoutRepository.get({ id: checkoutId })).pipe(
|
|
48
|
+
concatMap((checkout) =>
|
|
49
|
+
checkout?.user?.id
|
|
50
|
+
? of(checkout.user)
|
|
51
|
+
: from(this.repositoriesFacade.userRepository.get({ id: checkout.user.id })),
|
|
52
|
+
),
|
|
53
|
+
concatMap((user) => of(user) || throwError(() => new NotFoundError('User is not found'))),
|
|
54
|
+
)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
updateCheckoutLineItems(checkout: Partial<Checkout>): Observable<Checkout> {
|
|
58
|
+
return from(
|
|
59
|
+
this.repositoriesFacade.checkoutRepository.update(
|
|
60
|
+
Checkout.toInstance({ id: checkout.id, lineItems: checkout.lineItems }),
|
|
61
|
+
),
|
|
62
|
+
)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
updateCheckoutUser(checkout: Partial<Checkout>): Observable<Checkout> {
|
|
66
|
+
return from(
|
|
67
|
+
this.repositoriesFacade.checkoutRepository.update(Checkout.toInstance({ id: checkout.id, user: checkout.user })),
|
|
68
|
+
)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
clearCheckoutFromSession(): Observable<void> {
|
|
72
|
+
return this.dependenciesFacade.dataPersistence.remove('checkoutId')
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
resetCheckoutValues(): Observable<Checkout> {
|
|
76
|
+
return this.getCheckout().pipe(
|
|
77
|
+
concatMap((checkout) =>
|
|
78
|
+
this.dependenciesFacade.httpClient.post(`${this.checkoutUrl}/checkoutResetValues`, {
|
|
79
|
+
checkoutId: checkout.id,
|
|
80
|
+
}),
|
|
81
|
+
),
|
|
82
|
+
concatMap(() => this.getCheckout()),
|
|
83
|
+
)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
applyCouponDiscount(nickname: string, checkoutType: CheckoutTypes): Observable<Coupon> {
|
|
87
|
+
return this.getCheckout().pipe(
|
|
88
|
+
concatMap((checkout) =>
|
|
89
|
+
this.dependenciesFacade.httpClient.post(`${this.checkoutUrl}/checkoutApplyDiscount`, {
|
|
90
|
+
checkoutId: checkout.id,
|
|
91
|
+
coupon: nickname,
|
|
92
|
+
checkoutType,
|
|
93
|
+
}),
|
|
94
|
+
),
|
|
95
|
+
concatMap(() => this.getCheckout()),
|
|
96
|
+
map((checkout) => checkout.coupon),
|
|
97
|
+
)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
removeCouponDiscount(): Observable<Checkout> {
|
|
101
|
+
return this.getCheckout().pipe(
|
|
102
|
+
concatMap((checkout) =>
|
|
103
|
+
this.dependenciesFacade.httpClient.post(`${this.checkoutUrl}/checkoutRemoveDiscount`, {
|
|
104
|
+
checkoutId: checkout.id,
|
|
105
|
+
}),
|
|
106
|
+
),
|
|
107
|
+
concatMap(() => this.getCheckout()),
|
|
108
|
+
)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
validateStockProducts(): Observable<CheckoutStockValidation> {
|
|
112
|
+
return this.getCheckout().pipe(
|
|
113
|
+
concatMap((checkout) =>
|
|
114
|
+
this.dependenciesFacade.httpClient.post<{
|
|
115
|
+
valid: boolean
|
|
116
|
+
outOfStock: string[]
|
|
117
|
+
limitedStock: string[]
|
|
118
|
+
}>(`${this.checkoutUrl}/checkoutValidateProductStock`, {
|
|
119
|
+
checkoutId: checkout.id,
|
|
120
|
+
}),
|
|
121
|
+
),
|
|
122
|
+
)
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
selectShippingAddress(address: UserAddress): Observable<Checkout> {
|
|
126
|
+
const formattedAddress: UserAddress = {
|
|
127
|
+
...address,
|
|
128
|
+
zip: this.formatZip(address.zip),
|
|
129
|
+
} as UserAddress
|
|
130
|
+
|
|
131
|
+
return this.getCheckout().pipe(
|
|
132
|
+
concatMap((checkout) => {
|
|
133
|
+
return this.repositoriesFacade.checkoutRepository.update(
|
|
134
|
+
Checkout.toInstance({
|
|
135
|
+
id: checkout.id,
|
|
136
|
+
shippingAddress: formattedAddress,
|
|
137
|
+
billingAddress: formattedAddress,
|
|
138
|
+
}),
|
|
139
|
+
)
|
|
140
|
+
}),
|
|
141
|
+
)
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
private formatZip(zip?: string): string | undefined {
|
|
145
|
+
if (!zip) return zip
|
|
146
|
+
|
|
147
|
+
const digits = zip.replace(/\D/g, '')
|
|
148
|
+
|
|
149
|
+
return digits
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
getAvailableShippingForProduct(productShipping: ShippingProductRequest): Observable<ShippingMethodResponse[]> {
|
|
153
|
+
return this.dependenciesFacade.httpClient.post<ShippingMethodResponse[]>(
|
|
154
|
+
`${this.checkoutUrl}/checkoutGetAvailableShipping`,
|
|
155
|
+
{
|
|
156
|
+
checkoutId: null,
|
|
157
|
+
productShipping,
|
|
158
|
+
},
|
|
159
|
+
)
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
getAvailableShippingForCheckout(): Observable<ShippingMethodResponse[]> {
|
|
163
|
+
return this.getCheckout().pipe(
|
|
164
|
+
concatMap((checkout) =>
|
|
165
|
+
this.dependenciesFacade.httpClient.post<ShippingMethodResponse[]>(
|
|
166
|
+
`${this.checkoutUrl}/checkoutGetAvailableShipping`,
|
|
167
|
+
{
|
|
168
|
+
checkoutId: checkout.id,
|
|
169
|
+
productShipping: null,
|
|
170
|
+
},
|
|
171
|
+
),
|
|
172
|
+
),
|
|
173
|
+
)
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
selectShipping(option: string): Observable<Checkout> {
|
|
177
|
+
return this.getCheckout().pipe(
|
|
178
|
+
concatMap((checkout) =>
|
|
179
|
+
this.dependenciesFacade.httpClient.post(`${this.checkoutUrl}/checkoutSelectShipping`, {
|
|
180
|
+
checkoutId: checkout.id,
|
|
181
|
+
shippingOption: option,
|
|
182
|
+
}),
|
|
183
|
+
),
|
|
184
|
+
concatMap(() => this.getCheckout()),
|
|
185
|
+
)
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
createOrder(
|
|
189
|
+
checkoutPayload: CheckoutPayloadRequest,
|
|
190
|
+
paymentProvider: string,
|
|
191
|
+
applicationVersion: string,
|
|
192
|
+
): Observable<CheckoutResponse> {
|
|
193
|
+
return this.dependenciesFacade.httpClient.post<CheckoutResponse>(`${this.checkoutUrl}/checkout`, {
|
|
194
|
+
data: {
|
|
195
|
+
...checkoutPayload,
|
|
196
|
+
applicationVersion,
|
|
197
|
+
paymentProvider,
|
|
198
|
+
},
|
|
199
|
+
})
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
private async createCheckout(checkoutData?: RequiredCheckoutData): Promise<Checkout> {
|
|
203
|
+
const checkout = await this.repositoriesFacade.checkoutRepository.create({
|
|
204
|
+
createdAt: new Date(),
|
|
205
|
+
...Checkout.toInstance(pick(checkoutData, ['user', 'shop'])).toPlain(),
|
|
206
|
+
shop: checkoutData?.shop || this.configurationFacade.defaultShop,
|
|
207
|
+
})
|
|
208
|
+
|
|
209
|
+
await this.dependenciesFacade.dataPersistence.set('checkoutId', checkout.id).toPromise()
|
|
210
|
+
|
|
211
|
+
return checkout
|
|
212
|
+
}
|
|
213
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Inject, Injectable } from '@angular/core'
|
|
2
|
+
import { CategoryRepository, CouponRepository, OrderRepository } from '@infrab4a/connect'
|
|
3
|
+
|
|
4
|
+
@Injectable()
|
|
5
|
+
export class CouponRepositoriesFacade {
|
|
6
|
+
constructor(
|
|
7
|
+
@Inject('CouponRepository') public readonly couponRepository: CouponRepository,
|
|
8
|
+
@Inject('OrderRepository') public readonly orderRepository: OrderRepository,
|
|
9
|
+
@Inject('CategoryRepository') public readonly categoryRepository: CategoryRepository,
|
|
10
|
+
) {}
|
|
11
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { CouponRepositoriesFacade } from './coupon-repositories.facade'
|
|
1
|
+
export { CouponRepositoriesFacade } from './coupon-repositories.facade'
|