@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.
Files changed (301) hide show
  1. package/eslint.config.js +18 -0
  2. package/index.ts +1 -0
  3. package/karma.conf.js +32 -0
  4. package/ng-package.json +8 -0
  5. package/package.json +4 -24
  6. package/project.json +37 -0
  7. package/src/angular-connect.module.ts +270 -0
  8. package/src/angular-elastic-search.module.ts +23 -0
  9. package/src/angular-firebase-auth.module.ts +101 -0
  10. package/src/angular-firestore.module.ts +407 -0
  11. package/src/angular-hasura-graphql.module.ts +268 -0
  12. package/src/angular-vertex-search.module.ts +23 -0
  13. package/src/consts/backend-url.const.ts +1 -0
  14. package/src/consts/category-structure.ts +1 -0
  15. package/src/consts/default-shop.const.ts +1 -0
  16. package/src/consts/es-config.const.ts +1 -0
  17. package/src/consts/firebase-const.ts +5 -0
  18. package/src/consts/hasura-options.const.ts +1 -0
  19. package/src/consts/index.ts +8 -0
  20. package/src/consts/persistence.const.ts +1 -0
  21. package/src/consts/storage-base-url.const.ts +1 -0
  22. package/src/consts/vertex-config.const.ts +1 -0
  23. package/src/helpers/index.ts +1 -0
  24. package/src/helpers/mobile-operation-system-checker.helper.ts +10 -0
  25. package/src/index.ts +6 -0
  26. package/src/interfaces/catalog-strategies.interface.ts +36 -0
  27. package/src/interfaces/category-facades.interface.ts +7 -0
  28. package/src/interfaces/index.ts +2 -0
  29. package/src/persistence/cookie-data-persistence.ts +21 -0
  30. package/src/persistence/data-persistence.ts +7 -0
  31. package/src/persistence/index.ts +2 -0
  32. package/src/services/auth.service.ts +39 -0
  33. package/src/services/cart/cart-services.facade.ts +14 -0
  34. package/src/services/cart/index.ts +1 -0
  35. package/src/services/cart.service.ts +124 -0
  36. package/src/services/catalog/adapters/category-structure.adapter.ts +5 -0
  37. package/src/services/catalog/adapters/index.ts +3 -0
  38. package/src/services/catalog/adapters/new-category-structure.adapter.ts +42 -0
  39. package/src/services/catalog/adapters/old-category-structure.adapter.ts +17 -0
  40. package/src/services/catalog/catalog.service.ts +153 -0
  41. package/src/services/catalog/category.service.ts +56 -0
  42. package/src/services/catalog/context/catalog-search.context.ts +59 -0
  43. package/src/services/catalog/enums/index.ts +1 -0
  44. package/src/services/catalog/enums/product-sorts.enum.ts +9 -0
  45. package/src/services/catalog/facades/catalog-service.facade.ts +32 -0
  46. package/src/services/catalog/facades/catalog-strategies.facade.ts +12 -0
  47. package/src/services/catalog/facades/category-repository.facade.ts +10 -0
  48. package/src/services/catalog/facades/category-service.facade.ts +25 -0
  49. package/{services/catalog/facades/index.d.ts → src/services/catalog/facades/index.ts} +5 -5
  50. package/src/services/catalog/facades/product-catalog.facade.ts +13 -0
  51. package/src/services/catalog/helpers/brand-manager.helper.ts +69 -0
  52. package/src/services/catalog/helpers/catalog-filter.helper.ts +50 -0
  53. package/src/services/catalog/helpers/catalog-sort.helper.ts +54 -0
  54. package/src/services/catalog/helpers/index.ts +4 -0
  55. package/src/services/catalog/helpers/product-fields.helper.ts +39 -0
  56. package/src/services/catalog/index.ts +7 -0
  57. package/src/services/catalog/models/category-with-tree.model.ts +7 -0
  58. package/src/services/catalog/models/index.ts +1 -0
  59. package/src/services/catalog/services/catalog-helpers.service.ts +35 -0
  60. package/src/services/catalog/services/catalog-operations.facade.ts +24 -0
  61. package/src/services/catalog/services/catalog-repository.service.ts +20 -0
  62. package/{services/catalog/services/index.d.ts → src/services/catalog/services/index.ts} +4 -4
  63. package/src/services/catalog/services/product-management.facade.ts +20 -0
  64. package/src/services/catalog/strategies/category-search.strategy.ts +168 -0
  65. package/src/services/catalog/strategies/index.ts +3 -0
  66. package/src/services/catalog/strategies/profile-search.strategy.ts +51 -0
  67. package/src/services/catalog/strategies/term-search.strategy.ts +163 -0
  68. package/src/services/catalog/strategies/types/strategy-params.type.ts +59 -0
  69. package/src/services/catalog/types/fetch-products-options.type.ts +10 -0
  70. package/src/services/catalog/types/fetch-products-params.type.ts +27 -0
  71. package/src/services/catalog/types/fetch-products-response.type.ts +11 -0
  72. package/src/services/catalog/types/index.ts +5 -0
  73. package/src/services/catalog/types/method-params.type.ts +21 -0
  74. package/src/services/catalog/types/product-sort.type.ts +3 -0
  75. package/src/services/catalog/wishlist.service.ts +364 -0
  76. package/src/services/checkout/checkout-dependencies.facade.ts +13 -0
  77. package/src/services/checkout/checkout-repositories.facade.ts +10 -0
  78. package/{services/checkout/index.d.ts → src/services/checkout/index.ts} +2 -2
  79. package/src/services/checkout-subscription.service.ts +76 -0
  80. package/src/services/checkout.service.ts +213 -0
  81. package/src/services/coupon/coupon-repositories.facade.ts +11 -0
  82. package/{services/coupon/index.d.ts → src/services/coupon/index.ts} +1 -1
  83. package/src/services/coupon/types/coupon-params.type.ts +15 -0
  84. package/src/services/coupon.service.ts +347 -0
  85. package/src/services/errors/group-invalid-coupon.error.ts +9 -0
  86. package/src/services/errors/index.ts +2 -0
  87. package/src/services/errors/invalid-coupon.error.ts +7 -0
  88. package/src/services/helpers/index.ts +1 -0
  89. package/src/services/helpers/util.helper.ts +17 -0
  90. package/src/services/home-shop/home-shop-repositories.facade.ts +11 -0
  91. package/{services/home-shop/index.d.ts → src/services/home-shop/index.ts} +1 -1
  92. package/src/services/home-shop.service.ts +210 -0
  93. package/src/services/index.ts +12 -0
  94. package/src/services/order-product-review.service.ts +135 -0
  95. package/src/services/order-recurrence.service.ts +115 -0
  96. package/src/services/order.service.ts +23 -0
  97. package/src/services/shared/configuration.facade.ts +21 -0
  98. package/src/services/shared/index.ts +1 -0
  99. package/src/services/types/index.ts +4 -0
  100. package/src/services/types/pending-product-review.type.ts +12 -0
  101. package/src/services/types/product-review-create.type.ts +15 -0
  102. package/src/services/types/required-checkout-data.type.ts +3 -0
  103. package/src/services/types/required-checkout-subscription-data.type.ts +3 -0
  104. package/src/types/firebase-app-config.type.ts +1 -0
  105. package/src/types/index.ts +1 -0
  106. package/tsconfig.json +17 -0
  107. package/tsconfig.lib.json +13 -0
  108. package/tsconfig.lib.prod.json +13 -0
  109. package/tsconfig.spec.json +17 -0
  110. package/angular-connect.module.d.ts +0 -36
  111. package/angular-elastic-search.module.d.ts +0 -9
  112. package/angular-firebase-auth.module.d.ts +0 -11
  113. package/angular-firestore.module.d.ts +0 -17
  114. package/angular-hasura-graphql.module.d.ts +0 -14
  115. package/angular-vertex-search.module.d.ts +0 -9
  116. package/consts/backend-url.const.d.ts +0 -1
  117. package/consts/category-structure.d.ts +0 -1
  118. package/consts/default-shop.const.d.ts +0 -1
  119. package/consts/es-config.const.d.ts +0 -1
  120. package/consts/firebase-const.d.ts +0 -4
  121. package/consts/hasura-options.const.d.ts +0 -1
  122. package/consts/index.d.ts +0 -8
  123. package/consts/persistence.const.d.ts +0 -1
  124. package/consts/storage-base-url.const.d.ts +0 -1
  125. package/consts/vertex-config.const.d.ts +0 -1
  126. package/esm2020/angular-connect.module.mjs +0 -293
  127. package/esm2020/angular-elastic-search.module.mjs +0 -34
  128. package/esm2020/angular-firebase-auth.module.mjs +0 -141
  129. package/esm2020/angular-firestore.module.mjs +0 -597
  130. package/esm2020/angular-hasura-graphql.module.mjs +0 -421
  131. package/esm2020/angular-vertex-search.module.mjs +0 -34
  132. package/esm2020/consts/backend-url.const.mjs +0 -2
  133. package/esm2020/consts/category-structure.mjs +0 -2
  134. package/esm2020/consts/default-shop.const.mjs +0 -2
  135. package/esm2020/consts/es-config.const.mjs +0 -2
  136. package/esm2020/consts/firebase-const.mjs +0 -5
  137. package/esm2020/consts/hasura-options.const.mjs +0 -2
  138. package/esm2020/consts/index.mjs +0 -9
  139. package/esm2020/consts/persistence.const.mjs +0 -2
  140. package/esm2020/consts/storage-base-url.const.mjs +0 -2
  141. package/esm2020/consts/vertex-config.const.mjs +0 -2
  142. package/esm2020/helpers/index.mjs +0 -2
  143. package/esm2020/helpers/mobile-operation-system-checker.helper.mjs +0 -7
  144. package/esm2020/index.mjs +0 -7
  145. package/esm2020/infrab4a-connect-angular.mjs +0 -5
  146. package/esm2020/interfaces/catalog-strategies.interface.mjs +0 -2
  147. package/esm2020/interfaces/category-facades.interface.mjs +0 -2
  148. package/esm2020/interfaces/index.mjs +0 -3
  149. package/esm2020/persistence/cookie-data-persistence.mjs +0 -22
  150. package/esm2020/persistence/data-persistence.mjs +0 -2
  151. package/esm2020/persistence/index.mjs +0 -3
  152. package/esm2020/services/auth.service.mjs +0 -37
  153. package/esm2020/services/cart/cart-services.facade.mjs +0 -21
  154. package/esm2020/services/cart/index.mjs +0 -2
  155. package/esm2020/services/cart.service.mjs +0 -73
  156. package/esm2020/services/catalog/adapters/category-structure.adapter.mjs +0 -2
  157. package/esm2020/services/catalog/adapters/index.mjs +0 -4
  158. package/esm2020/services/catalog/adapters/new-category-structure.adapter.mjs +0 -43
  159. package/esm2020/services/catalog/adapters/old-category-structure.adapter.mjs +0 -23
  160. package/esm2020/services/catalog/catalog.service.mjs +0 -111
  161. package/esm2020/services/catalog/category.service.mjs +0 -42
  162. package/esm2020/services/catalog/context/catalog-search.context.mjs +0 -40
  163. package/esm2020/services/catalog/enums/index.mjs +0 -2
  164. package/esm2020/services/catalog/enums/product-sorts.enum.mjs +0 -11
  165. package/esm2020/services/catalog/facades/catalog-service.facade.mjs +0 -32
  166. package/esm2020/services/catalog/facades/catalog-strategies.facade.mjs +0 -17
  167. package/esm2020/services/catalog/facades/category-repository.facade.mjs +0 -20
  168. package/esm2020/services/catalog/facades/category-service.facade.mjs +0 -30
  169. package/esm2020/services/catalog/facades/index.mjs +0 -6
  170. package/esm2020/services/catalog/facades/product-catalog.facade.mjs +0 -21
  171. package/esm2020/services/catalog/helpers/brand-manager.helper.mjs +0 -62
  172. package/esm2020/services/catalog/helpers/catalog-filter.helper.mjs +0 -44
  173. package/esm2020/services/catalog/helpers/catalog-sort.helper.mjs +0 -52
  174. package/esm2020/services/catalog/helpers/index.mjs +0 -5
  175. package/esm2020/services/catalog/helpers/product-fields.helper.mjs +0 -43
  176. package/esm2020/services/catalog/index.mjs +0 -8
  177. package/esm2020/services/catalog/models/category-with-tree.model.mjs +0 -10
  178. package/esm2020/services/catalog/models/index.mjs +0 -2
  179. package/esm2020/services/catalog/services/catalog-helpers.service.mjs +0 -33
  180. package/esm2020/services/catalog/services/catalog-operations.facade.mjs +0 -26
  181. package/esm2020/services/catalog/services/catalog-repository.service.mjs +0 -25
  182. package/esm2020/services/catalog/services/index.mjs +0 -5
  183. package/esm2020/services/catalog/services/product-management.facade.mjs +0 -25
  184. package/esm2020/services/catalog/strategies/category-search.strategy.mjs +0 -133
  185. package/esm2020/services/catalog/strategies/index.mjs +0 -4
  186. package/esm2020/services/catalog/strategies/profile-search.strategy.mjs +0 -42
  187. package/esm2020/services/catalog/strategies/term-search.strategy.mjs +0 -126
  188. package/esm2020/services/catalog/strategies/types/strategy-params.type.mjs +0 -2
  189. package/esm2020/services/catalog/types/fetch-products-options.type.mjs +0 -2
  190. package/esm2020/services/catalog/types/fetch-products-params.type.mjs +0 -2
  191. package/esm2020/services/catalog/types/fetch-products-response.type.mjs +0 -2
  192. package/esm2020/services/catalog/types/index.mjs +0 -6
  193. package/esm2020/services/catalog/types/method-params.type.mjs +0 -2
  194. package/esm2020/services/catalog/types/product-sort.type.mjs +0 -2
  195. package/esm2020/services/catalog/wishlist.service.mjs +0 -258
  196. package/esm2020/services/checkout/checkout-dependencies.facade.mjs +0 -20
  197. package/esm2020/services/checkout/checkout-repositories.facade.mjs +0 -20
  198. package/esm2020/services/checkout/index.mjs +0 -3
  199. package/esm2020/services/checkout-subscription.service.mjs +0 -55
  200. package/esm2020/services/checkout.service.mjs +0 -120
  201. package/esm2020/services/coupon/coupon-repositories.facade.mjs +0 -24
  202. package/esm2020/services/coupon/index.mjs +0 -2
  203. package/esm2020/services/coupon/types/coupon-params.type.mjs +0 -2
  204. package/esm2020/services/coupon.service.mjs +0 -248
  205. package/esm2020/services/helpers/index.mjs +0 -2
  206. package/esm2020/services/helpers/util.helper.mjs +0 -18
  207. package/esm2020/services/home-shop/home-shop-repositories.facade.mjs +0 -24
  208. package/esm2020/services/home-shop/index.mjs +0 -2
  209. package/esm2020/services/home-shop.service.mjs +0 -119
  210. package/esm2020/services/index.mjs +0 -12
  211. package/esm2020/services/order-product-review.service.mjs +0 -126
  212. package/esm2020/services/order-recurrence.service.mjs +0 -83
  213. package/esm2020/services/order.service.mjs +0 -30
  214. package/esm2020/services/shared/configuration.facade.mjs +0 -29
  215. package/esm2020/services/shared/index.mjs +0 -2
  216. package/esm2020/services/types/index.mjs +0 -5
  217. package/esm2020/services/types/pending-product-review.type.mjs +0 -2
  218. package/esm2020/services/types/product-review-create.type.mjs +0 -2
  219. package/esm2020/services/types/required-checkout-data.type.mjs +0 -2
  220. package/esm2020/services/types/required-checkout-subscription-data.type.mjs +0 -2
  221. package/esm2020/types/firebase-app-config.type.mjs +0 -2
  222. package/esm2020/types/index.mjs +0 -2
  223. package/fesm2015/infrab4a-connect-angular.mjs +0 -3746
  224. package/fesm2015/infrab4a-connect-angular.mjs.map +0 -1
  225. package/fesm2020/infrab4a-connect-angular.mjs +0 -3648
  226. package/fesm2020/infrab4a-connect-angular.mjs.map +0 -1
  227. package/helpers/index.d.ts +0 -1
  228. package/helpers/mobile-operation-system-checker.helper.d.ts +0 -3
  229. package/index.d.ts +0 -6
  230. package/interfaces/catalog-strategies.interface.d.ts +0 -31
  231. package/interfaces/category-facades.interface.d.ts +0 -6
  232. package/interfaces/index.d.ts +0 -2
  233. package/persistence/cookie-data-persistence.d.ts +0 -10
  234. package/persistence/data-persistence.d.ts +0 -6
  235. package/persistence/index.d.ts +0 -2
  236. package/services/auth.service.d.ts +0 -18
  237. package/services/cart/cart-services.facade.d.ts +0 -12
  238. package/services/cart/index.d.ts +0 -1
  239. package/services/cart.service.d.ts +0 -26
  240. package/services/catalog/adapters/category-structure.adapter.d.ts +0 -4
  241. package/services/catalog/adapters/index.d.ts +0 -3
  242. package/services/catalog/adapters/new-category-structure.adapter.d.ts +0 -12
  243. package/services/catalog/adapters/old-category-structure.adapter.d.ts +0 -10
  244. package/services/catalog/catalog.service.d.ts +0 -24
  245. package/services/catalog/category.service.d.ts +0 -23
  246. package/services/catalog/context/catalog-search.context.d.ts +0 -14
  247. package/services/catalog/enums/index.d.ts +0 -1
  248. package/services/catalog/enums/product-sorts.enum.d.ts +0 -9
  249. package/services/catalog/facades/catalog-service.facade.d.ts +0 -15
  250. package/services/catalog/facades/catalog-strategies.facade.d.ts +0 -10
  251. package/services/catalog/facades/category-repository.facade.d.ts +0 -9
  252. package/services/catalog/facades/category-service.facade.d.ts +0 -15
  253. package/services/catalog/facades/product-catalog.facade.d.ts +0 -10
  254. package/services/catalog/helpers/brand-manager.helper.d.ts +0 -14
  255. package/services/catalog/helpers/catalog-filter.helper.d.ts +0 -8
  256. package/services/catalog/helpers/catalog-sort.helper.d.ts +0 -7
  257. package/services/catalog/helpers/index.d.ts +0 -4
  258. package/services/catalog/helpers/product-fields.helper.d.ts +0 -7
  259. package/services/catalog/index.d.ts +0 -7
  260. package/services/catalog/models/category-with-tree.model.d.ts +0 -4
  261. package/services/catalog/models/index.d.ts +0 -1
  262. package/services/catalog/services/catalog-helpers.service.d.ts +0 -17
  263. package/services/catalog/services/catalog-operations.facade.d.ts +0 -13
  264. package/services/catalog/services/catalog-repository.service.d.ts +0 -12
  265. package/services/catalog/services/product-management.facade.d.ts +0 -12
  266. package/services/catalog/strategies/category-search.strategy.d.ts +0 -19
  267. package/services/catalog/strategies/index.d.ts +0 -3
  268. package/services/catalog/strategies/profile-search.strategy.d.ts +0 -14
  269. package/services/catalog/strategies/term-search.strategy.d.ts +0 -20
  270. package/services/catalog/strategies/types/strategy-params.type.d.ts +0 -59
  271. package/services/catalog/types/fetch-products-options.type.d.ts +0 -8
  272. package/services/catalog/types/fetch-products-params.type.d.ts +0 -25
  273. package/services/catalog/types/fetch-products-response.type.d.ts +0 -19
  274. package/services/catalog/types/index.d.ts +0 -5
  275. package/services/catalog/types/method-params.type.d.ts +0 -17
  276. package/services/catalog/types/product-sort.type.d.ts +0 -2
  277. package/services/catalog/wishlist.service.d.ts +0 -60
  278. package/services/checkout/checkout-dependencies.facade.d.ts +0 -10
  279. package/services/checkout/checkout-repositories.facade.d.ts +0 -9
  280. package/services/checkout-subscription.service.d.ts +0 -19
  281. package/services/checkout.service.d.ts +0 -31
  282. package/services/coupon/coupon-repositories.facade.d.ts +0 -10
  283. package/services/coupon/types/coupon-params.type.d.ts +0 -13
  284. package/services/coupon.service.d.ts +0 -36
  285. package/services/helpers/index.d.ts +0 -1
  286. package/services/helpers/util.helper.d.ts +0 -3
  287. package/services/home-shop/home-shop-repositories.facade.d.ts +0 -10
  288. package/services/home-shop.service.d.ts +0 -26
  289. package/services/index.d.ts +0 -11
  290. package/services/order-product-review.service.d.ts +0 -18
  291. package/services/order-recurrence.service.d.ts +0 -37
  292. package/services/order.service.d.ts +0 -13
  293. package/services/shared/configuration.facade.d.ts +0 -12
  294. package/services/shared/index.d.ts +0 -1
  295. package/services/types/index.d.ts +0 -4
  296. package/services/types/pending-product-review.type.d.ts +0 -12
  297. package/services/types/product-review-create.type.d.ts +0 -14
  298. package/services/types/required-checkout-data.type.d.ts +0 -2
  299. package/services/types/required-checkout-subscription-data.type.d.ts +0 -2
  300. package/types/firebase-app-config.type.d.ts +0 -1
  301. 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'