@infrab4a/connect-angular 5.8.19 → 5.8.21-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/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 +266 -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 +443 -0
- package/src/angular-hasura-graphql.module.ts +269 -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 +148 -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.spec.ts +61 -0
- package/src/services/catalog/adapters/new-category-structure.adapter.ts +46 -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.spec.ts +214 -0
- package/src/services/catalog/strategies/category-search.strategy.ts +207 -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.service.ts +236 -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/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 +9 -0
- package/src/services/order-product-review.service.ts +135 -0
- package/src/services/order-recurrence.service.ts +121 -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/test.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 -289
- 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 -653
- 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 -84
- 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.service.mjs +0 -131
- package/esm2020/services/coupon/coupon-repositories.facade.mjs +0 -24
- package/esm2020/services/coupon/index.mjs +0 -2
- 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 -130
- package/esm2020/services/index.mjs +0 -10
- package/esm2020/services/order-product-review.service.mjs +0 -126
- package/esm2020/services/order-recurrence.service.mjs +0 -76
- 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 -3504
- package/fesm2015/infrab4a-connect-angular.mjs.map +0 -1
- package/fesm2020/infrab4a-connect-angular.mjs +0 -3439
- 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 -27
- 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.service.d.ts +0 -33
- package/services/coupon/coupon-repositories.facade.d.ts +0 -10
- 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 -34
- package/services/index.d.ts +0 -9
- package/services/order-product-review.service.d.ts +0 -18
- package/services/order-recurrence.service.d.ts +0 -25
- 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,236 @@
|
|
|
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
|
+
applyPointsDiscount(points: number): Observable<Checkout> {
|
|
112
|
+
return this.getCheckout().pipe(
|
|
113
|
+
concatMap((checkout) =>
|
|
114
|
+
this.dependenciesFacade.httpClient.post(`${this.checkoutUrl}/checkoutApplyPointsDiscount`, {
|
|
115
|
+
checkoutId: checkout.id,
|
|
116
|
+
points,
|
|
117
|
+
}),
|
|
118
|
+
),
|
|
119
|
+
concatMap(() => this.getCheckout()),
|
|
120
|
+
)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
removePointsDiscount(): Observable<Checkout> {
|
|
124
|
+
return this.getCheckout().pipe(
|
|
125
|
+
concatMap((checkout) =>
|
|
126
|
+
this.dependenciesFacade.httpClient.post(`${this.checkoutUrl}/checkoutRemovePointsDiscount`, {
|
|
127
|
+
checkoutId: checkout.id,
|
|
128
|
+
}),
|
|
129
|
+
),
|
|
130
|
+
concatMap(() => this.getCheckout()),
|
|
131
|
+
)
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
validateStockProducts(): Observable<CheckoutStockValidation> {
|
|
135
|
+
return this.getCheckout().pipe(
|
|
136
|
+
concatMap((checkout) =>
|
|
137
|
+
this.dependenciesFacade.httpClient.post<{
|
|
138
|
+
valid: boolean
|
|
139
|
+
outOfStock: string[]
|
|
140
|
+
limitedStock: string[]
|
|
141
|
+
}>(`${this.checkoutUrl}/checkoutValidateProductStock`, {
|
|
142
|
+
checkoutId: checkout.id,
|
|
143
|
+
}),
|
|
144
|
+
),
|
|
145
|
+
)
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
selectShippingAddress(address: UserAddress): Observable<Checkout> {
|
|
149
|
+
const formattedAddress: UserAddress = {
|
|
150
|
+
...address,
|
|
151
|
+
zip: this.formatZip(address.zip),
|
|
152
|
+
} as UserAddress
|
|
153
|
+
|
|
154
|
+
return this.getCheckout().pipe(
|
|
155
|
+
concatMap((checkout) => {
|
|
156
|
+
return this.repositoriesFacade.checkoutRepository.update(
|
|
157
|
+
Checkout.toInstance({
|
|
158
|
+
id: checkout.id,
|
|
159
|
+
shippingAddress: formattedAddress,
|
|
160
|
+
billingAddress: formattedAddress,
|
|
161
|
+
}),
|
|
162
|
+
)
|
|
163
|
+
}),
|
|
164
|
+
)
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
private formatZip(zip?: string): string | undefined {
|
|
168
|
+
if (!zip) return zip
|
|
169
|
+
|
|
170
|
+
const digits = zip.replace(/\D/g, '')
|
|
171
|
+
|
|
172
|
+
return digits
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
getAvailableShippingForProduct(productShipping: ShippingProductRequest): Observable<ShippingMethodResponse[]> {
|
|
176
|
+
return this.dependenciesFacade.httpClient.post<ShippingMethodResponse[]>(
|
|
177
|
+
`${this.checkoutUrl}/checkoutGetAvailableShipping`,
|
|
178
|
+
{
|
|
179
|
+
checkoutId: null,
|
|
180
|
+
productShipping,
|
|
181
|
+
},
|
|
182
|
+
)
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
getAvailableShippingForCheckout(): Observable<ShippingMethodResponse[]> {
|
|
186
|
+
return this.getCheckout().pipe(
|
|
187
|
+
concatMap((checkout) =>
|
|
188
|
+
this.dependenciesFacade.httpClient.post<ShippingMethodResponse[]>(
|
|
189
|
+
`${this.checkoutUrl}/checkoutGetAvailableShipping`,
|
|
190
|
+
{
|
|
191
|
+
checkoutId: checkout.id,
|
|
192
|
+
productShipping: null,
|
|
193
|
+
},
|
|
194
|
+
),
|
|
195
|
+
),
|
|
196
|
+
)
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
selectShipping(option: string): Observable<Checkout> {
|
|
200
|
+
return this.getCheckout().pipe(
|
|
201
|
+
concatMap((checkout) =>
|
|
202
|
+
this.dependenciesFacade.httpClient.post(`${this.checkoutUrl}/checkoutSelectShipping`, {
|
|
203
|
+
checkoutId: checkout.id,
|
|
204
|
+
shippingOption: option,
|
|
205
|
+
}),
|
|
206
|
+
),
|
|
207
|
+
concatMap(() => this.getCheckout()),
|
|
208
|
+
)
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
createOrder(
|
|
212
|
+
checkoutPayload: CheckoutPayloadRequest,
|
|
213
|
+
paymentProvider: string,
|
|
214
|
+
applicationVersion: string,
|
|
215
|
+
): Observable<CheckoutResponse> {
|
|
216
|
+
return this.dependenciesFacade.httpClient.post<CheckoutResponse>(`${this.checkoutUrl}/checkout`, {
|
|
217
|
+
data: {
|
|
218
|
+
...checkoutPayload,
|
|
219
|
+
applicationVersion,
|
|
220
|
+
paymentProvider,
|
|
221
|
+
},
|
|
222
|
+
})
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
private async createCheckout(checkoutData?: RequiredCheckoutData): Promise<Checkout> {
|
|
226
|
+
const checkout = await this.repositoriesFacade.checkoutRepository.create({
|
|
227
|
+
createdAt: new Date(),
|
|
228
|
+
...Checkout.toInstance(pick(checkoutData, ['user', 'shop'])).toPlain(),
|
|
229
|
+
shop: checkoutData?.shop || this.configurationFacade.defaultShop,
|
|
230
|
+
})
|
|
231
|
+
|
|
232
|
+
await this.dependenciesFacade.dataPersistence.set('checkoutId', checkout.id).toPromise()
|
|
233
|
+
|
|
234
|
+
return checkout
|
|
235
|
+
}
|
|
236
|
+
}
|
|
@@ -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'
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Checkout, CheckoutTypes, Coupon } from '@infrab4a/connect'
|
|
2
|
+
|
|
3
|
+
export type CheckCouponParams = {
|
|
4
|
+
nickname: string
|
|
5
|
+
checkoutType: CheckoutTypes
|
|
6
|
+
checkout: Partial<Checkout>
|
|
7
|
+
plan: string
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export type CouponRulesValidationParams = {
|
|
11
|
+
coupon: Coupon
|
|
12
|
+
checkoutType: CheckoutTypes
|
|
13
|
+
checkout: Partial<Checkout>
|
|
14
|
+
plan: string
|
|
15
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { CustomError } from 'ts-custom-error'
|
|
2
|
+
|
|
3
|
+
import { InvalidCouponError } from './invalid-coupon.error'
|
|
4
|
+
|
|
5
|
+
export class GroupInvalidCouponError extends CustomError {
|
|
6
|
+
constructor(readonly errors: InvalidCouponError[]) {
|
|
7
|
+
super('Many coupon errors throw')
|
|
8
|
+
}
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './util.helper'
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export class UtilHelper {
|
|
2
|
+
static createSlug(name: string): string {
|
|
3
|
+
return name
|
|
4
|
+
.toLowerCase()
|
|
5
|
+
.replace(/\s+/g, '-')
|
|
6
|
+
.replace(/[ãàáäâ]/g, 'a')
|
|
7
|
+
.replace(/[ẽèéëê]/g, 'e')
|
|
8
|
+
.replace(/[ìíïî]/g, 'i')
|
|
9
|
+
.replace(/[õòóöô]/g, 'o')
|
|
10
|
+
.replace(/[ùúüû]/g, 'u')
|
|
11
|
+
.replace(/[ñ]/g, 'n')
|
|
12
|
+
.replace(/[ç]/g, 'c')
|
|
13
|
+
.replace(/[&]/g, 'and')
|
|
14
|
+
.replace(/[^\w-]+/g, '')
|
|
15
|
+
.replace(/--+/g, '-')
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Inject, Injectable } from '@angular/core'
|
|
2
|
+
import { CategoryRepository, HomeRepository, ProductRepository } from '@infrab4a/connect'
|
|
3
|
+
|
|
4
|
+
@Injectable()
|
|
5
|
+
export class HomeShopRepositoriesFacade {
|
|
6
|
+
constructor(
|
|
7
|
+
@Inject('CategoryRepository') public readonly categoryRepository: CategoryRepository,
|
|
8
|
+
@Inject('HomeRepository') public readonly homeRepository: HomeRepository,
|
|
9
|
+
@Inject('ProductRepository') public readonly productRepository: ProductRepository,
|
|
10
|
+
) {}
|
|
11
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { HomeShopRepositoriesFacade } from './home-shop-repositories.facade'
|
|
1
|
+
export { HomeShopRepositoriesFacade } from './home-shop-repositories.facade'
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { Injectable } from '@angular/core'
|
|
2
|
+
import {
|
|
3
|
+
add,
|
|
4
|
+
Banner,
|
|
5
|
+
Category,
|
|
6
|
+
Home,
|
|
7
|
+
HomeCategoryGroup,
|
|
8
|
+
HomeData,
|
|
9
|
+
pick,
|
|
10
|
+
Product,
|
|
11
|
+
RequiredArgumentError,
|
|
12
|
+
ShippingThresholds,
|
|
13
|
+
Shops,
|
|
14
|
+
Where,
|
|
15
|
+
} from '@infrab4a/connect'
|
|
16
|
+
import { forkJoin, from, Observable, of, throwError } from 'rxjs'
|
|
17
|
+
import { concatMap, map, tap } from 'rxjs/operators'
|
|
18
|
+
|
|
19
|
+
import { HomeShopRepositoriesFacade } from './home-shop'
|
|
20
|
+
import { ConfigurationFacade } from './shared'
|
|
21
|
+
|
|
22
|
+
type HomeConfigurationId = 'glamshop' | 'mens_market'
|
|
23
|
+
type BannerType = 'brand' | 'buyToWin' | 'block' | 'blog'
|
|
24
|
+
|
|
25
|
+
@Injectable()
|
|
26
|
+
export class HomeShopService {
|
|
27
|
+
private homeConfiguration: Home
|
|
28
|
+
|
|
29
|
+
private get homeId(): HomeConfigurationId {
|
|
30
|
+
if (this.configurationFacade.defaultShop === Shops.GLAMSHOP) return 'glamshop'
|
|
31
|
+
|
|
32
|
+
if (this.configurationFacade.defaultShop === Shops.MENSMARKET) return 'mens_market'
|
|
33
|
+
|
|
34
|
+
return null
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
constructor(
|
|
38
|
+
private readonly repositoriesFacade: HomeShopRepositoriesFacade,
|
|
39
|
+
private readonly configurationFacade: ConfigurationFacade,
|
|
40
|
+
) {}
|
|
41
|
+
|
|
42
|
+
getHomeData(): Observable<Home> {
|
|
43
|
+
return this.getHomeConfiguration().pipe(
|
|
44
|
+
map((home) => (home?.data?.expiresAt > new Date() ? home : null)),
|
|
45
|
+
concatMap((home) =>
|
|
46
|
+
home
|
|
47
|
+
? of(home)
|
|
48
|
+
: forkJoin([
|
|
49
|
+
this.getDiscoverProducts(this.gender),
|
|
50
|
+
this.getFeaturedProducts(this.gender),
|
|
51
|
+
this.getVerticalProducts(this.gender),
|
|
52
|
+
]).pipe(
|
|
53
|
+
map(([discoverProducts, featuredProducts, verticalProducts]) => ({
|
|
54
|
+
discoverProducts,
|
|
55
|
+
featuredProducts,
|
|
56
|
+
verticalProducts,
|
|
57
|
+
})),
|
|
58
|
+
concatMap((data) => this.saveHomeData(data)),
|
|
59
|
+
),
|
|
60
|
+
),
|
|
61
|
+
)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
getBanners(type: BannerType): Observable<Banner[]> {
|
|
65
|
+
return this.getHomeConfiguration().pipe(
|
|
66
|
+
map((home) => {
|
|
67
|
+
if (type === 'brand') return home.brandsCarousel
|
|
68
|
+
|
|
69
|
+
if (type === 'buyToWin') return [home.buyToWinBanner]
|
|
70
|
+
|
|
71
|
+
if (type === 'block') return home.blockBanners
|
|
72
|
+
|
|
73
|
+
if (type === 'blog') return [home.blogBanner]
|
|
74
|
+
|
|
75
|
+
return []
|
|
76
|
+
}),
|
|
77
|
+
)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
getMinValueForFreeShipping(): Observable<number> {
|
|
81
|
+
return this.getHomeConfiguration().pipe(map((home) => home.minValueForFreeShipping))
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Retorna os thresholds de frete grátis estruturados configurados no documento
|
|
86
|
+
* Home (`shippingThresholds`). Quando o documento ainda não possui essa
|
|
87
|
+
* estrutura, retorna um default conservador equivalente à regra legada
|
|
88
|
+
* (edition: 50, avulsoSp: 99, avulsoOutro: null) para que consumidores não
|
|
89
|
+
* quebrem durante a migração.
|
|
90
|
+
*/
|
|
91
|
+
getShippingThresholds(): Observable<ShippingThresholds> {
|
|
92
|
+
const conservativeDefault: ShippingThresholds = { edition: 50, avulsoSp: 99, avulsoOutro: null }
|
|
93
|
+
|
|
94
|
+
return this.getHomeConfiguration().pipe(map((home) => home.shippingThresholds ?? conservativeDefault))
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
private getDiscoverProducts(_gender?: string): Observable<{ category: Category; products: Product[] }[]> {
|
|
98
|
+
return this.getHomeConfiguration().pipe(
|
|
99
|
+
concatMap((home) =>
|
|
100
|
+
from(
|
|
101
|
+
this.repositoriesFacade.categoryRepository.getCategoriesForHome({
|
|
102
|
+
categoryIds: home.discoverCategories,
|
|
103
|
+
shop: this.configurationFacade.defaultShop,
|
|
104
|
+
}),
|
|
105
|
+
).pipe(map((groups) => groups.map(this.buildCategoryGroupWithRequiredData))),
|
|
106
|
+
),
|
|
107
|
+
)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
private getFeaturedProducts(_gender?: string): Observable<{ category: Category; products: Product[] }[]> {
|
|
111
|
+
return this.getHomeConfiguration().pipe(
|
|
112
|
+
concatMap((home) =>
|
|
113
|
+
from(
|
|
114
|
+
this.repositoriesFacade.categoryRepository.getCategoriesForHome({
|
|
115
|
+
categoryIds: home.featuredCategories,
|
|
116
|
+
shop: this.configurationFacade.defaultShop,
|
|
117
|
+
}),
|
|
118
|
+
).pipe(map((groups) => groups.map(this.buildCategoryGroupWithRequiredData))),
|
|
119
|
+
),
|
|
120
|
+
)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
private getVerticalProducts(gender?: string): Observable<{ category: Category; products: Product[] }[]> {
|
|
124
|
+
return this.getHomeConfiguration().pipe(
|
|
125
|
+
concatMap((home) =>
|
|
126
|
+
forkJoin(
|
|
127
|
+
home.verticalCarousels.filter(Boolean).map((id) =>
|
|
128
|
+
from(this.repositoriesFacade.categoryRepository.get({ id })).pipe(
|
|
129
|
+
concatMap((category) =>
|
|
130
|
+
from(
|
|
131
|
+
this.repositoriesFacade.productRepository.find({
|
|
132
|
+
filters: {
|
|
133
|
+
categories: { operator: Where.IN, value: [category.id] },
|
|
134
|
+
...(gender ? { tags: { operator: Where.IN, value: [gender] } } : {}),
|
|
135
|
+
},
|
|
136
|
+
limits: { limit: 12 },
|
|
137
|
+
}),
|
|
138
|
+
).pipe(map((products) => ({ category, products }))),
|
|
139
|
+
),
|
|
140
|
+
map(({ category, products }) => ({ category, products: products.data })),
|
|
141
|
+
map(this.buildCategoryGroupWithRequiredData),
|
|
142
|
+
),
|
|
143
|
+
),
|
|
144
|
+
),
|
|
145
|
+
),
|
|
146
|
+
)
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
private getHomeConfiguration(): Observable<Home> {
|
|
150
|
+
return of(this.homeConfiguration).pipe(
|
|
151
|
+
concatMap((home) =>
|
|
152
|
+
home
|
|
153
|
+
? of(home)
|
|
154
|
+
: !this.homeId
|
|
155
|
+
? throwError(() => new RequiredArgumentError(['homeId']))
|
|
156
|
+
: from(this.repositoriesFacade.homeRepository.get({ id: this.homeId })).pipe(
|
|
157
|
+
tap((homeLoaded) => (this.homeConfiguration = homeLoaded)),
|
|
158
|
+
),
|
|
159
|
+
),
|
|
160
|
+
)
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
private saveHomeData(homeData: HomeData): Observable<Home> {
|
|
164
|
+
const data = {
|
|
165
|
+
createdAt: new Date(),
|
|
166
|
+
expiresAt: add(new Date(), { hours: 1 }),
|
|
167
|
+
data: homeData,
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return from(
|
|
171
|
+
this.repositoriesFacade.homeRepository.update({
|
|
172
|
+
id: this.homeId,
|
|
173
|
+
data,
|
|
174
|
+
}),
|
|
175
|
+
).pipe(
|
|
176
|
+
tap(() => (this.homeConfiguration.data = data)),
|
|
177
|
+
map(() => this.homeConfiguration),
|
|
178
|
+
)
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
private buildCategoryGroupWithRequiredData = (group: HomeCategoryGroup): HomeCategoryGroup => ({
|
|
182
|
+
category: Category.toInstance(pick(group?.category?.toPlain() || {}, ['id', 'name', 'slug', 'conditions'])),
|
|
183
|
+
products:
|
|
184
|
+
group?.products?.map((product) =>
|
|
185
|
+
Product.toInstance(
|
|
186
|
+
pick(product?.toPlain() || {}, [
|
|
187
|
+
'id',
|
|
188
|
+
'price',
|
|
189
|
+
'reviews',
|
|
190
|
+
'hasVariants',
|
|
191
|
+
'slug',
|
|
192
|
+
'sku',
|
|
193
|
+
'stock',
|
|
194
|
+
'costPrice',
|
|
195
|
+
'images',
|
|
196
|
+
'miniatures',
|
|
197
|
+
'name',
|
|
198
|
+
'weight',
|
|
199
|
+
'rate',
|
|
200
|
+
'type',
|
|
201
|
+
'brand',
|
|
202
|
+
]),
|
|
203
|
+
),
|
|
204
|
+
) || [],
|
|
205
|
+
})
|
|
206
|
+
|
|
207
|
+
private get gender() {
|
|
208
|
+
return this.homeId === 'mens_market' ? 'masculino' : undefined
|
|
209
|
+
}
|
|
210
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './auth.service'
|
|
2
|
+
export * from './cart.service'
|
|
3
|
+
export * from './catalog'
|
|
4
|
+
export * from './checkout.service'
|
|
5
|
+
export * from './helpers'
|
|
6
|
+
export * from './home-shop.service'
|
|
7
|
+
export * from './order-product-review.service'
|
|
8
|
+
export * from './order-recurrence.service'
|
|
9
|
+
export * from './order.service'
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { Inject, Injectable } from '@angular/core'
|
|
2
|
+
import {
|
|
3
|
+
LineItem,
|
|
4
|
+
Order,
|
|
5
|
+
OrderFirestoreRepository,
|
|
6
|
+
OrderStatus,
|
|
7
|
+
ProductReview,
|
|
8
|
+
ProductReviewRepository,
|
|
9
|
+
Shops,
|
|
10
|
+
VariantRepository,
|
|
11
|
+
Where,
|
|
12
|
+
} from '@infrab4a/connect'
|
|
13
|
+
|
|
14
|
+
import { DEFAULT_SHOP } from '../consts'
|
|
15
|
+
|
|
16
|
+
import { PendingProductReview, ProductReviewCreate } from './types'
|
|
17
|
+
|
|
18
|
+
@Injectable()
|
|
19
|
+
export class OrderProductReviewService {
|
|
20
|
+
constructor(
|
|
21
|
+
@Inject('OrderRepository') private readonly orderRepository: OrderFirestoreRepository,
|
|
22
|
+
@Inject('ProductReviewRepository') private readonly productReviewRepository: ProductReviewRepository,
|
|
23
|
+
@Inject('VariantRepository') private readonly variantRepository: VariantRepository,
|
|
24
|
+
@Inject(DEFAULT_SHOP) public readonly defaultShop: Shops,
|
|
25
|
+
) {}
|
|
26
|
+
|
|
27
|
+
async getPendingReviewsByEmail(email: string): Promise<PendingProductReview[]> {
|
|
28
|
+
const products: PendingProductReview[] = []
|
|
29
|
+
const orders = await this.getOrdersByEmail(email)
|
|
30
|
+
|
|
31
|
+
if (orders.length) {
|
|
32
|
+
for (const order of orders) {
|
|
33
|
+
const lineItems = order.lineItems.filter((item) => !item.isGift)
|
|
34
|
+
|
|
35
|
+
for (const item of lineItems) {
|
|
36
|
+
const productReview = await this.getProductReview(order, item)
|
|
37
|
+
|
|
38
|
+
if (productReview?.status != null) continue
|
|
39
|
+
|
|
40
|
+
products.push(this.buildProductReview(order, item, productReview))
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return products
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
private async getOrdersByEmail(email: string): Promise<Order[]> {
|
|
49
|
+
const { data: orders } = await this.orderRepository.find({
|
|
50
|
+
filters: {
|
|
51
|
+
user: {
|
|
52
|
+
email: email,
|
|
53
|
+
},
|
|
54
|
+
shop: this.defaultShop,
|
|
55
|
+
status: OrderStatus.ENTREGUE,
|
|
56
|
+
createdAt: {
|
|
57
|
+
operator: Where.GTE,
|
|
58
|
+
value: new Date(2024, 0, 0, 0, 0, 0).getTime(),
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
orderBy: {
|
|
62
|
+
createdAt: 'desc',
|
|
63
|
+
},
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
return orders
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
private async getProductReview(order: Order, item: LineItem) {
|
|
70
|
+
const products: string[] = [item.id]
|
|
71
|
+
const isVariant = await this.variantRepository
|
|
72
|
+
.find({
|
|
73
|
+
filters: {
|
|
74
|
+
id: item.id,
|
|
75
|
+
},
|
|
76
|
+
})
|
|
77
|
+
.then((res) => res.data.at(0))
|
|
78
|
+
|
|
79
|
+
if (isVariant) products.push(isVariant.productId)
|
|
80
|
+
const productReview = await this.productReviewRepository
|
|
81
|
+
.find({
|
|
82
|
+
filters: {
|
|
83
|
+
orderId: { operator: Where.IN, value: [order.id, order.orderNumber].filter(Boolean) },
|
|
84
|
+
productId: { operator: Where.IN, value: products },
|
|
85
|
+
},
|
|
86
|
+
})
|
|
87
|
+
.then((res) => res.data.at(0))
|
|
88
|
+
|
|
89
|
+
return productReview
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
private buildProductReview(order: Order, item: LineItem, review: ProductReview) {
|
|
93
|
+
return {
|
|
94
|
+
id: item.id,
|
|
95
|
+
orderId: order.id,
|
|
96
|
+
orderNumber: order.orderNumber,
|
|
97
|
+
isEdition: false,
|
|
98
|
+
name: item.name,
|
|
99
|
+
image: item.image,
|
|
100
|
+
deliveryDate: order.deliveredAt || null,
|
|
101
|
+
evaluationInAnalysis: review ? true : false,
|
|
102
|
+
rating: review ? review.rate : null,
|
|
103
|
+
shopProductSlug: item.slug,
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
async createReview(review: ProductReviewCreate): Promise<ProductReview> {
|
|
108
|
+
return this.productReviewRepository.create(
|
|
109
|
+
ProductReview.toInstance({
|
|
110
|
+
productId: review.productId.toString(),
|
|
111
|
+
shop: review.shop,
|
|
112
|
+
rate: review.rate,
|
|
113
|
+
author: review.author,
|
|
114
|
+
email: review.email,
|
|
115
|
+
location: review.location,
|
|
116
|
+
review: review.comment,
|
|
117
|
+
title: review.title,
|
|
118
|
+
personId: review.personId,
|
|
119
|
+
points: review.points,
|
|
120
|
+
orderId: review.orderId,
|
|
121
|
+
}),
|
|
122
|
+
)
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
async verifyReviewProductAndOrder(orderId: string[], productId: string) {
|
|
126
|
+
return this.productReviewRepository
|
|
127
|
+
.find({
|
|
128
|
+
filters: {
|
|
129
|
+
orderId: { operator: Where.IN, value: orderId },
|
|
130
|
+
productId: productId,
|
|
131
|
+
},
|
|
132
|
+
})
|
|
133
|
+
.then((res) => res.data)
|
|
134
|
+
}
|
|
135
|
+
}
|