@infrab4a/connect 4.0.0-beta.9 → 4.0.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.
Files changed (302) hide show
  1. package/domain/catalog/helpers/index.d.ts +1 -0
  2. package/domain/catalog/helpers/round-product-price.helper.d.ts +4 -0
  3. package/domain/catalog/index.d.ts +1 -0
  4. package/domain/catalog/models/category-base.d.ts +30 -0
  5. package/domain/catalog/models/category-collection-children.d.ts +13 -0
  6. package/domain/catalog/models/category-filter.d.ts +13 -0
  7. package/domain/catalog/models/category-for-product.d.ts +5 -0
  8. package/domain/catalog/models/category.d.ts +5 -22
  9. package/domain/catalog/models/filter-option.d.ts +9 -0
  10. package/domain/catalog/models/filter.d.ts +12 -0
  11. package/domain/catalog/models/index.d.ts +5 -0
  12. package/domain/catalog/models/kit-product.d.ts +4 -4
  13. package/domain/catalog/models/product-base.d.ts +40 -0
  14. package/domain/catalog/models/product-for-category.d.ts +7 -0
  15. package/domain/catalog/models/product-for-kit.d.ts +7 -0
  16. package/domain/catalog/models/product.d.ts +5 -35
  17. package/domain/catalog/models/types/category-product.d.ts +4 -0
  18. package/domain/catalog/models/types/index.d.ts +2 -1
  19. package/domain/catalog/models/types/product-evaluation.type.d.ts +6 -0
  20. package/domain/catalog/models/types/shop-description.type.d.ts +1 -0
  21. package/domain/catalog/models/variant.d.ts +1 -2
  22. package/domain/catalog/models/wishlist.d.ts +6 -0
  23. package/domain/catalog/repositories/category-collection-children.repository.d.ts +4 -0
  24. package/domain/catalog/repositories/category-filter.repository.d.ts +6 -0
  25. package/domain/catalog/repositories/category.repository.d.ts +6 -3
  26. package/domain/catalog/repositories/filter-option.repository.d.ts +4 -0
  27. package/domain/catalog/repositories/filter.repository.d.ts +4 -0
  28. package/domain/catalog/repositories/index.d.ts +5 -0
  29. package/domain/catalog/repositories/product.repository.d.ts +4 -1
  30. package/domain/catalog/repositories/wishlist.repository.d.ts +6 -0
  31. package/domain/generic/model/base.model.d.ts +9 -5
  32. package/domain/generic/model/types/base-model-builder.type.d.ts +4 -2
  33. package/domain/generic/model/types/identifier-model.type.d.ts +6 -5
  34. package/domain/generic/model/types/model-base-structure.type.d.ts +9 -3
  35. package/domain/generic/model/types/non-function-property-name.type.d.ts +12 -3
  36. package/domain/generic/repository/find.repository.d.ts +7 -1
  37. package/domain/generic/repository/get.repository.d.ts +2 -2
  38. package/domain/generic/repository/types/repository-find-filters.type.d.ts +3 -3
  39. package/domain/generic/repository/types/repository-find-result.type.d.ts +11 -1
  40. package/domain/generic/repository/types/repository-order-by-list.type.d.ts +2 -2
  41. package/domain/generic/repository/types/repository-update-params.type.d.ts +2 -2
  42. package/domain/location/models/address.d.ts +5 -3
  43. package/domain/shop-settings/models/index.d.ts +1 -0
  44. package/domain/shop-settings/models/shop-settings.d.ts +9 -0
  45. package/domain/shop-settings/models/types/index.d.ts +6 -1
  46. package/domain/shop-settings/models/types/shop-banner.type.d.ts +12 -0
  47. package/domain/shop-settings/models/types/shop-brands.type.d.ts +10 -0
  48. package/domain/shop-settings/models/types/shop-carousel.type.d.ts +5 -0
  49. package/domain/shop-settings/models/types/shop-collection.type.d.ts +9 -0
  50. package/domain/shop-settings/models/types/shop-section.type.d.ts +9 -0
  51. package/domain/shop-settings/repositories/index.d.ts +1 -0
  52. package/domain/shop-settings/repositories/shop-settings.repository.d.ts +4 -0
  53. package/domain/shopping/models/buy-2-win.d.ts +3 -1
  54. package/domain/shopping/models/campaign-dashboard.d.ts +15 -0
  55. package/domain/shopping/models/campaign-hashtag.d.ts +18 -0
  56. package/domain/shopping/models/checkout.d.ts +5 -6
  57. package/domain/shopping/models/coupons/coupon.d.ts +34 -6
  58. package/domain/shopping/models/index.d.ts +5 -4
  59. package/domain/shopping/models/order.d.ts +1 -0
  60. package/domain/shopping/models/shipping-method.d.ts +1 -0
  61. package/domain/shopping/models/subscription/checkout.d.ts +3 -4
  62. package/domain/shopping/repositories/campaign-dashboard.repository.d.ts +4 -0
  63. package/domain/shopping/repositories/campaign-hashtag.repository.d.ts +4 -0
  64. package/domain/shopping/repositories/index.d.ts +4 -2
  65. package/domain/users/models/lead.d.ts +1 -0
  66. package/domain/users/models/subscription/subscription.d.ts +3 -3
  67. package/domain/users/models/user-address.d.ts +1 -2
  68. package/domain/users/models/user.d.ts +2 -3
  69. package/esm2020/domain/catalog/helpers/index.mjs +2 -0
  70. package/esm2020/domain/catalog/helpers/round-product-price.helper.mjs +15 -0
  71. package/esm2020/domain/catalog/index.mjs +2 -1
  72. package/esm2020/domain/catalog/models/category-base.mjs +18 -0
  73. package/esm2020/domain/catalog/models/category-collection-children.mjs +13 -0
  74. package/esm2020/domain/catalog/models/category-filter.mjs +19 -0
  75. package/esm2020/domain/catalog/models/category-for-product.mjs +7 -0
  76. package/esm2020/domain/catalog/models/category.mjs +10 -6
  77. package/esm2020/domain/catalog/models/filter-option.mjs +7 -0
  78. package/esm2020/domain/catalog/models/filter.mjs +7 -0
  79. package/esm2020/domain/catalog/models/index.mjs +6 -1
  80. package/esm2020/domain/catalog/models/kit-product.mjs +7 -7
  81. package/esm2020/domain/catalog/models/product-base.mjs +25 -0
  82. package/esm2020/domain/catalog/models/product-for-category.mjs +14 -0
  83. package/esm2020/domain/catalog/models/product-for-kit.mjs +14 -0
  84. package/esm2020/domain/catalog/models/product.mjs +8 -6
  85. package/esm2020/domain/catalog/models/types/category-product.mjs +2 -0
  86. package/esm2020/domain/catalog/models/types/index.mjs +3 -2
  87. package/esm2020/domain/catalog/models/types/product-evaluation.type.mjs +2 -0
  88. package/esm2020/domain/catalog/models/types/shop-description.type.mjs +1 -1
  89. package/esm2020/domain/catalog/models/variant.mjs +1 -4
  90. package/esm2020/domain/catalog/models/wishlist.mjs +7 -0
  91. package/esm2020/domain/catalog/repositories/category-collection-children.repository.mjs +2 -0
  92. package/esm2020/domain/catalog/repositories/category-filter.repository.mjs +2 -0
  93. package/esm2020/domain/catalog/repositories/category.repository.mjs +1 -1
  94. package/esm2020/domain/catalog/repositories/filter-option.repository.mjs +2 -0
  95. package/esm2020/domain/catalog/repositories/filter.repository.mjs +2 -0
  96. package/esm2020/domain/catalog/repositories/index.mjs +6 -1
  97. package/esm2020/domain/catalog/repositories/product.repository.mjs +1 -1
  98. package/esm2020/domain/catalog/repositories/wishlist.repository.mjs +2 -0
  99. package/esm2020/domain/generic/model/base.model.mjs +3 -2
  100. package/esm2020/domain/generic/model/types/base-model-builder.type.mjs +1 -1
  101. package/esm2020/domain/generic/model/types/identifier-model.type.mjs +1 -1
  102. package/esm2020/domain/generic/model/types/model-base-structure.type.mjs +1 -1
  103. package/esm2020/domain/generic/model/types/non-function-property-name.type.mjs +1 -1
  104. package/esm2020/domain/generic/repository/find.repository.mjs +1 -1
  105. package/esm2020/domain/generic/repository/get.repository.mjs +1 -1
  106. package/esm2020/domain/generic/repository/types/repository-find-filters.type.mjs +1 -1
  107. package/esm2020/domain/generic/repository/types/repository-find-result.type.mjs +1 -1
  108. package/esm2020/domain/generic/repository/types/repository-order-by-list.type.mjs +1 -1
  109. package/esm2020/domain/generic/repository/types/repository-update-params.type.mjs +1 -1
  110. package/esm2020/domain/location/models/address.mjs +2 -2
  111. package/esm2020/domain/shop-settings/models/index.mjs +2 -1
  112. package/esm2020/domain/shop-settings/models/shop-settings.mjs +7 -0
  113. package/esm2020/domain/shop-settings/models/types/index.mjs +7 -2
  114. package/esm2020/domain/shop-settings/models/types/shop-banner.type.mjs +2 -0
  115. package/esm2020/domain/shop-settings/models/types/shop-brands.type.mjs +2 -0
  116. package/esm2020/domain/shop-settings/models/types/shop-carousel.type.mjs +2 -0
  117. package/esm2020/domain/shop-settings/models/types/shop-collection.type.mjs +2 -0
  118. package/esm2020/domain/shop-settings/models/types/shop-section.type.mjs +2 -0
  119. package/esm2020/domain/shop-settings/repositories/index.mjs +2 -1
  120. package/esm2020/domain/shop-settings/repositories/shop-settings.repository.mjs +2 -0
  121. package/esm2020/domain/shopping/models/buy-2-win.mjs +2 -2
  122. package/esm2020/domain/shopping/models/campaign-dashboard.mjs +7 -0
  123. package/esm2020/domain/shopping/models/campaign-hashtag.mjs +7 -0
  124. package/esm2020/domain/shopping/models/checkout.mjs +6 -7
  125. package/esm2020/domain/shopping/models/coupons/coupon.mjs +16 -16
  126. package/esm2020/domain/shopping/models/index.mjs +6 -5
  127. package/esm2020/domain/shopping/models/order.mjs +1 -1
  128. package/esm2020/domain/shopping/models/shipping-method.mjs +1 -1
  129. package/esm2020/domain/shopping/models/subscription/checkout.mjs +6 -6
  130. package/esm2020/domain/shopping/repositories/campaign-dashboard.repository.mjs +2 -0
  131. package/esm2020/domain/shopping/repositories/campaign-hashtag.repository.mjs +2 -0
  132. package/esm2020/domain/shopping/repositories/index.mjs +5 -3
  133. package/esm2020/domain/users/models/lead.mjs +1 -1
  134. package/esm2020/domain/users/models/subscription/subscription.mjs +6 -6
  135. package/esm2020/domain/users/models/user-address.mjs +1 -1
  136. package/esm2020/domain/users/models/user.mjs +2 -2
  137. package/esm2020/domain/users/use-cases/authentication.mjs +2 -2
  138. package/esm2020/infra/elasticsearch/adapters/axios.adapter.mjs +28 -11
  139. package/esm2020/infra/elasticsearch/adapters/elastic-search.adapter.mjs +1 -1
  140. package/esm2020/infra/elasticsearch/indexes/products-index.mjs +63 -51
  141. package/esm2020/infra/elasticsearch/types/elastic-search-result.mjs +1 -1
  142. package/esm2020/infra/firebase/firestore/mixins/with-create-firestore.mixin.mjs +8 -4
  143. package/esm2020/infra/firebase/firestore/mixins/with-crud-firestore.mixin.mjs +1 -1
  144. package/esm2020/infra/firebase/firestore/mixins/with-delete-firestore.mixin.mjs +6 -2
  145. package/esm2020/infra/firebase/firestore/mixins/with-find-firestore.mixin.mjs +11 -8
  146. package/esm2020/infra/firebase/firestore/mixins/with-firestore.mixin.mjs +27 -4
  147. package/esm2020/infra/firebase/firestore/mixins/with-get-firestore.mixin.mjs +6 -3
  148. package/esm2020/infra/firebase/firestore/mixins/with-helpers.mixin.mjs +1 -1
  149. package/esm2020/infra/firebase/firestore/mixins/with-sub-collection.mixin.mjs +5 -3
  150. package/esm2020/infra/firebase/firestore/mixins/with-update-firestore.mixin.mjs +7 -4
  151. package/esm2020/infra/firebase/firestore/repositories/catalog/category-firestore.repository.mjs +21 -8
  152. package/esm2020/infra/firebase/firestore/repositories/catalog/product-firestore.repository.mjs +15 -7
  153. package/esm2020/infra/firebase/firestore/repositories/catalog/product-variant-firestore.repository.mjs +10 -8
  154. package/esm2020/infra/firebase/firestore/repositories/catalog/subscription-product-firestore.repository.mjs +8 -6
  155. package/esm2020/infra/firebase/firestore/repositories/shop-settings/home-firestore.repository.mjs +36 -30
  156. package/esm2020/infra/firebase/firestore/repositories/shop-settings/index.mjs +2 -1
  157. package/esm2020/infra/firebase/firestore/repositories/shop-settings/shop-menu-firestore.repository.mjs +8 -6
  158. package/esm2020/infra/firebase/firestore/repositories/shop-settings/shop-settings-firestore.repository.mjs +14 -0
  159. package/esm2020/infra/firebase/firestore/repositories/shopping/buy-2-win-firestore.repository.mjs +8 -6
  160. package/esm2020/infra/firebase/firestore/repositories/shopping/campaign-dashboard-firestore.repository.mjs +14 -0
  161. package/esm2020/infra/firebase/firestore/repositories/shopping/campaign-hashtag-firestore.repository.mjs +14 -0
  162. package/esm2020/infra/firebase/firestore/repositories/shopping/checkout-firestore.repository.mjs +8 -6
  163. package/esm2020/infra/firebase/firestore/repositories/shopping/checkout-subscription-firestore.repository.mjs +8 -6
  164. package/esm2020/infra/firebase/firestore/repositories/shopping/coupon-firestore.repository.mjs +8 -6
  165. package/esm2020/infra/firebase/firestore/repositories/shopping/index.mjs +6 -4
  166. package/esm2020/infra/firebase/firestore/repositories/shopping/legacy-order-firestore.repository.mjs +6 -4
  167. package/esm2020/infra/firebase/firestore/repositories/shopping/order-firestore.repository.mjs +11 -9
  168. package/esm2020/infra/firebase/firestore/repositories/shopping/payment-firestore.repository.mjs +8 -6
  169. package/esm2020/infra/firebase/firestore/repositories/shopping/subscription-plan-firestore.repository.mjs +8 -6
  170. package/esm2020/infra/firebase/firestore/repositories/users/lead-firestore.repository.mjs +8 -6
  171. package/esm2020/infra/firebase/firestore/repositories/users/subscription-edition-firestore.repository.mjs +10 -8
  172. package/esm2020/infra/firebase/firestore/repositories/users/subscription-firestore.repository.mjs +8 -6
  173. package/esm2020/infra/firebase/firestore/repositories/users/subscription-payment-firestore.repository.mjs +10 -8
  174. package/esm2020/infra/firebase/firestore/repositories/users/user-address-firestore.repository.mjs +10 -8
  175. package/esm2020/infra/firebase/firestore/repositories/users/user-beauty-profile-firestore.repository.mjs +10 -8
  176. package/esm2020/infra/firebase/firestore/repositories/users/user-firestore.repository.mjs +8 -6
  177. package/esm2020/infra/firebase/firestore/repositories/users/user-payment-method-firestore.repository.mjs +10 -8
  178. package/esm2020/infra/firebase/firestore/types/firestore-interceptors.type.mjs +2 -0
  179. package/esm2020/infra/firebase/firestore/types/firestore-sub.repository.type.mjs +1 -1
  180. package/esm2020/infra/firebase/firestore/types/firestore.helpers.type.mjs +1 -1
  181. package/esm2020/infra/firebase/firestore/types/firestore.repository.type.mjs +1 -1
  182. package/esm2020/infra/firebase/firestore/types/index.mjs +4 -3
  183. package/esm2020/infra/hasura-graphql/mixins/helpers/attribute-option.helper.mjs +3 -3
  184. package/esm2020/infra/hasura-graphql/mixins/helpers/bind-filter-query.helper.mjs +6 -5
  185. package/esm2020/infra/hasura-graphql/mixins/helpers/filter-option.helper.mjs +1 -1
  186. package/esm2020/infra/hasura-graphql/mixins/helpers/graphql-field.helper.mjs +36 -25
  187. package/esm2020/infra/hasura-graphql/mixins/with-create-hasura-graphql.mixin.mjs +6 -4
  188. package/esm2020/infra/hasura-graphql/mixins/with-crud-hasura-graphql.mixin.mjs +1 -1
  189. package/esm2020/infra/hasura-graphql/mixins/with-delete-hasura-graphql.mixin.mjs +5 -3
  190. package/esm2020/infra/hasura-graphql/mixins/with-find-hasura-graphql.mixin.mjs +126 -20
  191. package/esm2020/infra/hasura-graphql/mixins/with-get-hasura-graphql.mixin.mjs +5 -3
  192. package/esm2020/infra/hasura-graphql/mixins/with-hasura-graphql.mixin.mjs +40 -22
  193. package/esm2020/infra/hasura-graphql/mixins/with-update-hasura-graphql.mixin.mjs +7 -5
  194. package/esm2020/infra/hasura-graphql/models/product-hasura-graphql.mjs +1 -1
  195. package/esm2020/infra/hasura-graphql/models/variant-hasura-graphql.mjs +1 -1
  196. package/esm2020/infra/hasura-graphql/repositories/catalog/category-collection-children-hasura-graphql.repository.mjs +39 -0
  197. package/esm2020/infra/hasura-graphql/repositories/catalog/category-filter-hasura-graphql.repository.mjs +107 -0
  198. package/esm2020/infra/hasura-graphql/repositories/catalog/category-hasura-graphql.repository.mjs +130 -14
  199. package/esm2020/infra/hasura-graphql/repositories/catalog/filter-hasura-graphql.repository.mjs +105 -0
  200. package/esm2020/infra/hasura-graphql/repositories/catalog/filter-option-hasura-graphql.repository.mjs +22 -0
  201. package/esm2020/infra/hasura-graphql/repositories/catalog/index.mjs +6 -1
  202. package/esm2020/infra/hasura-graphql/repositories/catalog/product-hasura-graphql.repository.mjs +68 -19
  203. package/esm2020/infra/hasura-graphql/repositories/catalog/variant-hasura-graphql.repository.mjs +4 -3
  204. package/esm2020/infra/hasura-graphql/repositories/catalog/wishlist-hasura-graphql.repository.mjs +236 -0
  205. package/esm2020/infra/hasura-graphql/types/graphql.repository.type.mjs +1 -1
  206. package/esm2020/infra/hasura-graphql/types/hasura-graphql-fields.type.mjs +1 -1
  207. package/esm2020/utils/decorators/debug.class.decorator.mjs +7 -0
  208. package/esm2020/utils/decorators/index.mjs +3 -0
  209. package/esm2020/utils/decorators/trace.method.decorator.mjs +81 -0
  210. package/esm2020/utils/helpers/class-name.helper.mjs +15 -0
  211. package/esm2020/utils/helpers/debug-decorator.helper.mjs +18 -0
  212. package/esm2020/utils/helpers/debug.helper.mjs +150 -0
  213. package/esm2020/utils/helpers/index.mjs +5 -0
  214. package/esm2020/utils/helpers/reflect.helper.mjs +165 -0
  215. package/esm2020/utils/index.mjs +6 -3
  216. package/esm2020/utils/log.utils.mjs +9 -0
  217. package/fesm2015/infrab4a-connect.mjs +2022 -444
  218. package/fesm2015/infrab4a-connect.mjs.map +1 -1
  219. package/fesm2020/infrab4a-connect.mjs +2004 -461
  220. package/fesm2020/infrab4a-connect.mjs.map +1 -1
  221. package/infra/elasticsearch/adapters/axios.adapter.d.ts +7 -5
  222. package/infra/elasticsearch/adapters/elastic-search.adapter.d.ts +3 -2
  223. package/infra/elasticsearch/indexes/products-index.d.ts +8 -10
  224. package/infra/elasticsearch/types/elastic-search-result.d.ts +2 -0
  225. package/infra/firebase/firestore/mixins/with-create-firestore.mixin.d.ts +2 -2
  226. package/infra/firebase/firestore/mixins/with-crud-firestore.mixin.d.ts +2 -1
  227. package/infra/firebase/firestore/mixins/with-delete-firestore.mixin.d.ts +2 -2
  228. package/infra/firebase/firestore/mixins/with-find-firestore.mixin.d.ts +2 -2
  229. package/infra/firebase/firestore/mixins/with-firestore.mixin.d.ts +13 -4
  230. package/infra/firebase/firestore/mixins/with-get-firestore.mixin.d.ts +2 -2
  231. package/infra/firebase/firestore/mixins/with-helpers.mixin.d.ts +2 -2
  232. package/infra/firebase/firestore/mixins/with-sub-collection.mixin.d.ts +8 -4
  233. package/infra/firebase/firestore/mixins/with-update-firestore.mixin.d.ts +3 -3
  234. package/infra/firebase/firestore/repositories/catalog/category-firestore.repository.d.ts +8 -5
  235. package/infra/firebase/firestore/repositories/catalog/product-firestore.repository.d.ts +6 -5
  236. package/infra/firebase/firestore/repositories/catalog/product-variant-firestore.repository.d.ts +3 -4
  237. package/infra/firebase/firestore/repositories/catalog/subscription-product-firestore.repository.d.ts +3 -4
  238. package/infra/firebase/firestore/repositories/shop-settings/home-firestore.repository.d.ts +4 -4
  239. package/infra/firebase/firestore/repositories/shop-settings/index.d.ts +1 -0
  240. package/infra/firebase/firestore/repositories/shop-settings/shop-menu-firestore.repository.d.ts +3 -4
  241. package/infra/firebase/firestore/repositories/shop-settings/shop-settings-firestore.repository.d.ts +7 -0
  242. package/infra/firebase/firestore/repositories/shopping/buy-2-win-firestore.repository.d.ts +3 -4
  243. package/infra/firebase/firestore/repositories/shopping/campaign-dashboard-firestore.repository.d.ts +8 -0
  244. package/infra/firebase/firestore/repositories/shopping/campaign-hashtag-firestore.repository.d.ts +8 -0
  245. package/infra/firebase/firestore/repositories/shopping/checkout-firestore.repository.d.ts +3 -4
  246. package/infra/firebase/firestore/repositories/shopping/checkout-subscription-firestore.repository.d.ts +3 -4
  247. package/infra/firebase/firestore/repositories/shopping/coupon-firestore.repository.d.ts +4 -4
  248. package/infra/firebase/firestore/repositories/shopping/index.d.ts +5 -3
  249. package/infra/firebase/firestore/repositories/shopping/legacy-order-firestore.repository.d.ts +3 -4
  250. package/infra/firebase/firestore/repositories/shopping/order-firestore.repository.d.ts +4 -4
  251. package/infra/firebase/firestore/repositories/shopping/payment-firestore.repository.d.ts +3 -4
  252. package/infra/firebase/firestore/repositories/shopping/subscription-plan-firestore.repository.d.ts +3 -4
  253. package/infra/firebase/firestore/repositories/users/lead-firestore.repository.d.ts +3 -4
  254. package/infra/firebase/firestore/repositories/users/subscription-edition-firestore.repository.d.ts +3 -4
  255. package/infra/firebase/firestore/repositories/users/subscription-firestore.repository.d.ts +3 -4
  256. package/infra/firebase/firestore/repositories/users/subscription-payment-firestore.repository.d.ts +3 -4
  257. package/infra/firebase/firestore/repositories/users/user-address-firestore.repository.d.ts +3 -4
  258. package/infra/firebase/firestore/repositories/users/user-beauty-profile-firestore.repository.d.ts +3 -4
  259. package/infra/firebase/firestore/repositories/users/user-firestore.repository.d.ts +4 -4
  260. package/infra/firebase/firestore/repositories/users/user-payment-method-firestore.repository.d.ts +3 -4
  261. package/infra/firebase/firestore/types/firestore-interceptors.type.d.ts +14 -0
  262. package/infra/firebase/firestore/types/firestore-sub.repository.type.d.ts +3 -3
  263. package/infra/firebase/firestore/types/firestore.helpers.type.d.ts +5 -5
  264. package/infra/firebase/firestore/types/firestore.repository.type.d.ts +3 -1
  265. package/infra/firebase/firestore/types/index.d.ts +3 -2
  266. package/infra/hasura-graphql/mixins/helpers/attribute-option.helper.d.ts +9 -3
  267. package/infra/hasura-graphql/mixins/helpers/bind-filter-query.helper.d.ts +5 -5
  268. package/infra/hasura-graphql/mixins/helpers/filter-option.helper.d.ts +4 -2
  269. package/infra/hasura-graphql/mixins/helpers/graphql-field.helper.d.ts +9 -5
  270. package/infra/hasura-graphql/mixins/with-create-hasura-graphql.mixin.d.ts +2 -1
  271. package/infra/hasura-graphql/mixins/with-crud-hasura-graphql.mixin.d.ts +3 -3
  272. package/infra/hasura-graphql/mixins/with-delete-hasura-graphql.mixin.d.ts +1 -1
  273. package/infra/hasura-graphql/mixins/with-find-hasura-graphql.mixin.d.ts +24 -15
  274. package/infra/hasura-graphql/mixins/with-get-hasura-graphql.mixin.d.ts +7 -6
  275. package/infra/hasura-graphql/mixins/with-hasura-graphql.mixin.d.ts +15 -7
  276. package/infra/hasura-graphql/mixins/with-update-hasura-graphql.mixin.d.ts +2 -2
  277. package/infra/hasura-graphql/models/product-hasura-graphql.d.ts +4 -0
  278. package/infra/hasura-graphql/models/variant-hasura-graphql.d.ts +1 -0
  279. package/infra/hasura-graphql/repositories/catalog/category-collection-children-hasura-graphql.repository.d.ts +10 -0
  280. package/infra/hasura-graphql/repositories/catalog/category-filter-hasura-graphql.repository.d.ts +12 -0
  281. package/infra/hasura-graphql/repositories/catalog/category-hasura-graphql.repository.d.ts +11 -4
  282. package/infra/hasura-graphql/repositories/catalog/filter-hasura-graphql.repository.d.ts +18 -0
  283. package/infra/hasura-graphql/repositories/catalog/filter-option-hasura-graphql.repository.d.ts +10 -0
  284. package/infra/hasura-graphql/repositories/catalog/index.d.ts +5 -0
  285. package/infra/hasura-graphql/repositories/catalog/product-hasura-graphql.repository.d.ts +6 -4
  286. package/infra/hasura-graphql/repositories/catalog/variant-hasura-graphql.repository.d.ts +3 -3
  287. package/infra/hasura-graphql/repositories/catalog/wishlist-hasura-graphql.repository.d.ts +27 -0
  288. package/infra/hasura-graphql/types/graphql.repository.type.d.ts +9 -6
  289. package/infra/hasura-graphql/types/hasura-graphql-fields.type.d.ts +7 -3
  290. package/package.json +2 -1
  291. package/utils/decorators/debug.class.decorator.d.ts +2 -0
  292. package/utils/decorators/index.d.ts +2 -0
  293. package/utils/decorators/trace.method.decorator.d.ts +14 -0
  294. package/utils/helpers/class-name.helper.d.ts +3 -0
  295. package/utils/helpers/debug-decorator.helper.d.ts +9 -0
  296. package/utils/helpers/debug.helper.d.ts +60 -0
  297. package/utils/helpers/index.d.ts +4 -0
  298. package/utils/helpers/reflect.helper.d.ts +50 -0
  299. package/utils/index.d.ts +5 -2
  300. package/utils/log.utils.d.ts +7 -0
  301. package/domain/catalog/models/types/category-filter.type.d.ts +0 -4
  302. package/esm2020/domain/catalog/models/types/category-filter.type.mjs +0 -2
@@ -3,8 +3,10 @@ import { plainToInstance, instanceToPlain, Expose, Type } from 'class-transforme
3
3
  import { __decorate, __metadata } from 'tslib';
4
4
  import { parseISO } from 'date-fns';
5
5
  export { add, addBusinessDays, addDays, addMonths, addYears, endOfDay, format, formatISO9075, parseISO, startOfDay, sub } from 'date-fns';
6
- import { get as get$1, isString, isNil, isNumber, isDate, set, isObject, isEmpty, chunk, isBoolean, isInteger, isNaN as isNaN$1, omit } from 'lodash';
7
- export { chunk, isBoolean, isDate, isEmpty, isInteger, isNaN, isNil, isNumber, isObject, isString, now, omit, pick, set } from 'lodash';
6
+ import { isNil, isArray, first, last, flatten, compact, get as get$1, isString, each, unset, isObject, isNumber, isDate, set, isEmpty, chunk, isBoolean, isInteger, isNaN as isNaN$1, omit } from 'lodash';
7
+ export { chunk, each, get, isBoolean, isDate, isEmpty, isInteger, isNaN, isNil, isNumber, isObject, isString, now, omit, pick, set, unset } from 'lodash';
8
+ import { Subject } from 'rxjs';
9
+ import { debug } from 'debug';
8
10
  import { CustomError } from 'ts-custom-error';
9
11
  import axios from 'axios';
10
12
  import { collection, getDoc, doc, where, orderBy, getDocs, query, startAfter, startAt, limit, addDoc, setDoc, deleteField, arrayUnion, arrayRemove, deleteDoc, Timestamp } from 'firebase/firestore';
@@ -14,7 +16,8 @@ import { mutation, query as query$1 } from 'gql-query-builder';
14
16
  class BaseModel {
15
17
  get identifier() {
16
18
  const fields = this.constructor.identifiersFields.filter((field) => field !== 'identifier');
17
- return fields.reduce((object, field) => ({ ...object, [field]: this[field] }), {});
19
+ const data = this;
20
+ return fields.reduce((object, field) => ({ ...object, [field]: data[field] }), {});
18
21
  }
19
22
  get identifiersFields() {
20
23
  return this.constructor.identifiersFields;
@@ -460,12 +463,438 @@ __decorate([
460
463
  __metadata("design:type", Payment)
461
464
  ], SubscriptionPayment.prototype, "payment", void 0);
462
465
 
463
- class Address extends BaseModel {
464
- static get identifiersFields() {
465
- return ['id'];
466
+ var DebugNamespaces;
467
+ (function (DebugNamespaces) {
468
+ DebugNamespaces["ROOT"] = "connect";
469
+ DebugNamespaces["TRACE"] = "trace";
470
+ DebugNamespaces["ERROR"] = "error";
471
+ })(DebugNamespaces || (DebugNamespaces = {}));
472
+ const Logger = debug(DebugNamespaces.ROOT);
473
+
474
+ class ReflectHelper {
475
+ static get items() {
476
+ return this._items;
477
+ }
478
+ static get keys() {
479
+ return Object.keys(ReflectHelper.items);
480
+ }
481
+ static has(key, target, property) {
482
+ return (!isNil(key) &&
483
+ !isNil(ReflectHelper.items[key]) &&
484
+ (isNil(target) ||
485
+ (!isNil(ReflectHelper.items[key][target]) &&
486
+ (isNil(property) || !isNil(ReflectHelper.items[key][target][String(property)])))));
487
+ }
488
+ static get({ key, target, property, own = true }) {
489
+ try {
490
+ if (own) {
491
+ return Reflect.getOwnMetadata(key, target, property) || null;
492
+ }
493
+ else {
494
+ return Reflect.getMetadata(key, target, property) || null;
495
+ }
496
+ }
497
+ catch (_err) {
498
+ return null;
499
+ }
500
+ }
501
+ static first({ key, target, property, own = true }) {
502
+ const values = ReflectHelper.get({ key, target, property, own });
503
+ return isArray(values) ? first(values) : values;
504
+ }
505
+ static last({ key, target, property, own = true }) {
506
+ const values = ReflectHelper.get({ key, target, property, own });
507
+ return isArray(values) ? last(values) : values;
508
+ }
509
+ static set({ key, target, property, value, propertyDescriptor }) {
510
+ Reflect.defineMetadata(key, value, target, property);
511
+ ReflectHelper.put({ key, target, property, value, propertyDescriptor });
512
+ }
513
+ static add({ key, target, property, value, propertyDescriptor }) {
514
+ let values = ReflectHelper.get({ key, target, property }) || new Array();
515
+ if (!Array.isArray(values))
516
+ values = [values];
517
+ values.push(value);
518
+ ReflectHelper.set({ key, target, property, value: values, propertyDescriptor });
519
+ }
520
+ static all({ key }) {
521
+ const items = ReflectHelper.items[key] || {};
522
+ return flatten(Object.keys(items).map((item) => flatten(this.allFrom(key, items[item]))));
523
+ }
524
+ static allFrom(key, target) {
525
+ return Object.keys(target)
526
+ .filter((property) => property !== 'object')
527
+ .map((property) => this.allValuesFrom(key, target, property));
528
+ }
529
+ static allValuesFrom(key, target, property) {
530
+ const values = target[property];
531
+ let value = values.value;
532
+ const propertyDescriptor = values.propertyDescriptor;
533
+ if (!isArray(value))
534
+ value = [value];
535
+ return flatten(value.map((val) => {
536
+ return {
537
+ key,
538
+ target: target.object,
539
+ property,
540
+ value: val,
541
+ propertyDescriptor,
542
+ };
543
+ }));
544
+ }
545
+ static delete({ key, target, property }) {
546
+ Reflect.deleteMetadata(key, target, property);
547
+ return ReflectHelper.remove(key, target, property);
548
+ }
549
+ static clear(key) {
550
+ if (!key) {
551
+ ReflectHelper.keys.forEach((storedKey) => {
552
+ ReflectHelper.clear(storedKey);
553
+ });
554
+ }
555
+ else {
556
+ if (ReflectHelper.keys.includes(key)) {
557
+ Object.values(ReflectHelper.items[key]).forEach((target) => {
558
+ if (ReflectHelper.has(key, target)) {
559
+ Object.values(ReflectHelper.items[key][target.toString()]).forEach((property) => {
560
+ ReflectHelper.delete({
561
+ key,
562
+ target: target.object,
563
+ property: String(property),
564
+ });
565
+ ReflectHelper.remove(key, target, String(property));
566
+ });
567
+ }
568
+ ReflectHelper.delete({ key, target: target.object });
569
+ ReflectHelper.remove(key, target);
570
+ });
571
+ }
572
+ }
573
+ }
574
+ static getType({ target, propertyKey }) {
575
+ return Reflect.getMetadata('design:type', target, propertyKey);
576
+ }
577
+ static getReturntype({ target, propertyKey }) {
578
+ return Reflect.getMetadata('design:returntype', target, propertyKey);
579
+ }
580
+ static getAllMethods(target) {
581
+ const props = [];
582
+ let obj = target;
583
+ do {
584
+ props.push(...Object.getOwnPropertyNames(obj));
585
+ } while ((obj = Object.getPrototypeOf(obj)));
586
+ return props.sort().filter((e, i, arr) => {
587
+ if ([
588
+ '__defineGetter__',
589
+ '__defineSetter__',
590
+ '__lookupGetter__',
591
+ '__lookupSetter__',
592
+ 'constructor',
593
+ 'hasOwnProperty',
594
+ 'isPrototypeOf',
595
+ 'propertyIsEnumerable',
596
+ 'toLocaleString',
597
+ 'toString',
598
+ 'valueOf',
599
+ ].includes(e))
600
+ return false;
601
+ if (e != arr[i + 1] && typeof target[e] === 'function')
602
+ return true;
603
+ });
604
+ }
605
+ static put({ key, target, property, value, propertyDescriptor }) {
606
+ const index = target.constructor.name;
607
+ ReflectHelper.items[key] = ReflectHelper.items[key] || {};
608
+ ReflectHelper.items[key][index] = ReflectHelper.items[key][index] || {};
609
+ ReflectHelper.items[key][index].object = target;
610
+ if (isNil(property)) {
611
+ ReflectHelper.items[key][index].value = {
612
+ value,
613
+ propertyDescriptor,
614
+ };
615
+ }
616
+ else {
617
+ ReflectHelper.items[key][index][String(property)] = ReflectHelper.items[key][index][String(property)] || {};
618
+ ReflectHelper.items[key][index][String(property)] = {
619
+ value,
620
+ propertyDescriptor,
621
+ };
622
+ }
623
+ }
624
+ static remove(key, target, property) {
625
+ if (ReflectHelper.has(key, target, property))
626
+ return delete ReflectHelper.items[key][target][String(property)];
627
+ else if (ReflectHelper.has(key, target))
628
+ return delete ReflectHelper.items[key][target];
629
+ else if (ReflectHelper.has(key))
630
+ return delete ReflectHelper.items[key];
631
+ else
632
+ return false;
633
+ }
634
+ }
635
+ ReflectHelper._items = {};
636
+
637
+ class DebugDecoratorHelper {
638
+ static set(target, options) {
639
+ ReflectHelper.add({
640
+ key: DebugDecoratorHelper.DebugNamingMetadataKey,
641
+ target,
642
+ value: options,
643
+ });
644
+ }
645
+ static get(target) {
646
+ return ReflectHelper.first({
647
+ key: DebugDecoratorHelper.DebugNamingMetadataKey,
648
+ target,
649
+ });
650
+ }
651
+ }
652
+ DebugDecoratorHelper.DebugNamingMetadataKey = 'model:naming:decorator';
653
+
654
+ class ClassNameHelper {
655
+ static get(clazz) {
656
+ if (!clazz)
657
+ return null;
658
+ const prototype = Object.getPrototypeOf(clazz);
659
+ const names = compact([
660
+ get$1(clazz, 'constructor.name'),
661
+ get$1(prototype, 'constructor.name'),
662
+ get$1(prototype, '__proto__.constructor.name'),
663
+ ]);
664
+ return names.find((name) => name !== 'class_1');
665
+ }
666
+ }
667
+
668
+ const isDebuggable = (object) => {
669
+ return 'debug' in object;
670
+ };
671
+ class DebugHelper {
672
+ constructor(...namespace) {
673
+ this.namespaces = new Set();
674
+ this.push(...namespace);
675
+ }
676
+ static namespacesFor(target) {
677
+ if (isNil(target))
678
+ return [];
679
+ const decorator = DebugDecoratorHelper.get(Object.getPrototypeOf(target));
680
+ const namespaces = get$1(decorator, 'namespaces', []);
681
+ const name = get$1(decorator, 'name', ClassNameHelper.get(target));
682
+ return [...namespaces, name];
683
+ }
684
+ static as(...namespaces) {
685
+ return new DebugHelper(...namespaces);
686
+ }
687
+ static for(target, ...namespaces) {
688
+ const targetNamespaces = this.namespacesFor(target);
689
+ return new DebugHelper(...targetNamespaces, ...namespaces);
690
+ }
691
+ static from(target, ...namespaces) {
692
+ if (this.isDebuggable(target)) {
693
+ const debug = target.debug;
694
+ if (namespaces)
695
+ debug.push(...namespaces);
696
+ return debug;
697
+ }
698
+ return DebugHelper.for(target, ...namespaces);
699
+ }
700
+ static clonedFrom(target, ...namespaces) {
701
+ if (this.isDebuggable(target)) {
702
+ namespaces.push(...target.debug.entries);
703
+ }
704
+ else if (!isNil(target)) {
705
+ namespaces.push(...this.namespacesFor(target));
706
+ }
707
+ return DebugHelper.for(target, ...namespaces);
708
+ }
709
+ static clone(target, ...namespaces) {
710
+ let original;
711
+ if (this.isDebuggable(target)) {
712
+ original = target.debug;
713
+ namespaces.push(...original.entries);
714
+ }
715
+ return {
716
+ original,
717
+ debug: DebugHelper.for(target, ...namespaces),
718
+ };
719
+ }
720
+ static replace(target, attrs) {
721
+ if (this.isDebuggable(target))
722
+ target.debug = attrs.with;
723
+ }
724
+ static mock(target, ...namespaces) {
725
+ const { original, debug } = DebugHelper.clone(target, ...namespaces);
726
+ DebugHelper.replace(target, { with: debug });
727
+ return { original, debug };
728
+ }
729
+ get entries() {
730
+ return Array.from(get$1(this, 'namespaces', []));
731
+ }
732
+ get namespace() {
733
+ return compact(flatten(this.entries)).join(':');
734
+ }
735
+ log(message, ...args) {
736
+ this.logger(JSON.stringify(message), ...args.map((element) => JSON.stringify(element)));
737
+ DebugHelper.logs$.next({ namespace: this.namespace, message, args });
738
+ return this;
739
+ }
740
+ trace(message, ...args) {
741
+ this.logger.extend(DebugNamespaces.TRACE)(message, ...args);
742
+ DebugHelper.traces$.next({ namespace: this.namespace, message, args });
743
+ return this;
744
+ }
745
+ error(error, ...args) {
746
+ this.logger.extend(DebugNamespaces.ERROR)(JSON.stringify(error), ...args.map((element) => JSON.stringify(element)));
747
+ DebugHelper.errors$.next({ namespace: this.namespace, error, args });
748
+ return this;
749
+ }
750
+ build() {
751
+ this.logger = Logger;
752
+ this.tracer = Logger;
753
+ this.err = Logger;
754
+ this.entries.forEach((namespace) => {
755
+ this.logger = this.logger.extend(namespace);
756
+ this.tracer = this.tracer.extend(namespace);
757
+ this.err = this.err.extend(namespace);
758
+ });
759
+ return this;
760
+ }
761
+ with(...namespace) {
762
+ return new DebugHelper(...this.entries, ...namespace);
763
+ }
764
+ push(...namespace) {
765
+ if (namespace) {
766
+ namespace.filter((item) => Boolean(item)).forEach((item) => this.namespaces.add(item));
767
+ }
768
+ return this.build();
769
+ }
770
+ unshift(...namespace) {
771
+ if (namespace) {
772
+ return this.reset(...namespace, ...this.entries);
773
+ }
774
+ return this;
775
+ }
776
+ reset(...namespace) {
777
+ this.namespaces = new Set(flatten(compact(namespace)));
778
+ return this.build();
779
+ }
780
+ startWith(...namespace) {
781
+ const current = this.namespaces;
782
+ this.namespaces = new Set(flatten([compact(namespace), ...current]));
783
+ return this.build();
784
+ }
785
+ shift() {
786
+ const list = this.entries;
787
+ list.shift();
788
+ return this.reset(...list);
466
789
  }
790
+ pop() {
791
+ const list = this.entries;
792
+ list.pop();
793
+ return this.reset(...list);
794
+ }
795
+ clear() {
796
+ return this.reset();
797
+ }
798
+ remove(...namespace) {
799
+ if (namespace) {
800
+ namespace.filter((item) => Boolean(item)).forEach((item) => this.namespaces.delete(item));
801
+ }
802
+ return this.build();
803
+ }
804
+ puts(...args) {
805
+ return [`[${this.namespace}]`, ...args].join(' ');
806
+ }
807
+ }
808
+ DebugHelper.logs$ = new Subject();
809
+ DebugHelper.traces$ = new Subject();
810
+ DebugHelper.errors$ = new Subject();
811
+ DebugHelper.isDebuggable = isDebuggable;
812
+
813
+ function Debug(opts) {
814
+ return function (target) {
815
+ DebugDecoratorHelper.set(target.prototype, opts);
816
+ };
467
817
  }
468
818
 
819
+ const ASYNC_IDENTIFIER = 'async';
820
+ function Log(options = {}) {
821
+ return Trace({ level: 'log', ...options });
822
+ }
823
+ function Trace(options = {}) {
824
+ return function (target, propertyKey, propertyDescriptor) {
825
+ const method = propertyDescriptor.value;
826
+ const isPromise = method.toString().includes(ASYNC_IDENTIFIER);
827
+ const args = {
828
+ options,
829
+ method,
830
+ target,
831
+ propertyKey,
832
+ propertyDescriptor,
833
+ };
834
+ propertyDescriptor.value = isPromise ? promiseTracer(args) : functionTracer(args);
835
+ return propertyDescriptor;
836
+ };
837
+ }
838
+ const traceCall = function ({ target, propertyKey, propertyDescriptor, args }) {
839
+ if (!target.debug)
840
+ target.debug = DebugHelper.for(target, propertyKey);
841
+ return target.debug.push(propertyKey).trace('called', { target, propertyKey, propertyDescriptor, args });
842
+ };
843
+ const promiseTracer = function ({ options, method, propertyKey, propertyDescriptor }) {
844
+ return function (...args) {
845
+ return new Promise((resolve, reject) => {
846
+ const debug = traceCall({ target: this, propertyDescriptor, propertyKey, args });
847
+ if (get$1(options, 'level', '') === 'log') {
848
+ debug.with('params').log(args);
849
+ }
850
+ return method
851
+ .apply(this, args)
852
+ .then((result) => {
853
+ if (options.callbackFn) {
854
+ options.callbackFn({ target: this, result, args, namespace: [propertyKey] });
855
+ }
856
+ if (get$1(options, 'level', '') === 'log') {
857
+ debug.with('returns').log(result === undefined ? 'void' : result);
858
+ }
859
+ return resolve(result);
860
+ })
861
+ .catch((error) => {
862
+ debug.error(error, ...args);
863
+ debug.with('stack').error(error.stack).pop();
864
+ return reject(error);
865
+ })
866
+ .finally(() => {
867
+ return debug.trace('finally', { args }).pop();
868
+ });
869
+ });
870
+ };
871
+ };
872
+ const functionTracer = function ({ options, target, method, propertyKey, propertyDescriptor, }) {
873
+ return function (...args) {
874
+ const debug = traceCall({ target: this || target, propertyDescriptor, propertyKey, args });
875
+ if (get$1(options, 'level', '') === 'log') {
876
+ debug.with('params').log(args);
877
+ }
878
+ let result;
879
+ try {
880
+ result = method.apply(this, args);
881
+ if (options.callbackFn)
882
+ options.callbackFn({ target: this, result, args, namespace: [propertyKey] });
883
+ if (get$1(options, 'level', '') === 'log') {
884
+ debug.with('returns').log(result === undefined ? 'void' : result);
885
+ }
886
+ return result;
887
+ }
888
+ catch (error) {
889
+ debug.error(error, ...args).pop();
890
+ throw error;
891
+ }
892
+ finally {
893
+ debug.trace('finally', { args }).pop();
894
+ }
895
+ };
896
+ };
897
+
469
898
  const get = (object, path, defaultValue) => get$1(object, path, defaultValue);
470
899
 
471
900
  function is(value) {
@@ -536,26 +965,28 @@ class Coupon extends BaseModel {
536
965
  static createCoupon(userId) {
537
966
  return this.toInstance({
538
967
  nickname: `${Date.now()}`,
539
- type: CouponTypes.ABSOLUTE,
540
968
  checkoutType: CheckoutTypes.ECOMMERCE,
541
- discount: 30,
969
+ discount: {
970
+ subscriber: {
971
+ type: CouponTypes.ABSOLUTE,
972
+ value: 10,
973
+ },
974
+ non_subscriber: {
975
+ type: CouponTypes.ABSOLUTE,
976
+ value: 10,
977
+ },
978
+ subscription: {
979
+ type: CouponTypes.ABSOLUTE,
980
+ value: 10,
981
+ },
982
+ },
542
983
  user: userId,
543
- useLimit: 1,
544
- useLimitPerUser: true,
545
984
  createdAt: new Date(Date.now()),
546
985
  beginAt: new Date(Date.now()),
547
986
  expiresIn: new Date(Date.now() + COUPON_EXPIRATION),
548
987
  });
549
988
  }
550
989
  }
551
- __decorate([
552
- Expose({ name: 'checkout_type' }),
553
- __metadata("design:type", Number)
554
- ], Coupon.prototype, "checkoutType", void 0);
555
- __decorate([
556
- Expose({ name: 'exclusivity_type' }),
557
- __metadata("design:type", Number)
558
- ], Coupon.prototype, "exclusivityType", void 0);
559
990
 
560
991
  class SubscriptionPlan extends BaseModel {
561
992
  static get identifiersFields() {
@@ -595,6 +1026,18 @@ __decorate([
595
1026
  __metadata("design:type", BeautyProfile)
596
1027
  ], User.prototype, "beautyProfile", void 0);
597
1028
 
1029
+ class Address extends BaseModel {
1030
+ static get identifiersFields() {
1031
+ return ['id'];
1032
+ }
1033
+ }
1034
+
1035
+ class UserAddress extends Address {
1036
+ static get identifiersFields() {
1037
+ return ['id', 'userId'];
1038
+ }
1039
+ }
1040
+
598
1041
  class Subscription extends BaseModel {
599
1042
  static get identifiersFields() {
600
1043
  return ['id'];
@@ -609,12 +1052,12 @@ __decorate([
609
1052
  __metadata("design:type", SubscriptionPlan)
610
1053
  ], Subscription.prototype, "subscriptionPlan", void 0);
611
1054
  __decorate([
612
- Type(() => Address),
613
- __metadata("design:type", Address)
1055
+ Type(() => UserAddress),
1056
+ __metadata("design:type", UserAddress)
614
1057
  ], Subscription.prototype, "shippingAddress", void 0);
615
1058
  __decorate([
616
- Type(() => Address),
617
- __metadata("design:type", Address)
1059
+ Type(() => UserAddress),
1060
+ __metadata("design:type", UserAddress)
618
1061
  ], Subscription.prototype, "billingAddress", void 0);
619
1062
  __decorate([
620
1063
  Type(() => Coupon),
@@ -629,12 +1072,6 @@ __decorate([
629
1072
  __metadata("design:type", Array)
630
1073
  ], Subscription.prototype, "payment", void 0);
631
1074
 
632
- class UserAddress extends Address {
633
- static get identifiersFields() {
634
- return ['id', 'userId'];
635
- }
636
- }
637
-
638
1075
  class UserPaymentMethod extends BaseModel {
639
1076
  static get identifiersFields() {
640
1077
  return ['id', 'userId'];
@@ -666,7 +1103,7 @@ class Authentication {
666
1103
  async signIn({ email, password }, signInMethod) {
667
1104
  const method = this.getServiceByMethod(signInMethod);
668
1105
  const userAuth = await this.authService[method]({ email, password });
669
- const user = this.userRepository.get(userAuth);
1106
+ const user = this.userRepository.get({ id: userAuth.id });
670
1107
  if (!isNil(user))
671
1108
  return user;
672
1109
  if (/^.+@b4a.com.br$/.test(userAuth.email))
@@ -759,14 +1196,123 @@ class RecoveryPassword {
759
1196
  }
760
1197
  }
761
1198
 
762
- class Category extends BaseModel {
763
- identifierFields() {
1199
+ class Filter extends BaseModel {
1200
+ static get identifiersFields() {
1201
+ return ['id'];
1202
+ }
1203
+ }
1204
+
1205
+ class CategoryBase extends BaseModel {
1206
+ static get identifiersFields() {
1207
+ return ['id'];
1208
+ }
1209
+ }
1210
+ __decorate([
1211
+ Type(() => CategoryBase),
1212
+ __metadata("design:type", CategoryBase)
1213
+ ], CategoryBase.prototype, "parent", void 0);
1214
+ __decorate([
1215
+ Type(() => Filter),
1216
+ __metadata("design:type", Array)
1217
+ ], CategoryBase.prototype, "filters", void 0);
1218
+
1219
+ class CategoryForProduct extends CategoryBase {
1220
+ static get identifiersFields() {
1221
+ return ['id'];
1222
+ }
1223
+ }
1224
+
1225
+ class ProductBase extends BaseModel {
1226
+ get evaluation() {
1227
+ return {
1228
+ reviews: this.reviews,
1229
+ count: this.reviewsTotal,
1230
+ rating: this.rate,
1231
+ };
1232
+ }
1233
+ set evaluation(evaluation) {
1234
+ if (!evaluation) {
1235
+ this.reviews = null;
1236
+ this.reviewsTotal = null;
1237
+ this.rate = null;
1238
+ return;
1239
+ }
1240
+ this.reviews = evaluation.reviews || this.reviews;
1241
+ this.reviewsTotal = evaluation.count || this.reviewsTotal;
1242
+ this.rate = evaluation.rating || this.rate;
1243
+ }
1244
+ static get identifiersFields() {
1245
+ return ['id'];
1246
+ }
1247
+ }
1248
+
1249
+ class ProductForKit extends ProductBase {
1250
+ static get identifiersFields() {
1251
+ return ['id'];
1252
+ }
1253
+ }
1254
+ __decorate([
1255
+ Type(() => CategoryForProduct),
1256
+ __metadata("design:type", CategoryForProduct)
1257
+ ], ProductForKit.prototype, "category", void 0);
1258
+
1259
+ class KitProduct extends BaseModel {
1260
+ static get identifiersFields() {
1261
+ return ['productId', 'kitProductId'];
1262
+ }
1263
+ }
1264
+ __decorate([
1265
+ Type(() => ProductForKit),
1266
+ __metadata("design:type", ProductForKit)
1267
+ ], KitProduct.prototype, "kit", void 0);
1268
+ __decorate([
1269
+ Type(() => ProductForKit),
1270
+ __metadata("design:type", ProductForKit)
1271
+ ], KitProduct.prototype, "product", void 0);
1272
+
1273
+ class ProductForCategory extends ProductBase {
1274
+ static get identifiersFields() {
764
1275
  return ['id'];
765
1276
  }
1277
+ }
1278
+ __decorate([
1279
+ Type(() => KitProduct),
1280
+ __metadata("design:type", Array)
1281
+ ], ProductForCategory.prototype, "kitProducts", void 0);
1282
+
1283
+ class Category extends CategoryBase {
766
1284
  static get identifiersFields() {
767
1285
  return ['id'];
768
1286
  }
769
1287
  }
1288
+ __decorate([
1289
+ Type(() => ProductForCategory),
1290
+ __metadata("design:type", Array)
1291
+ ], Category.prototype, "childrenProducts", void 0);
1292
+
1293
+ class CategoryCollectionChildren extends BaseModel {
1294
+ static get identifiersFields() {
1295
+ return ['collectionId', 'categoryId'];
1296
+ }
1297
+ }
1298
+ __decorate([
1299
+ Type(() => CategoryCollectionChildren),
1300
+ __metadata("design:type", CategoryCollectionChildren)
1301
+ ], CategoryCollectionChildren.prototype, "parent", void 0);
1302
+
1303
+ class CategoryFilter extends BaseModel {
1304
+ static get identifiersFields() {
1305
+ return ['id'];
1306
+ }
1307
+ }
1308
+ __decorate([
1309
+ Type(() => Filter),
1310
+ __metadata("design:type", Filter)
1311
+ ], CategoryFilter.prototype, "filter", void 0);
1312
+ __decorate([
1313
+ Type(() => Category),
1314
+ __metadata("design:type", Category)
1315
+ ], CategoryFilter.prototype, "category", void 0);
770
1316
 
771
1317
  var GenderDestination;
772
1318
  (function (GenderDestination) {
@@ -783,53 +1329,59 @@ var Shops;
783
1329
  Shops["ALL"] = "ALL";
784
1330
  })(Shops || (Shops = {}));
785
1331
 
786
- class Product extends BaseModel {
787
- identifierFields() {
1332
+ class FilterOption extends BaseModel {
1333
+ static get identifiersFields() {
788
1334
  return ['id'];
789
1335
  }
1336
+ }
1337
+
1338
+ class Product extends ProductBase {
790
1339
  static get identifiersFields() {
791
1340
  return ['id'];
792
1341
  }
793
1342
  }
1343
+ __decorate([
1344
+ Type(() => CategoryForProduct),
1345
+ __metadata("design:type", CategoryForProduct)
1346
+ ], Product.prototype, "category", void 0);
794
1347
  __decorate([
795
1348
  Type(() => KitProduct),
796
1349
  __metadata("design:type", Array)
797
1350
  ], Product.prototype, "kitProducts", void 0);
798
1351
 
799
- class KitProduct extends BaseModel {
1352
+ class Variant extends BaseModel {
800
1353
  static get identifiersFields() {
801
- return ['productId', 'kitProducId'];
1354
+ return ['id', 'productId'];
802
1355
  }
803
1356
  }
804
- __decorate([
805
- Type(() => Product),
806
- __metadata("design:type", Product)
807
- ], KitProduct.prototype, "kit", void 0);
808
- __decorate([
809
- Type(() => Product),
810
- __metadata("design:type", Product)
811
- ], KitProduct.prototype, "product", void 0);
812
1357
 
813
- class Variant extends BaseModel {
814
- identifierFields() {
1358
+ class Wishlist extends Category {
1359
+ static get identifiersFields() {
815
1360
  return ['id'];
816
1361
  }
1362
+ }
1363
+
1364
+ class Buy2Win extends BaseModel {
817
1365
  static get identifiersFields() {
818
- return ['id', 'productId'];
1366
+ return ['id'];
819
1367
  }
820
1368
  }
1369
+ __decorate([
1370
+ Type(() => Category),
1371
+ __metadata("design:type", Array)
1372
+ ], Buy2Win.prototype, "categories", void 0);
821
1373
 
822
- var OrderStatus;
823
- (function (OrderStatus) {
824
- OrderStatus["AGUARDANDO_PAGAMENTO"] = "Aguardando pagamento";
825
- OrderStatus["EM_PREPARO"] = "Preparando pedido";
826
- OrderStatus["NF_EMITIDA"] = "Nota Fiscal Emitida";
827
- OrderStatus["AGUARDANDO_ENVIO"] = "Aguardando Transaportadora";
828
- OrderStatus["ENVIADO"] = "Enviado";
829
- OrderStatus["ENTREGUE"] = "Entregue";
830
- OrderStatus["CANCELADO"] = "Cancelado";
831
- OrderStatus["CREDIT_CARD"] = "credit_card";
832
- })(OrderStatus || (OrderStatus = {}));
1374
+ class CampaignDashboard extends BaseModel {
1375
+ static get identifiersFields() {
1376
+ return ['id'];
1377
+ }
1378
+ }
1379
+
1380
+ class CampaignHashtag extends BaseModel {
1381
+ static get identifiersFields() {
1382
+ return ['id'];
1383
+ }
1384
+ }
833
1385
 
834
1386
  class LineItem extends Product {
835
1387
  }
@@ -854,12 +1406,12 @@ __decorate([
854
1406
  __metadata("design:type", User)
855
1407
  ], Checkout.prototype, "user", void 0);
856
1408
  __decorate([
857
- Type(() => Address),
858
- __metadata("design:type", Address)
1409
+ Type(() => UserAddress),
1410
+ __metadata("design:type", UserAddress)
859
1411
  ], Checkout.prototype, "shippingAddress", void 0);
860
1412
  __decorate([
861
- Type(() => Address),
862
- __metadata("design:type", Address)
1413
+ Type(() => UserAddress),
1414
+ __metadata("design:type", UserAddress)
863
1415
  ], Checkout.prototype, "billingAddress", void 0);
864
1416
  __decorate([
865
1417
  Type(() => ShippingMethod),
@@ -870,6 +1422,18 @@ __decorate([
870
1422
  __metadata("design:type", Coupon)
871
1423
  ], Checkout.prototype, "coupon", void 0);
872
1424
 
1425
+ var OrderStatus;
1426
+ (function (OrderStatus) {
1427
+ OrderStatus["AGUARDANDO_PAGAMENTO"] = "Aguardando pagamento";
1428
+ OrderStatus["EM_PREPARO"] = "Preparando pedido";
1429
+ OrderStatus["NF_EMITIDA"] = "Nota Fiscal Emitida";
1430
+ OrderStatus["AGUARDANDO_ENVIO"] = "Aguardando Transaportadora";
1431
+ OrderStatus["ENVIADO"] = "Enviado";
1432
+ OrderStatus["ENTREGUE"] = "Entregue";
1433
+ OrderStatus["CANCELADO"] = "Cancelado";
1434
+ OrderStatus["CREDIT_CARD"] = "credit_card";
1435
+ })(OrderStatus || (OrderStatus = {}));
1436
+
873
1437
  class Order extends Checkout {
874
1438
  }
875
1439
  __decorate([
@@ -883,12 +1447,12 @@ class CheckoutSubscription extends BaseModel {
883
1447
  }
884
1448
  }
885
1449
  __decorate([
886
- Type(() => Address),
887
- __metadata("design:type", Address)
1450
+ Type(() => UserAddress),
1451
+ __metadata("design:type", UserAddress)
888
1452
  ], CheckoutSubscription.prototype, "shippingAddress", void 0);
889
1453
  __decorate([
890
- Type(() => Address),
891
- __metadata("design:type", Address)
1454
+ Type(() => UserAddress),
1455
+ __metadata("design:type", UserAddress)
892
1456
  ], CheckoutSubscription.prototype, "billingAddress", void 0);
893
1457
  __decorate([
894
1458
  Type(() => SubscriptionPlan),
@@ -899,15 +1463,19 @@ __decorate([
899
1463
  __metadata("design:type", Coupon)
900
1464
  ], CheckoutSubscription.prototype, "coupon", void 0);
901
1465
 
902
- class Buy2Win extends BaseModel {
903
- static get identifiersFields() {
904
- return ['id'];
1466
+ class RoundProductPricesHelper {
1467
+ static roundProductPrices(product) {
1468
+ product.price.price = Number(product.price.price.toFixed(2));
1469
+ product.price.fullPrice = Number(product.price.fullPrice.toFixed(2));
1470
+ if (product.price.subscriberPrice) {
1471
+ product.price.subscriberPrice = Number(product.price.subscriberPrice.toFixed(2));
1472
+ }
1473
+ if (product instanceof LineItem && product.pricePaid) {
1474
+ product.pricePaid = Number(product.pricePaid.toFixed(2));
1475
+ }
1476
+ return product;
905
1477
  }
906
1478
  }
907
- __decorate([
908
- Type(() => Category),
909
- __metadata("design:type", Array)
910
- ], Buy2Win.prototype, "categories", void 0);
911
1479
 
912
1480
  var FilterType;
913
1481
  (function (FilterType) {
@@ -1008,6 +1576,12 @@ class ShopMenu extends BaseModel {
1008
1576
  }
1009
1577
  }
1010
1578
 
1579
+ class ShopSettings extends BaseModel {
1580
+ static get identifiersFields() {
1581
+ return ['id'];
1582
+ }
1583
+ }
1584
+
1011
1585
  class InvalidArgumentError extends CustomError {
1012
1586
  constructor(message) {
1013
1587
  super(message);
@@ -1038,12 +1612,16 @@ class AxiosAdapter {
1038
1612
  constructor(config) {
1039
1613
  this.config = config;
1040
1614
  }
1041
- async get(index) {
1615
+ async get(index, id) {
1042
1616
  try {
1043
1617
  const { data } = await axios({
1044
- url: `${this.config.url}/${index}`,
1618
+ url: `${this.config.url}/${index}/_doc/${id}`,
1045
1619
  method: 'GET',
1046
- headers: { Authorization: `Basic ${this.config.credential}` },
1620
+ responseType: 'json',
1621
+ headers: {
1622
+ 'Content-Type': 'application/json',
1623
+ Authorization: `ApiKey ${this.config.credential}`,
1624
+ },
1047
1625
  });
1048
1626
  return data._source;
1049
1627
  }
@@ -1055,9 +1633,14 @@ class AxiosAdapter {
1055
1633
  }
1056
1634
  async query(index, query) {
1057
1635
  const { data } = await axios({
1058
- url: `${this.config.url}/${index}`,
1636
+ url: `${this.config.url}/${index}/_search`,
1059
1637
  method: 'POST',
1060
- headers: { Authorization: `Basic ${this.config.credential}` },
1638
+ responseType: 'json',
1639
+ headers: {
1640
+ Accept: 'application/vnd.elasticsearch+json;compatible-with=7',
1641
+ 'Content-Type': 'application/vnd.elasticsearch+json;compatible-with=7',
1642
+ Authorization: `ApiKey ${this.config.credential}`,
1643
+ },
1061
1644
  data: query,
1062
1645
  });
1063
1646
  return {
@@ -1067,17 +1650,25 @@ class AxiosAdapter {
1067
1650
  }
1068
1651
  async save(index, data) {
1069
1652
  await axios({
1070
- url: `${this.config.url}/${index}`,
1653
+ url: `${this.config.url}/${index}/_doc`,
1654
+ method: 'POST',
1655
+ headers: { Authorization: `ApiKey ${this.config.credential}` },
1656
+ data,
1657
+ });
1658
+ }
1659
+ async update(index, id, data) {
1660
+ await axios({
1661
+ url: `${this.config.url}/${index}/_update/${id}`,
1071
1662
  method: 'PUT',
1072
- headers: { Authorization: `Basic ${this.config.credential}` },
1663
+ headers: { Authorization: `ApiKey ${this.config.credential}` },
1073
1664
  data,
1074
1665
  });
1075
1666
  }
1076
- async delete(index) {
1667
+ async delete(index, id) {
1077
1668
  await axios({
1078
- url: `${this.config.url}/${index}`,
1669
+ url: `${this.config.url}/${index}/_doc/${id}`,
1079
1670
  method: 'DELETE',
1080
- headers: { Authorization: `Basic ${this.config.credential}` },
1671
+ headers: { Authorization: `ApiKey ${this.config.credential}` },
1081
1672
  });
1082
1673
  }
1083
1674
  }
@@ -1085,13 +1676,16 @@ class AxiosAdapter {
1085
1676
  class ProductsIndex {
1086
1677
  constructor(adapter) {
1087
1678
  this.adapter = adapter;
1679
+ this.index = `products`;
1088
1680
  }
1089
- async get(id) {
1090
- const data = await this.adapter.get(`products/_doc/${id}`);
1681
+ async getById(id) {
1682
+ const data = await this.adapter.get(this.index, id);
1091
1683
  return Product.toInstance(data);
1092
1684
  }
1093
- async findById(ids, options) {
1685
+ async search(searchTerm, total, shop) {
1686
+ const size = total || 9;
1094
1687
  const fields = [
1688
+ 'EAN',
1095
1689
  'brand',
1096
1690
  'id',
1097
1691
  'images',
@@ -1102,73 +1696,82 @@ class ProductsIndex {
1102
1696
  'stock',
1103
1697
  'slug',
1104
1698
  'reviews',
1105
- 'pricePaid',
1106
- 'isGift',
1107
- 'stock',
1108
- 'weight',
1109
- 'tags',
1110
1699
  'hasVariants',
1111
- 'type',
1700
+ 'rate',
1112
1701
  ];
1113
- const { hits } = await this.adapter.query('products/_search', {
1702
+ const filter = [{ term: { published: true } }];
1703
+ if (size > 9) {
1704
+ fields.push(...['pricePaid', 'isGift', 'stock', 'weight', 'tags']);
1705
+ }
1706
+ else {
1707
+ filter.push({ term: { tags: shop == Shops.GLAMSHOP ? 'feminino' : 'masculino' } });
1708
+ }
1709
+ const search = await this.adapter.query(this.index, {
1710
+ size,
1114
1711
  _source: fields,
1115
1712
  query: {
1116
1713
  bool: {
1117
- filter: [
1118
- {
1119
- terms: {
1120
- _id: ids,
1121
- },
1714
+ must: {
1715
+ multi_match: {
1716
+ query: `${searchTerm}`,
1717
+ type: 'bool_prefix',
1718
+ fields: [
1719
+ 'name',
1720
+ 'name.folded',
1721
+ 'name.search',
1722
+ 'description',
1723
+ 'description.search',
1724
+ 'description.folded',
1725
+ 'brand',
1726
+ 'brand.search',
1727
+ 'brand.folded',
1728
+ ],
1729
+ fuzziness: 2,
1122
1730
  },
1123
- {
1124
- term: {
1125
- published: true,
1731
+ },
1732
+ should: {
1733
+ match_phrase_prefix: {
1734
+ 'name.search': {
1735
+ query: `${searchTerm}`,
1736
+ slop: 10,
1126
1737
  },
1127
1738
  },
1128
- ...(options?.hasStock
1129
- ? [
1130
- {
1131
- range: {
1132
- 'stock.quantity': {
1133
- gt: 0,
1134
- },
1135
- },
1136
- },
1137
- ]
1138
- : []),
1139
- ],
1739
+ },
1740
+ filter,
1140
1741
  },
1141
1742
  },
1142
- ...(options?.size ? { size: options?.size } : {}),
1143
1743
  });
1144
- return hits.map((hit) => Product.toInstance(hit._source));
1744
+ search.hits = search.hits
1745
+ .filter((e) => e._source.name !== '')
1746
+ .map((hit) => {
1747
+ RoundProductPricesHelper.roundProductPrices(hit._source);
1748
+ return hit;
1749
+ });
1750
+ return search;
1145
1751
  }
1146
1752
  async save(product) {
1147
- delete product.createdAt;
1148
- delete product.updatedAt;
1149
- delete product.kitProducts;
1150
1753
  try {
1151
- if (!product.firestoreId)
1152
- throw new Error('Is not a product from firestore');
1153
- await this.get(product.firestoreId);
1154
- await this.adapter.save(`products/_doc/${product.firestoreId}`, product.toPlain());
1754
+ const { createdAt, updatedAt, kitProducts, ...data } = product;
1755
+ this.adapter.save(this.index, data);
1155
1756
  }
1156
1757
  catch (error) {
1157
- if (!(error instanceof Error))
1158
- throw error;
1159
- console.error(error.message);
1160
- await this.adapter.save(`products/_doc/${product.id}`, product.toPlain());
1758
+ console.error(error);
1161
1759
  }
1162
1760
  }
1163
- async delete(product) {
1164
- if (!product.firestoreId)
1165
- return;
1761
+ async update(product) {
1166
1762
  try {
1167
- await this.get(product.firestoreId);
1168
- await this.adapter.delete(`products/_doc/${product.firestoreId}`);
1763
+ await this.adapter.update(this.index, product.id, product);
1169
1764
  }
1170
1765
  catch (error) {
1171
- await this.adapter.delete(`products/_doc/${product.id}`);
1766
+ console.error(error);
1767
+ }
1768
+ }
1769
+ async delete(id) {
1770
+ try {
1771
+ await this.adapter.delete(this.index, id);
1772
+ }
1773
+ catch (error) {
1774
+ console.error(error);
1172
1775
  }
1173
1776
  }
1174
1777
  }
@@ -1198,17 +1801,39 @@ const withFirestore = (MixinBase) => {
1198
1801
  : bindDate(data[key], key),
1199
1802
  }), {});
1200
1803
  };
1804
+ const omitByRecursivelyInPlace = (value, iteratee) => {
1805
+ each(value, (v, k) => {
1806
+ if (iteratee(v, k)) {
1807
+ unset(value, k);
1808
+ }
1809
+ else if (isObject(v)) {
1810
+ omitByRecursivelyInPlace(v, iteratee);
1811
+ }
1812
+ });
1813
+ return value;
1814
+ };
1201
1815
  return class extends MixinBase {
1202
- constructor() {
1203
- super(...arguments);
1816
+ constructor(...params) {
1817
+ super(...params);
1818
+ this.fields = {};
1819
+ this.interceptors = {};
1204
1820
  this.collectionName = '';
1821
+ const options = params[0];
1822
+ this.firestore = options.firestore;
1823
+ this.collectionName = options.collectionName;
1824
+ this.model = options.model;
1825
+ this.fields = options.fields;
1826
+ this.interceptors = options.interceptors;
1205
1827
  }
1206
1828
  collection(path) {
1207
1829
  return collection(this.firestore, path || this.collectionName).withConverter(this.buildModelInstance());
1208
1830
  }
1209
1831
  buildModelInstance() {
1210
1832
  return {
1211
- toFirestore: (data) => (data?.toPlain ? data.toPlain() : data),
1833
+ toFirestore: (data) => {
1834
+ const plain = data?.toPlain ? data.toPlain() : data;
1835
+ return omitByRecursivelyInPlace(plain, (value) => value === undefined);
1836
+ },
1212
1837
  fromFirestore: (snap) => {
1213
1838
  const data = snap.data();
1214
1839
  let bindedData = null;
@@ -1248,11 +1873,14 @@ const withHelpers = (MixinBase) => {
1248
1873
  const withGetFirestore = (MixinBase) => {
1249
1874
  return class GetFirestore extends MixinBase {
1250
1875
  async get(identifiers) {
1251
- const docRef = await getDoc(doc(await this.collection(this.buildCollectionPathForGet(identifiers)), Object.values(identifiers).shift().toString()));
1876
+ const instance = this.model.toInstance(this.model.identifiersFields.reduce((acc, field) => ({ ...acc, [field]: identifiers[field] }), {}));
1877
+ const intercepted = await this.interceptors?.request?.({ instance });
1878
+ const builded = intercepted?.instance || instance;
1879
+ const docRef = await getDoc(doc(await this.collection(this.buildCollectionPathForGet(identifiers)), Object.values(builded.identifier).shift().toString()));
1252
1880
  const data = docRef.data();
1253
1881
  if (isNil(data))
1254
1882
  throw new NotFoundError(`Document ${JSON.stringify(identifiers)} not found`);
1255
- return data;
1883
+ return this.interceptors?.response?.(data, intercepted) || data;
1256
1884
  }
1257
1885
  buildCollectionPathForGet(identifiers) {
1258
1886
  return this.isSubCollection(this)
@@ -1289,7 +1917,7 @@ const withFindFirestore = (MixinBase) => {
1289
1917
  ], []);
1290
1918
  this.buildWhereSentence = (fieldName, options) => {
1291
1919
  if (this.isSubCollection(this) && fieldName === this.parentIdField)
1292
- [];
1920
+ return [];
1293
1921
  const value = options?.value || options;
1294
1922
  const object = {};
1295
1923
  set(object, fieldName, value);
@@ -1333,8 +1961,11 @@ const withFindFirestore = (MixinBase) => {
1333
1961
  return Object.keys(fieldsToOrderBy).map((fieldName) => orderBy(fieldName, fieldsToOrderBy[fieldName]));
1334
1962
  };
1335
1963
  }
1336
- async find({ filters, limits, orderBy, } = {}) {
1337
- const collection = this.collection(this.buildCollectionPathForFind(filters));
1964
+ async find(find = {}) {
1965
+ const collection = this.collection(this.buildCollectionPathForFind(find.filters));
1966
+ const enableCount = find?.options?.enableCount ?? true;
1967
+ const intercepted = await this.interceptors?.request?.({ find });
1968
+ const { filters, limits, orderBy } = intercepted.find || find;
1338
1969
  const queries = this.makeFirestoreWhere(filters || {});
1339
1970
  const ordination = this.makeFirestoreOrderBy(filters, orderBy);
1340
1971
  const offsets = await this.defineLimits(filters, limits);
@@ -1342,8 +1973,8 @@ const withFindFirestore = (MixinBase) => {
1342
1973
  const docs = await getDocs(query(collection, ...queryArgumments));
1343
1974
  const data = docs.docs.map((doc) => doc.data());
1344
1975
  return {
1345
- data,
1346
- count: this.calculateCount(data, limits),
1976
+ data: (await this.interceptors?.response?.(data, intercepted)) || data,
1977
+ count: enableCount ? this.calculateCount(data, limits) : Infinity,
1347
1978
  };
1348
1979
  }
1349
1980
  buildCollectionPathForFind(filters) {
@@ -1357,7 +1988,7 @@ const withFindFirestore = (MixinBase) => {
1357
1988
  const queries = [];
1358
1989
  if (limits?.offset) {
1359
1990
  if (this.model.isModel(limits.offset))
1360
- queries.push(startAfter(await getDoc(doc(this.collection(this.buildCollectionPathForFind(filters)), limits.offset.identifier[limits.offset.identifiersFields?.shift()]))));
1991
+ queries.push(startAfter(await getDoc(doc(this.collection(this.buildCollectionPathForFind(filters)), Object.values(limits.offset.identifier).shift()?.toString()))));
1361
1992
  else if (isNumber(limits.offset) || isString(limits.offset))
1362
1993
  queries.push(startAt(limits.offset));
1363
1994
  }
@@ -1378,12 +2009,16 @@ const withFindFirestore = (MixinBase) => {
1378
2009
  const withCreateFirestore = (MixinBase) => {
1379
2010
  return class CreateFirestore extends MixinBase {
1380
2011
  async create(data) {
1381
- const docRef = await this.save(this.model.toInstance(data));
2012
+ const instance = this.model.toInstance(data);
2013
+ const intercepted = await this.interceptors?.request?.({ instance });
2014
+ const builded = intercepted?.instance || instance;
2015
+ const docRef = await this.save(builded);
1382
2016
  const doc = await getDoc(docRef);
1383
- return doc.data();
2017
+ const docBuilded = (await this.interceptors?.response?.(doc.data(), intercepted)) || doc.data();
2018
+ return docBuilded;
1384
2019
  }
1385
2020
  async save(data) {
1386
- const id = data.identifier[data.identifiersFields?.shift()]?.toString();
2021
+ const id = Object.values(data.identifier)?.shift()?.toString();
1387
2022
  const collectionPath = this.buildCollectionPathForAdd(data);
1388
2023
  const collection = this.collection(collectionPath);
1389
2024
  if (isEmpty(id))
@@ -1424,9 +2059,12 @@ const withUpdateFirestore = (MixinBase) => {
1424
2059
  const model = new this.model();
1425
2060
  const keyField = model.identifiersFields.shift();
1426
2061
  const docRef = doc(this.collection(this.buildCollectionPathForUpdate(data)), getValueFromParams(data, keyField).toString());
1427
- await setDoc(docRef, this.paramsToPlain(data), { merge: true });
1428
- const docData = await getDoc(docRef);
1429
- return docData.data();
2062
+ const plainFromData = this.model.toInstance(this.paramsToPlain(data));
2063
+ const intercepted = await this.interceptors?.request?.({ instance: plainFromData });
2064
+ const builded = intercepted?.instance || plainFromData;
2065
+ await setDoc(docRef, builded.toPlain(), { merge: true });
2066
+ const docData = await getDoc(docRef).then((doc) => doc.data());
2067
+ return this.interceptors?.response?.(docData, intercepted) || docData;
1430
2068
  }
1431
2069
  buildCollectionPathForUpdate(identifiers) {
1432
2070
  return this.isSubCollection(this)
@@ -1448,7 +2086,11 @@ const withUpdateFirestore = (MixinBase) => {
1448
2086
  const withDeleteFirestore = (MixinBase) => {
1449
2087
  return class DeleteFirestore extends MixinBase {
1450
2088
  async delete(identifiers) {
1451
- await deleteDoc(doc(this.collection(this.buildCollectionPathForRemove(identifiers)), Object.values(identifiers).shift().toString()));
2089
+ const instance = this.model.toInstance(this.model.identifiersFields.reduce((acc, field) => ({ ...acc, [field]: identifiers[field] }), {}));
2090
+ const intercepted = await this.interceptors?.request?.({ instance });
2091
+ const builded = intercepted?.instance || instance;
2092
+ await deleteDoc(doc(this.collection(this.buildCollectionPathForRemove(identifiers)), Object.values(builded.identifier).shift().toString()));
2093
+ await this.interceptors?.response?.(instance, intercepted);
1452
2094
  }
1453
2095
  buildCollectionPathForRemove(identifiers) {
1454
2096
  return this.isSubCollection(this)
@@ -1460,8 +2102,10 @@ const withDeleteFirestore = (MixinBase) => {
1460
2102
 
1461
2103
  const withSubCollection = (MixinBase, ParentModel) => {
1462
2104
  return class SubCollectionMix extends MixinBase {
1463
- constructor(...args) {
1464
- super(args);
2105
+ constructor(...params) {
2106
+ const options = params[0];
2107
+ super(...params);
2108
+ this.parentIdField = options.parentIdField;
1465
2109
  }
1466
2110
  collection(path) {
1467
2111
  return super.collection(path);
@@ -1475,73 +2119,87 @@ const withCrudFirestore = (MixinBase) => {
1475
2119
  };
1476
2120
 
1477
2121
  class LeadFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
1478
- constructor(firestore) {
1479
- super();
1480
- this.firestore = firestore;
1481
- this.collectionName = 'leads';
1482
- this.model = Lead;
2122
+ constructor({ firestore, interceptors }) {
2123
+ super({
2124
+ firestore,
2125
+ collectionName: 'leads',
2126
+ model: Lead,
2127
+ interceptors,
2128
+ });
1483
2129
  }
1484
2130
  }
1485
2131
 
1486
2132
  class SubscriptionEditionFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base))), Subscription) {
1487
- constructor(firestore, parentRepository) {
1488
- super();
1489
- this.firestore = firestore;
2133
+ constructor({ firestore, interceptors }, parentRepository) {
2134
+ super({
2135
+ firestore,
2136
+ collectionName: 'editions',
2137
+ parentIdField: 'subscriptionId',
2138
+ model: Edition,
2139
+ interceptors,
2140
+ });
1490
2141
  this.parentRepository = parentRepository;
1491
- this.collectionName = 'editions';
1492
- this.parentIdField = 'subscriptionId';
1493
- this.model = Edition;
1494
2142
  }
1495
2143
  }
1496
2144
 
1497
2145
  class SubscriptionFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
1498
- constructor(firestore) {
1499
- super();
1500
- this.firestore = firestore;
1501
- this.collectionName = 'subscription';
1502
- this.model = Subscription;
2146
+ constructor({ firestore, interceptors, }) {
2147
+ super({
2148
+ firestore,
2149
+ collectionName: 'subscription',
2150
+ model: Subscription,
2151
+ interceptors,
2152
+ });
1503
2153
  }
1504
2154
  }
1505
2155
 
1506
2156
  class SubscriptionPaymentFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base))), Subscription) {
1507
- constructor(firestore, parentRepository) {
1508
- super();
1509
- this.firestore = firestore;
2157
+ constructor({ firestore, interceptors }, parentRepository) {
2158
+ super({
2159
+ firestore,
2160
+ collectionName: 'payments',
2161
+ parentIdField: 'subscriptionId',
2162
+ model: SubscriptionPayment,
2163
+ interceptors,
2164
+ });
1510
2165
  this.parentRepository = parentRepository;
1511
- this.collectionName = 'payments';
1512
- this.parentIdField = 'subscriptionId';
1513
- this.model = SubscriptionPayment;
1514
2166
  }
1515
2167
  }
1516
2168
 
1517
2169
  class UserAddressFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base))), User) {
1518
- constructor(firestore, parentRepository) {
1519
- super();
1520
- this.firestore = firestore;
2170
+ constructor({ firestore, interceptors }, parentRepository) {
2171
+ super({
2172
+ firestore,
2173
+ collectionName: 'address',
2174
+ parentIdField: 'userId',
2175
+ model: UserAddress,
2176
+ interceptors,
2177
+ });
1521
2178
  this.parentRepository = parentRepository;
1522
- this.collectionName = 'address';
1523
- this.parentIdField = 'userId';
1524
- this.model = UserAddress;
1525
2179
  }
1526
2180
  }
1527
2181
 
1528
2182
  class UserBeautyProfileFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base))), User) {
1529
- constructor(firestore, parentRepository) {
1530
- super();
1531
- this.firestore = firestore;
2183
+ constructor({ firestore, interceptors }, parentRepository) {
2184
+ super({
2185
+ firestore,
2186
+ collectionName: 'CX',
2187
+ parentIdField: 'userId',
2188
+ model: BeautyProfile,
2189
+ interceptors,
2190
+ });
1532
2191
  this.parentRepository = parentRepository;
1533
- this.collectionName = 'CX';
1534
- this.parentIdField = 'userId';
1535
- this.model = BeautyProfile;
1536
2192
  }
1537
2193
  }
1538
2194
 
1539
2195
  class UserFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
1540
- constructor(firestore) {
1541
- super();
1542
- this.firestore = firestore;
1543
- this.collectionName = 'users';
1544
- this.model = User;
2196
+ constructor({ firestore, interceptors }) {
2197
+ super({
2198
+ firestore,
2199
+ collectionName: 'users',
2200
+ model: User,
2201
+ interceptors,
2202
+ });
1545
2203
  }
1546
2204
  async get(identifiers) {
1547
2205
  const user = await super.get({ id: identifiers.id });
@@ -1581,22 +2239,26 @@ class UserFirestoreRepository extends withCrudFirestore(withHelpers(withFirestor
1581
2239
  }
1582
2240
 
1583
2241
  class UserPaymentMethodFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base))), User) {
1584
- constructor(firestore, parentRepository) {
1585
- super();
1586
- this.firestore = firestore;
2242
+ constructor({ firestore, interceptors }, parentRepository) {
2243
+ super({
2244
+ firestore,
2245
+ collectionName: 'payment_method',
2246
+ parentIdField: 'userId',
2247
+ model: UserPaymentMethod,
2248
+ interceptors,
2249
+ });
1587
2250
  this.parentRepository = parentRepository;
1588
- this.collectionName = 'payment_method';
1589
- this.parentIdField = 'userId';
1590
- this.model = UserPaymentMethod;
1591
2251
  }
1592
2252
  }
1593
2253
 
1594
2254
  class CategoryFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
1595
- constructor(firestore) {
1596
- super();
1597
- this.firestore = firestore;
1598
- this.collectionName = 'categories';
1599
- this.model = Category;
2255
+ constructor({ firestore, interceptors }) {
2256
+ super({
2257
+ firestore,
2258
+ collectionName: 'categories',
2259
+ model: Category,
2260
+ interceptors,
2261
+ });
1600
2262
  }
1601
2263
  async getCategoryBySlug(slug, shop) {
1602
2264
  const categoryDocs = await getDocs(query(this.collection(this.collectionName), where('slug', '==', slug), where('shop', '==', shop), where('published', '==', true)));
@@ -1606,14 +2268,14 @@ class CategoryFirestoreRepository extends withCrudFirestore(withHelpers(withFire
1606
2268
  throw new NotFoundError(`Document with slug ${slug} not found`);
1607
2269
  return categoryDocs.docs[0].data();
1608
2270
  }
1609
- async getCategoriesForHome(categoryIds, limit = 4) {
2271
+ async getCategoriesForHome(categoryIds, limit = 4, gender) {
1610
2272
  const categorySnap = await getDocs(query(this.collection(this.collectionName), where('id', 'in', categoryIds.filter(Boolean)), where('published', '==', true)));
1611
2273
  if (categorySnap.empty)
1612
2274
  throw new NotFoundError('Categories not found');
1613
2275
  const categories = categorySnap.docs.map((doc) => doc.data());
1614
2276
  const homeSections = await Promise.all(categories.map(async (category) => ({
1615
2277
  category,
1616
- products: await this.mountCategory(category, { limit, hasStock: true }),
2278
+ products: await this.mountCategory(category, { limit, hasStock: true, gender }),
1617
2279
  })));
1618
2280
  return homeSections;
1619
2281
  }
@@ -1629,6 +2291,8 @@ class CategoryFirestoreRepository extends withCrudFirestore(withHelpers(withFire
1629
2291
  wheres.push(where('published', '==', true), where('id', 'in', productIds));
1630
2292
  if (options?.hasStock)
1631
2293
  wheres.push(where('stock.quantity', '>', 0));
2294
+ if (options?.gender)
2295
+ wheres.push(where('tags', 'array-contains', options?.gender));
1632
2296
  if (options?.limit)
1633
2297
  wheres.push(limit(options?.limit));
1634
2298
  const productSnap = await getDocs(query(this.collection('productsErpVitrine'), ...wheres));
@@ -1638,15 +2302,26 @@ class CategoryFirestoreRepository extends withCrudFirestore(withHelpers(withFire
1638
2302
  }
1639
2303
  return is(products);
1640
2304
  }
2305
+ getCategoryByShop(shop) {
2306
+ return;
2307
+ }
2308
+ getChildren(parentId) {
2309
+ return;
2310
+ }
2311
+ isChild(id, parentId) {
2312
+ return;
2313
+ }
1641
2314
  }
1642
2315
 
1643
2316
  class ProductFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
1644
- constructor(firestore) {
1645
- super();
1646
- this.firestore = firestore;
2317
+ constructor({ firestore, interceptors }) {
2318
+ super({
2319
+ firestore,
2320
+ collectionName: 'productsErpVitrine',
2321
+ model: Product,
2322
+ interceptors,
2323
+ });
1647
2324
  this.reviews = {};
1648
- this.collectionName = 'productsErpVitrine';
1649
- this.model = Product;
1650
2325
  }
1651
2326
  async getBySlug(slug) {
1652
2327
  const result = await this.find({
@@ -1681,43 +2356,101 @@ class ProductFirestoreRepository extends withCrudFirestore(withHelpers(withFires
1681
2356
  });
1682
2357
  return this.reviews[status];
1683
2358
  }
2359
+ cleanShoppingCountFromIds() {
2360
+ return;
2361
+ }
2362
+ findCatalog(params) {
2363
+ return this.find(params);
2364
+ }
1684
2365
  }
1685
2366
 
1686
2367
  class ProductVariantFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base))), Product) {
1687
- constructor(firestore, parentRepository) {
1688
- super();
1689
- this.firestore = firestore;
2368
+ constructor({ firestore, interceptors }, parentRepository) {
2369
+ super({
2370
+ firestore,
2371
+ collectionName: 'variants',
2372
+ parentIdField: 'productId',
2373
+ model: Variant,
2374
+ interceptors,
2375
+ });
1690
2376
  this.parentRepository = parentRepository;
1691
- this.collectionName = 'variants';
1692
- this.parentIdField = 'productId';
1693
- this.model = Variant;
1694
2377
  }
1695
2378
  }
1696
2379
 
1697
2380
  class SubscriptionProductFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
1698
- constructor(firestore) {
1699
- super();
1700
- this.firestore = firestore;
1701
- this.collectionName = 'subscriptionProducts';
1702
- this.model = Product;
2381
+ constructor({ firestore, interceptors }) {
2382
+ super({
2383
+ firestore,
2384
+ collectionName: 'subscriptionProducts',
2385
+ model: Product,
2386
+ interceptors,
2387
+ });
2388
+ }
2389
+ }
2390
+
2391
+ class Buy2WinFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
2392
+ constructor({ firestore, interceptors }) {
2393
+ super({
2394
+ firestore,
2395
+ collectionName: 'buy2win',
2396
+ model: Buy2Win,
2397
+ interceptors,
2398
+ });
2399
+ }
2400
+ }
2401
+
2402
+ class CampaignDashboardFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
2403
+ constructor({ firestore, interceptors, }) {
2404
+ super({
2405
+ firestore,
2406
+ collectionName: 'dashboardCampaignsAuto',
2407
+ model: CampaignDashboard,
2408
+ interceptors,
2409
+ });
2410
+ }
2411
+ }
2412
+
2413
+ class CampaignHashtagFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
2414
+ constructor({ firestore, interceptors, }) {
2415
+ super({
2416
+ firestore,
2417
+ collectionName: 'hashtagCampaignsAuto',
2418
+ model: CampaignHashtag,
2419
+ interceptors,
2420
+ });
1703
2421
  }
1704
2422
  }
1705
2423
 
1706
2424
  class CheckoutFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
1707
- constructor(firestore) {
1708
- super();
1709
- this.firestore = firestore;
1710
- this.collectionName = 'checkouts';
1711
- this.model = Checkout;
2425
+ constructor({ firestore, interceptors }) {
2426
+ super({
2427
+ firestore,
2428
+ collectionName: 'checkouts',
2429
+ model: Checkout,
2430
+ interceptors,
2431
+ });
2432
+ }
2433
+ }
2434
+
2435
+ class CheckoutSubscriptionFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
2436
+ constructor({ firestore, interceptors, }) {
2437
+ super({
2438
+ firestore,
2439
+ collectionName: 'checkoutsSubscription',
2440
+ model: CheckoutSubscription,
2441
+ interceptors,
2442
+ });
1712
2443
  }
1713
2444
  }
1714
2445
 
1715
2446
  class CouponFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
1716
- constructor(firestore) {
1717
- super();
1718
- this.firestore = firestore;
1719
- this.collectionName = 'coupons';
1720
- this.model = Coupon;
2447
+ constructor({ firestore, interceptors }) {
2448
+ super({
2449
+ firestore,
2450
+ collectionName: 'coupons',
2451
+ model: Coupon,
2452
+ interceptors,
2453
+ });
1721
2454
  }
1722
2455
  buildModelInstance() {
1723
2456
  const { fromFirestore, toFirestore } = super.buildModelInstance();
@@ -1739,9 +2472,16 @@ class CouponFirestoreRepository extends withCrudFirestore(withHelpers(withFirest
1739
2472
  }
1740
2473
 
1741
2474
  class OrderFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
1742
- constructor(firestore) {
1743
- super();
1744
- this.firestore = firestore;
2475
+ constructor({ firestore, interceptors }) {
2476
+ super({
2477
+ firestore,
2478
+ collectionName: 'orders',
2479
+ model: Order,
2480
+ interceptors,
2481
+ fields: {
2482
+ status: FirestoreFieldType.String,
2483
+ },
2484
+ });
1745
2485
  this.orderFromFirestore = (order) => {
1746
2486
  if (!!order?.lineItems?.length) {
1747
2487
  order.lineItems = order.lineItems.map((lineItem) => {
@@ -1754,11 +2494,6 @@ class OrderFirestoreRepository extends withCrudFirestore(withHelpers(withFiresto
1754
2494
  }
1755
2495
  return order;
1756
2496
  };
1757
- this.collectionName = 'orders';
1758
- this.model = Order;
1759
- this.fields = {
1760
- status: FirestoreFieldType.String,
1761
- };
1762
2497
  }
1763
2498
  buildModelInstance() {
1764
2499
  const { fromFirestore, toFirestore } = super.buildModelInstance();
@@ -1772,84 +2507,58 @@ class OrderFirestoreRepository extends withCrudFirestore(withHelpers(withFiresto
1772
2507
  }
1773
2508
  }
1774
2509
 
1775
- class PaymentFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
1776
- constructor(firestore) {
1777
- super();
1778
- this.firestore = firestore;
1779
- this.collectionName = 'payments';
1780
- this.model = Payment;
2510
+ class LegacyOrderFirestoreRepository extends OrderFirestoreRepository {
2511
+ constructor({ firestore, interceptors }) {
2512
+ super({
2513
+ firestore,
2514
+ interceptors,
2515
+ });
2516
+ this.collectionName = 'legacyOrders';
1781
2517
  }
1782
2518
  }
1783
2519
 
1784
- class CheckoutSubscriptionFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
1785
- constructor(firestore) {
1786
- super();
1787
- this.firestore = firestore;
1788
- this.collectionName = 'checkoutsSubscription';
1789
- this.model = CheckoutSubscription;
2520
+ class PaymentFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
2521
+ constructor({ firestore, interceptors }) {
2522
+ super({
2523
+ firestore,
2524
+ collectionName: 'payments',
2525
+ model: Payment,
2526
+ interceptors,
2527
+ });
1790
2528
  }
1791
2529
  }
1792
2530
 
1793
2531
  class SubscriptionPlanFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
1794
- constructor(firestore) {
1795
- super();
1796
- this.firestore = firestore;
1797
- this.collectionName = 'subscriptionPlans';
1798
- this.model = SubscriptionPlan;
1799
- }
1800
- }
1801
-
1802
- class Buy2WinFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
1803
- constructor(firestore) {
1804
- super();
1805
- this.firestore = firestore;
1806
- this.collectionName = 'buy2win';
1807
- this.model = Buy2Win;
1808
- }
1809
- }
1810
-
1811
- class LegacyOrderFirestoreRepository extends OrderFirestoreRepository {
1812
- constructor(firestore) {
1813
- super(firestore);
1814
- this.firestore = firestore;
1815
- this.collectionName = 'legacyOrders';
2532
+ constructor({ firestore, interceptors, }) {
2533
+ super({
2534
+ firestore,
2535
+ collectionName: 'subscriptionPlans',
2536
+ model: SubscriptionPlan,
2537
+ interceptors,
2538
+ });
1816
2539
  }
1817
2540
  }
1818
2541
 
1819
2542
  class HomeFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
1820
- constructor(firestore) {
1821
- super();
1822
- this.firestore = firestore;
1823
- this.homeToFirestore = (home) => {
1824
- if (home.data?.data) {
1825
- home.data.data.discoverProducts = home.data.data.discoverProducts.map(this.homeCategoryGroupToPlain);
1826
- home.data.data.featuredProducts = home.data.data.featuredProducts.map(this.homeCategoryGroupToPlain);
1827
- home.data.data.verticalProducts = home.data.data.verticalProducts.map(this.homeCategoryGroupToPlain);
1828
- }
1829
- return home;
1830
- };
2543
+ constructor({ firestore, interceptors }) {
2544
+ super({
2545
+ firestore,
2546
+ collectionName: 'dms',
2547
+ model: Home,
2548
+ interceptors,
2549
+ });
1831
2550
  this.homeCategoryGroupToPlain = (homeCategoryGroup) => ({
1832
- category: homeCategoryGroup.category.toPlain(),
1833
- products: homeCategoryGroup.products.map((product) => product.toPlain()),
1834
- });
1835
- this.homeFromFirestore = (home) => {
1836
- if (home.data?.data) {
1837
- home.data.data.discoverProducts = home.data.data.discoverProducts.map(this.plainToHomeCategoryGroup);
1838
- home.data.data.featuredProducts = home.data.data.featuredProducts.map(this.plainToHomeCategoryGroup);
1839
- home.data.data.verticalProducts = home.data.data.verticalProducts.map(this.plainToHomeCategoryGroup);
1840
- home.data.createdAt =
1841
- home.data.createdAt instanceof Timestamp ? home.data.createdAt.toDate() : home.data.createdAt;
1842
- home.data.expiresAt =
1843
- home.data.expiresAt instanceof Timestamp ? home.data.expiresAt.toDate() : home.data.expiresAt;
1844
- }
1845
- return home;
1846
- };
2551
+ category: homeCategoryGroup?.category?.toPlain
2552
+ ? homeCategoryGroup?.category?.toPlain()
2553
+ : homeCategoryGroup?.category,
2554
+ products: homeCategoryGroup?.products
2555
+ ?.map((product) => (product?.toPlain ? product?.toPlain() : product))
2556
+ .filter(Boolean) || [],
2557
+ });
1847
2558
  this.plainToHomeCategoryGroup = (homeCategoryGroup) => ({
1848
- category: Category.toInstance(homeCategoryGroup.category),
1849
- products: homeCategoryGroup.products.map((product) => Product.toInstance(product)),
2559
+ category: Category.toInstance(homeCategoryGroup?.category),
2560
+ products: homeCategoryGroup.products?.map((product) => Product.toInstance(product)),
1850
2561
  });
1851
- this.collectionName = 'dms';
1852
- this.model = Home;
1853
2562
  }
1854
2563
  buildModelInstance() {
1855
2564
  const { fromFirestore, toFirestore } = super.buildModelInstance();
@@ -1864,14 +2573,47 @@ class HomeFirestoreRepository extends withCrudFirestore(withHelpers(withFirestor
1864
2573
  },
1865
2574
  };
1866
2575
  }
2576
+ homeToFirestore(home) {
2577
+ if (home.data?.data) {
2578
+ home.data.data.discoverProducts = home.data.data.discoverProducts?.map(this.homeCategoryGroupToPlain) || [];
2579
+ home.data.data.featuredProducts = home.data.data.featuredProducts?.map(this.homeCategoryGroupToPlain) || [];
2580
+ home.data.data.verticalProducts = home.data.data.verticalProducts?.map(this.homeCategoryGroupToPlain) || [];
2581
+ }
2582
+ return home;
2583
+ }
2584
+ homeFromFirestore(home) {
2585
+ if (home.data?.data) {
2586
+ home.data.data.discoverProducts = home.data.data.discoverProducts.map(this.plainToHomeCategoryGroup);
2587
+ home.data.data.featuredProducts = home.data.data.featuredProducts.map(this.plainToHomeCategoryGroup);
2588
+ home.data.data.verticalProducts = home.data.data.verticalProducts.map(this.plainToHomeCategoryGroup);
2589
+ home.data.createdAt =
2590
+ home.data.createdAt instanceof Timestamp ? home.data.createdAt.toDate() : home.data.createdAt;
2591
+ home.data.expiresAt =
2592
+ home.data.expiresAt instanceof Timestamp ? home.data.expiresAt.toDate() : home.data.expiresAt;
2593
+ }
2594
+ return home;
2595
+ }
2596
+ }
2597
+
2598
+ class ShopMenuFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
2599
+ constructor({ firestore, interceptors }) {
2600
+ super({
2601
+ firestore,
2602
+ collectionName: 'shopMenus',
2603
+ model: ShopMenu,
2604
+ interceptors,
2605
+ });
2606
+ }
1867
2607
  }
1868
2608
 
1869
- class ShopMenuFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
1870
- constructor(firestore) {
1871
- super();
1872
- this.firestore = firestore;
1873
- this.collectionName = 'shopMenus';
1874
- this.model = ShopMenu;
2609
+ class ShopSettingsFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
2610
+ constructor({ firestore, interceptors, }) {
2611
+ super({
2612
+ firestore,
2613
+ collectionName: 'shopSettings',
2614
+ model: ShopSettings,
2615
+ interceptors,
2616
+ });
1875
2617
  }
1876
2618
  }
1877
2619
 
@@ -1948,7 +2690,7 @@ class AttributeOptionHelper {
1948
2690
  }
1949
2691
  AttributeOptionHelper.FindByAttribute = (attributeName, fields) => {
1950
2692
  if (fields.includes(attributeName))
1951
- return { columnName: attributeName.toString(), attributeName };
2693
+ return { columnName: attributeName.toString(), attributeName, to: (value) => value, from: (value) => value };
1952
2694
  const field = fields.find((columnOption) => isObject(columnOption) && Object.keys(columnOption).includes(attributeName.toString()));
1953
2695
  const fieldOption = is(field)?.[attributeName];
1954
2696
  if (isNil(fieldOption))
@@ -1957,7 +2699,7 @@ AttributeOptionHelper.FindByAttribute = (attributeName, fields) => {
1957
2699
  return { columnName: attributeName.toString(), attributeName, fields: fieldOption };
1958
2700
  return { attributeName, columnName: attributeName.toString(), ...fieldOption };
1959
2701
  };
1960
- AttributeOptionHelper.CheckIsColumnOption = (fieldValue) => !!fieldValue.columnName;
2702
+ AttributeOptionHelper.CheckIsColumnOption = (fieldValue) => !!fieldValue?.columnName;
1961
2703
  AttributeOptionHelper.FindColumnOptionFromList = (columnName, fields) => {
1962
2704
  if (fields.includes(columnName))
1963
2705
  return { columnName, attributeName: columnName };
@@ -2050,25 +2792,26 @@ BindFilterQueryHelper.MakeGraphQLWhere = (filter, fields) => Object.keys(filter)
2050
2792
  }, {});
2051
2793
  BindFilterQueryHelper.BuildWhereSentence = (field, options, fields) => {
2052
2794
  const fieldSentenceOptions = AttributeOptionHelper.FindByAttribute(field, fields);
2053
- if (!Array.isArray(options) &&
2795
+ const isNestedField = !Array.isArray(options) &&
2054
2796
  isObject(options) &&
2055
2797
  isNil(options?.operator) &&
2056
2798
  isNil(options?.value) &&
2057
- isNil(fieldSentenceOptions?.to))
2799
+ isNil(fieldSentenceOptions?.to);
2800
+ if (isNestedField)
2058
2801
  return Object.keys(options).reduce((variables, key) => {
2059
2802
  const fieldOptions = AttributeOptionHelper.FindByAttribute(key, fieldSentenceOptions?.fields || fields);
2060
2803
  const columnName = fieldOptions.columnName;
2061
2804
  const columnFields = fieldOptions.fields;
2062
2805
  return {
2063
2806
  ...variables,
2064
- [columnName]: BindFilterQueryHelper.BuildWhereSentence(key, is(is(options)[key]), columnFields || []),
2807
+ [columnName]: BindFilterQueryHelper.BuildWhereSentence(key, is(is(options)[key]), fieldSentenceOptions?.fields || columnFields || fields),
2065
2808
  };
2066
2809
  }, {});
2067
2810
  if (!Array.isArray(options) && !isNil(fieldSentenceOptions.fields))
2068
2811
  return {
2069
2812
  [fieldSentenceOptions.fields[0]]: BindFilterQueryHelper.BuildOperatorSentence(options, fieldSentenceOptions),
2070
2813
  };
2071
- if (isObject(options) && !FilterOptionHelper.CheckIfIsFilterOption(options))
2814
+ if (!Array.isArray(options) && isObject(options) && !FilterOptionHelper.CheckIfIsFilterOption(options))
2072
2815
  options = Object.values(options)[0];
2073
2816
  return Array.isArray(options)
2074
2817
  ? options.reduce((whereSentence, option) => ({
@@ -2104,28 +2847,14 @@ GraphQLFieldHelper.ConvertModelFieldsToGraphQLFields = (fields) => {
2104
2847
  if (field === 'affected_rows')
2105
2848
  return field;
2106
2849
  const fieldName = Object.keys(field).shift();
2107
- const fieldValue = field[fieldName];
2850
+ const fieldValue = is(field[fieldName]);
2108
2851
  if (Array.isArray(fieldValue))
2109
2852
  return { [fieldName]: GraphQLFieldHelper.ConvertModelFieldsToGraphQLFields(fieldValue) };
2110
2853
  if (!AttributeOptionHelper.CheckIsColumnOption(fieldValue))
2111
- return null;
2112
- if (fieldValue.fields)
2113
- return !fieldValue.filters
2114
- ? {
2115
- [fieldValue.columnName || fieldName]: GraphQLFieldHelper.ConvertModelFieldsToGraphQLFields(fieldValue.fields),
2116
- }
2117
- : {
2118
- operation: fieldValue.columnName || fieldName,
2119
- fields: GraphQLFieldHelper.ConvertModelFieldsToGraphQLFields(fieldValue.fields),
2120
- variables: {
2121
- [`${fieldValue.columnName}_where`]: {
2122
- name: 'where',
2123
- type: fieldValue.filters.filterType,
2124
- value: BindFilterQueryHelper.MakeGraphQLWhere(fieldValue.filters.filters, fieldValue.fields),
2125
- required: true,
2126
- },
2127
- },
2128
- };
2854
+ return;
2855
+ const isNestedField = !!fieldValue.fields;
2856
+ if (isNestedField)
2857
+ return GraphQLFieldHelper.ConvertNestedFieldsToGraphQLFields(fieldName, fieldValue);
2129
2858
  return fieldValue.columnName;
2130
2859
  })
2131
2860
  .filter((field) => !!field);
@@ -2150,7 +2879,10 @@ GraphQLFieldHelper.ConvertFieldValueFrom = (data, fields) => Object.keys(data).r
2150
2879
  }
2151
2880
  if (!!from)
2152
2881
  return { ...result, [attributeName]: from(data[columnName], data) };
2153
- return { ...result, [attributeName]: parseDateTime(data[columnName]?.toString()) };
2882
+ return {
2883
+ ...result,
2884
+ [attributeName]: isString(data[columnName]) ? parseDateTime(data[columnName].toString()) : data[columnName],
2885
+ };
2154
2886
  }, {});
2155
2887
  GraphQLFieldHelper.ConvertFieldValueTo = (instance, fields, update = false) => {
2156
2888
  const data = instance.toPlain?.() || instance;
@@ -2166,10 +2898,13 @@ GraphQLFieldHelper.ConvertFieldValueTo = (instance, fields, update = false) => {
2166
2898
  if (!!foreignKeyColumn &&
2167
2899
  !isEmpty(foreignKeyColumn) &&
2168
2900
  !Object.keys(foreignKeyColumn).filter((key) => !is(data[attributeName])?.[key]).length)
2169
- return Object.keys(foreignKeyColumn).reduce((object, current) => ({
2170
- ...object,
2171
- [foreignKeyColumn[current]]: data[attributeName]?.[current],
2172
- }), { ...result });
2901
+ return Object.keys(foreignKeyColumn).reduce((object, current) => {
2902
+ const { columnName: foreignColumnName } = AttributeOptionHelper.FindByAttribute(foreignKeyColumn[current], fields);
2903
+ return {
2904
+ ...object,
2905
+ [foreignColumnName]: data[attributeName]?.[current],
2906
+ };
2907
+ }, { ...result });
2173
2908
  if (update &&
2174
2909
  isObject(data[attributeName]) &&
2175
2910
  !isNil(attributeFields) &&
@@ -2202,6 +2937,25 @@ GraphQLFieldHelper.ConvertFieldValueTo = (instance, fields, update = false) => {
2202
2937
  return { ...result, [columnName]: data[attributeName] };
2203
2938
  }, {});
2204
2939
  };
2940
+ GraphQLFieldHelper.ConvertNestedFieldsToGraphQLFields = (fieldName, fieldValue) => {
2941
+ const hasCustomFilters = !!fieldValue.filters;
2942
+ if (hasCustomFilters)
2943
+ return {
2944
+ operation: fieldValue.columnName || fieldName,
2945
+ fields: GraphQLFieldHelper.ConvertModelFieldsToGraphQLFields(fieldValue.fields),
2946
+ variables: {
2947
+ [`${fieldValue.columnName}_where`]: {
2948
+ name: 'where',
2949
+ type: fieldValue.filters.filterType,
2950
+ value: BindFilterQueryHelper.MakeGraphQLWhere(fieldValue.filters.filters, fieldValue.fields),
2951
+ required: true,
2952
+ },
2953
+ },
2954
+ };
2955
+ return {
2956
+ [fieldValue.columnName || fieldName]: GraphQLFieldHelper.ConvertModelFieldsToGraphQLFields(fieldValue.fields),
2957
+ };
2958
+ };
2205
2959
 
2206
2960
  const withCreateHasuraGraphQL = (MixinBase) => {
2207
2961
  return class CreateHasuraGraphQLMixin extends MixinBase {
@@ -2212,6 +2966,7 @@ const withCreateHasuraGraphQL = (MixinBase) => {
2212
2966
  this.insertGraphQLObjectType = options?.insertGraphQLObjectType || `${this.tableName}_insert_input`;
2213
2967
  }
2214
2968
  async create(data) {
2969
+ this.logger = DebugHelper.from(this, 'create');
2215
2970
  const newData = await this.save(this.model.toInstance(data));
2216
2971
  return this.model.toInstance(newData);
2217
2972
  }
@@ -2222,10 +2977,10 @@ const withCreateHasuraGraphQL = (MixinBase) => {
2222
2977
  const columnOptions = Object.values(field).shift();
2223
2978
  return (AttributeOptionHelper.CheckIsColumnOption(columnOptions) &&
2224
2979
  columnOptions.foreignKeyColumn && [
2225
- ...Object.values(columnOptions.foreignKeyColumn),
2980
+ ...Object.values(columnOptions.foreignKeyColumn).map((foreignKeyName) => AttributeOptionHelper.FindByAttribute(foreignKeyName, this.fields)?.columnName),
2226
2981
  {
2227
- [columnOptions.columnName]: Object.keys(columnOptions.foreignKeyColumn).map((foreignKeyField) => AttributeOptionHelper.FindByAttribute(foreignKeyField, columnOptions?.fields)?.columnName ||
2228
- foreignKeyField),
2982
+ [columnOptions.columnName]: Object.keys(columnOptions.foreignKeyColumn).map((foreignKeyField) => AttributeOptionHelper.FindByAttribute(foreignKeyField, columnOptions?.fields)
2983
+ ?.columnName || foreignKeyField),
2229
2984
  },
2230
2985
  ]);
2231
2986
  })
@@ -2247,9 +3002,11 @@ const withDeleteHasuraGraphQL = (MixinBase) => {
2247
3002
  this.deleteGraphQLOperation = options?.deleteGraphQLOperation || `delete_${this.tableName}_by_pk`;
2248
3003
  }
2249
3004
  async delete(identifiers) {
3005
+ this.logger = DebugHelper.from(this, 'delete');
2250
3006
  const instance = this.model.toInstance(identifiers);
2251
3007
  await this.mutation(this.deleteGraphQLOperation, this.model.identifiersFields.map((field) => AttributeOptionHelper.FindByAttribute(field, this.fields).columnName), this.model.identifiersFields.reduce((ids, identifier) => {
2252
- if (isNil(instance[identifier]))
3008
+ const identifierBinded = identifier;
3009
+ if (isNil(instance.identifier[identifierBinded]))
2253
3010
  return ids;
2254
3011
  const columnOption = AttributeOptionHelper.FindByAttribute(identifier, this.fields);
2255
3012
  const value = columnOption.to(identifiers[identifier], instance);
@@ -2276,15 +3033,19 @@ const withHasuraGraphQL = (MixinBase) => {
2276
3033
  this.authOptions = options.authOptions;
2277
3034
  this.model = options.model;
2278
3035
  this.fields = options.fields || this.model.identifiersFields;
3036
+ this.logger = DebugHelper.from(this);
2279
3037
  }
2280
3038
  get headers() {
2281
3039
  return {
2282
3040
  'Content-Type': 'application/json',
2283
- ...(isNil(this.authOptions.authToken) ? {} : { Authorization: this.authOptions.authToken }),
2284
- ...(isNil(this.authOptions.adminSecret) ? {} : { 'X-Hasura-Admin-Secret': this.authOptions.adminSecret }),
2285
- ...(isNil(this.authOptions.authRole)
3041
+ ...(isNil(this.authOptions?.authToken) ? {} : { Authorization: this.authOptions?.authToken }),
3042
+ ...(isNil(this.authOptions?.adminSecret) ? {} : { 'X-Hasura-Admin-Secret': this.authOptions?.adminSecret }),
3043
+ ...(isNil(this.authOptions?.authRole)
2286
3044
  ? {}
2287
- : { 'X-Hasura-Role': this.authOptions.authRole.role, 'X-Hasura-User-Id': this.authOptions.authRole.userId }),
3045
+ : {
3046
+ 'X-Hasura-Role': this.authOptions.authRole.role,
3047
+ 'X-Hasura-User-Id': this.authOptions?.authRole?.userId,
3048
+ }),
2288
3049
  };
2289
3050
  }
2290
3051
  async mutation(operation, fields, variables) {
@@ -2296,27 +3057,28 @@ const withHasuraGraphQL = (MixinBase) => {
2296
3057
  return this.fetch(resultQuery);
2297
3058
  }
2298
3059
  async query(operation, fields, variables) {
2299
- const resultQuery = GraphQLFieldHelper.CheckIsGraphQLParams(operation)
2300
- ? query$1(operation.map((option) => ({
2301
- operation: option.operation,
2302
- variables: option.variables,
2303
- fields: GraphQLFieldHelper.ConvertModelFieldsToGraphQLFields(option.fields),
2304
- })))
2305
- : query$1({
2306
- operation,
2307
- variables,
2308
- fields: GraphQLFieldHelper.ConvertModelFieldsToGraphQLFields(fields),
2309
- });
2310
- return this.fetch(resultQuery);
3060
+ const builded = this.buildHasuraQueryFields({
3061
+ operation,
3062
+ fields: fields,
3063
+ variables,
3064
+ });
3065
+ const interpected = (await this.interceptors?.request?.(builded)) || builded;
3066
+ const resultQuery = query$1(interpected);
3067
+ const result = await this.fetch(resultQuery);
3068
+ return (await this.interceptors?.response?.(result, interpected)) || result;
2311
3069
  }
2312
3070
  async fetch(params) {
3071
+ this.logger.with('params').log(params);
2313
3072
  const headers = this.headers;
2314
- const response = await axios.post(`${this.endpoint}`, params, {
3073
+ const { data: result } = await axios({
3074
+ url: `${this.endpoint}`,
3075
+ method: 'POST',
3076
+ data: params,
2315
3077
  headers,
2316
3078
  });
2317
- const result = await response.data;
2318
3079
  if (!isNil(result.errors))
2319
3080
  throw new Error(JSON.stringify(result.errors));
3081
+ this.logger.with('returns').log(result);
2320
3082
  return result.data;
2321
3083
  }
2322
3084
  getAttributeGraphQLTypeOf(value) {
@@ -2342,13 +3104,26 @@ const withHasuraGraphQL = (MixinBase) => {
2342
3104
  return value;
2343
3105
  return date;
2344
3106
  }
2345
- convertDataFromHasura(data) {
2346
- const plain = GraphQLFieldHelper.ConvertFieldValueFrom(data, this.fields);
3107
+ convertDataFromHasura(data, fields) {
3108
+ const plain = GraphQLFieldHelper.ConvertFieldValueFrom(data, fields || this.fields);
2347
3109
  return this.model.toInstance(plain);
2348
3110
  }
2349
3111
  convertDataToHasura(instance, update = false) {
2350
3112
  return GraphQLFieldHelper.ConvertFieldValueTo(instance, this.fields, update);
2351
3113
  }
3114
+ buildHasuraQueryFields({ operation, fields, variables, }) {
3115
+ return GraphQLFieldHelper.CheckIsGraphQLParams(operation)
3116
+ ? operation.map((option) => ({
3117
+ operation: option.operation,
3118
+ variables: option.variables,
3119
+ fields: GraphQLFieldHelper.ConvertModelFieldsToGraphQLFields(option.fields),
3120
+ }))
3121
+ : {
3122
+ operation,
3123
+ variables,
3124
+ fields: GraphQLFieldHelper.ConvertModelFieldsToGraphQLFields(fields),
3125
+ };
3126
+ }
2352
3127
  };
2353
3128
  };
2354
3129
 
@@ -2371,6 +3146,7 @@ const withUpdateHasuraGraphQL = (MixinBase) => {
2371
3146
  this.updateGraphQLPKType = options?.updateGraphQLPKType || `${this.tableName}_pk_columns_input`;
2372
3147
  }
2373
3148
  async update(data) {
3149
+ this.logger = DebugHelper.from(this, 'update');
2374
3150
  const plainData = this.paramsToPlain(data);
2375
3151
  await this.mutation(this.updateGraphQLOperation, this.model.identifiersFields.map((field) => AttributeOptionHelper.FindByAttribute(field, this.fields).columnName), {
2376
3152
  _set: {
@@ -2396,10 +3172,11 @@ const withUpdateHasuraGraphQL = (MixinBase) => {
2396
3172
  getUpdateModelKeys(data) {
2397
3173
  const instance = this.model.toInstance(data);
2398
3174
  return this.model.identifiersFields.reduce((ids, identifier) => {
2399
- if (isNil(instance[identifier]))
3175
+ const identifierBinded = identifier;
3176
+ if (isNil(instance.identifier[identifierBinded]))
2400
3177
  return ids;
2401
- const columnOption = AttributeOptionHelper.FindByAttribute(identifier, this.fields);
2402
- const value = columnOption?.to?.(data[identifier], instance) || data[columnOption.attributeName];
3178
+ const columnOption = AttributeOptionHelper.FindByAttribute(identifierBinded, this.fields);
3179
+ const value = columnOption?.to?.(data[identifierBinded], instance) || data[columnOption.attributeName];
2403
3180
  return {
2404
3181
  ...ids,
2405
3182
  [columnOption.columnName]: value,
@@ -2417,9 +3194,11 @@ const withGetHasuraGraphQL = (MixinBase) => {
2417
3194
  this.getGraphQLOperation = options?.getGraphQLOperation || `${this.tableName}_by_pk`;
2418
3195
  }
2419
3196
  async get(identifiers) {
3197
+ this.logger = DebugHelper.from(this, 'get');
2420
3198
  const instance = this.model.toInstance(identifiers);
2421
3199
  const result = await this.query(this.getGraphQLOperation, this.fields, this.model.identifiersFields.reduce((ids, identifier) => {
2422
- if (isNil(instance[identifier]))
3200
+ const identifierBinded = identifier;
3201
+ if (isNil(instance[identifierBinded]))
2423
3202
  return ids;
2424
3203
  const columnOption = AttributeOptionHelper.FindByAttribute(identifier, this.fields);
2425
3204
  const value = columnOption?.to?.(identifiers[identifier], instance) ||
@@ -2443,44 +3222,150 @@ const withGetHasuraGraphQL = (MixinBase) => {
2443
3222
 
2444
3223
  const withFindHasuraGraphQL = (MixinBase) => {
2445
3224
  return class FindHasuraGraphQLMixin extends MixinBase {
2446
- async find(options) {
2447
- const { filters, limits, orderBy } = options || {};
3225
+ constructor() {
3226
+ super(...arguments);
3227
+ this.bindOrderByAttributes = (orderBy, fields) => Object.keys(orderBy).reduce((acc, current) => [
3228
+ ...acc,
3229
+ {
3230
+ [AttributeOptionHelper.FindByAttribute(current, fields)
3231
+ .columnName]: orderBy[current] === 'asc'
3232
+ ? 'asc_nulls_last'
3233
+ : 'desc_nulls_last',
3234
+ },
3235
+ ], []);
3236
+ this.bindAggretageAttributes = (aggregates, fields) => [
3237
+ ...(aggregates?.minimal?.length
3238
+ ? [
3239
+ {
3240
+ min: this.bindAttributesToColumns(aggregates?.minimal, fields),
3241
+ },
3242
+ ]
3243
+ : []),
3244
+ ...(aggregates?.maximum?.length
3245
+ ? [
3246
+ {
3247
+ max: this.bindAttributesToColumns(aggregates?.maximum, fields),
3248
+ },
3249
+ ]
3250
+ : []),
3251
+ ];
3252
+ this.bindDistinctAttributes = (distinct, fields) => this.bindAttributesToColumns(distinct, fields);
3253
+ this.bindAttributesToColumns = (attributes, fields) => attributes.map((attr) => AttributeOptionHelper.FindByAttribute(attr.toString().split('.').pop(), fields)?.columnName || attr);
3254
+ }
3255
+ async find(params) {
3256
+ this.logger = DebugHelper.from(this, 'find');
3257
+ const { filters, limits, orderBy, options } = params || {};
3258
+ const enableCount = options?.enableCount ?? true;
3259
+ const variablesFilters = isNil(filters)
3260
+ ? {}
3261
+ : {
3262
+ where: {
3263
+ value: BindFilterQueryHelper.MakeGraphQLWhere(filters, this.fields),
3264
+ type: `${this.tableName}_bool_exp`,
3265
+ required: true,
3266
+ },
3267
+ };
2448
3268
  const variablesCount = {
2449
- ...(isNil(orderBy) ? {} : { order_by: { type: `${this.tableName}_order_by!`, list: true, value: orderBy } }),
2450
- ...(isNil(filters)
3269
+ ...(isNil(orderBy)
2451
3270
  ? {}
2452
3271
  : {
2453
- where: {
2454
- value: BindFilterQueryHelper.MakeGraphQLWhere(filters, this.fields),
2455
- type: `${this.tableName}_bool_exp`,
2456
- required: true,
3272
+ order_by: {
3273
+ type: `${this.tableName}_order_by!`,
3274
+ list: true,
3275
+ value: this.bindOrderByAttributes(orderBy, this.fields),
2457
3276
  },
2458
3277
  }),
3278
+ ...variablesFilters,
2459
3279
  };
2460
3280
  const variables = {
2461
3281
  ...(isNil(limits) ? {} : limits),
2462
3282
  ...variablesCount,
2463
3283
  };
3284
+ const aggregateFields = [
3285
+ ...(enableCount ? ['count'] : []),
3286
+ ...this.bindAggretageAttributes(params.options, this.fields),
3287
+ ];
2464
3288
  const result = await this.query([
2465
3289
  {
2466
3290
  operation: this.tableName,
2467
- fields: options.fields
2468
- ? options.fields
3291
+ fields: params.fields
3292
+ ? params.fields
2469
3293
  .map((fieldName) => this.fields.find((fieldOption) => fieldOption === fieldName) ??
2470
3294
  this.fields.find((fieldOption) => Object.keys(fieldOption).shift() === fieldName))
2471
3295
  .filter(Boolean)
2472
3296
  : this.fields,
2473
3297
  variables,
2474
3298
  },
2475
- {
2476
- operation: `${this.tableName}_aggregate`,
2477
- fields: [{ aggregate: ['count'] }],
2478
- variables: variablesCount,
2479
- },
3299
+ ...(aggregateFields.length > 0
3300
+ ? [
3301
+ {
3302
+ operation: `${this.tableName}_aggregate`,
3303
+ fields: [
3304
+ {
3305
+ aggregate: aggregateFields,
3306
+ },
3307
+ ],
3308
+ variables: variablesCount,
3309
+ },
3310
+ ]
3311
+ : []),
3312
+ ...((!params.limits?.offset &&
3313
+ params.options?.distinct?.map((distinct) => {
3314
+ const distinctOption = this.fields.find((fieldOption) => fieldOption === distinct) ??
3315
+ this.fields.find((fieldOption) => Object.keys(fieldOption).shift() === distinct);
3316
+ const fieldName = Object.values(distinctOption).shift()?.columnName || distinct;
3317
+ return {
3318
+ operation: {
3319
+ name: `${this.tableName}`,
3320
+ alias: `${this.tableName}_${distinct.toString()}_distinct`,
3321
+ },
3322
+ fields: [distinctOption],
3323
+ variables: {
3324
+ ...variablesFilters,
3325
+ [`${this.tableName}_${fieldName}_distinct`]: {
3326
+ type: `${this.tableName}_select_column!`,
3327
+ list: true,
3328
+ value: fieldName,
3329
+ name: 'distinct_on',
3330
+ },
3331
+ },
3332
+ };
3333
+ })) ||
3334
+ []),
2480
3335
  ]);
2481
3336
  const data = result[this.tableName].map((row) => this.convertDataFromHasura(row));
2482
- const count = result[`${this.tableName}_aggregate`].aggregate.count;
2483
- return { count, data };
3337
+ return {
3338
+ data,
3339
+ count: enableCount ? result[`${this.tableName}_aggregate`].aggregate.count : Infinity,
3340
+ ...(options?.minimal?.length
3341
+ ? {
3342
+ minimal: options.minimal.reduce((minimals, current) => ({
3343
+ ...minimals,
3344
+ ...set(minimals, current, result[`${this.tableName}_aggregate`].aggregate.min[AttributeOptionHelper.FindByAttribute(current.toString().split('.').pop(), this.fields)?.columnName || current]),
3345
+ }), {}),
3346
+ }
3347
+ : {}),
3348
+ ...(options?.maximum?.length
3349
+ ? {
3350
+ maximum: options.maximum.reduce((maximums, current) => ({
3351
+ ...maximums,
3352
+ ...set(maximums, current, result[`${this.tableName}_aggregate`].aggregate.max[AttributeOptionHelper.FindByAttribute(current.toString().split('.').pop(), this.fields)?.columnName || current]),
3353
+ }), {}),
3354
+ }
3355
+ : {}),
3356
+ ...(!params.limits?.offset &&
3357
+ options?.distinct?.length && {
3358
+ distinct: options?.distinct.reduce((distinct, current) => {
3359
+ const distinctOption = this.fields.find((fieldOption) => fieldOption === current) ??
3360
+ this.fields.find((fieldOption) => Object.keys(fieldOption).shift() === current);
3361
+ const fieldName = Object.values(distinctOption).shift()?.columnName || current;
3362
+ return {
3363
+ ...distinct,
3364
+ [current.toString()]: result[`${this.tableName}_${current.toString()}_distinct`].map((obj) => obj[fieldName]),
3365
+ };
3366
+ }, {}),
3367
+ }),
3368
+ };
2484
3369
  }
2485
3370
  };
2486
3371
  };
@@ -2519,8 +3404,148 @@ class VariantHasuraGraphQL extends Variant {
2519
3404
  }
2520
3405
  }
2521
3406
 
3407
+ class CategoryCollectionChildrenHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
3408
+ constructor({ endpoint, authOptions, interceptors, }) {
3409
+ super({
3410
+ tableName: 'category_collection_children',
3411
+ model: CategoryCollectionChildren,
3412
+ endpoint,
3413
+ authOptions,
3414
+ interceptors,
3415
+ fields: [
3416
+ { collectionId: { columnName: 'collection_id' } },
3417
+ { categoryId: { columnName: 'category_id' } },
3418
+ 'name',
3419
+ 'slug',
3420
+ 'reference',
3421
+ { parentCollectionId: { columnName: 'parent_collection_id' } },
3422
+ { parentCategoryId: { columnName: 'parent_category_id' } },
3423
+ {
3424
+ parent: {
3425
+ columnName: 'parent',
3426
+ foreignKeyColumn: { collectionId: 'parentCollectionId', categoryId: 'parentCategoryId' },
3427
+ fields: [
3428
+ { collectionId: { columnName: 'collection_id' } },
3429
+ { categoryId: { columnName: 'category_id' } },
3430
+ 'name',
3431
+ 'slug',
3432
+ 'reference',
3433
+ { parentCollectionId: { columnName: 'parent_collection_id' } },
3434
+ { parentCategoryId: { columnName: 'parent_category_id' } },
3435
+ ],
3436
+ },
3437
+ },
3438
+ ],
3439
+ });
3440
+ }
3441
+ }
3442
+
3443
+ class CategoryFilterHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
3444
+ constructor({ endpoint, authOptions, interceptors, }) {
3445
+ super({
3446
+ tableName: 'category_filter',
3447
+ model: CategoryFilter,
3448
+ endpoint,
3449
+ authOptions,
3450
+ interceptors,
3451
+ fields: [
3452
+ 'id',
3453
+ { filterId: { columnName: 'filter_id' } },
3454
+ { categoryId: { columnName: 'category_id' } },
3455
+ {
3456
+ filter: {
3457
+ columnName: 'filter',
3458
+ foreignKeyColumn: { id: 'filterId' },
3459
+ fields: [
3460
+ 'id',
3461
+ 'description',
3462
+ 'slug',
3463
+ 'enabled',
3464
+ { createdAt: { columnName: 'created_at' } },
3465
+ { updatedAt: { columnName: 'updated_at' } },
3466
+ {
3467
+ options: {
3468
+ columnName: 'options',
3469
+ foreignKeyColumn: { filterId: 'id' },
3470
+ fields: [
3471
+ 'id',
3472
+ { filterId: { columnName: 'filter_id' } },
3473
+ 'description',
3474
+ { createdAt: { columnName: 'created_at' } },
3475
+ { updatedAt: { columnName: 'updated_at' } },
3476
+ ],
3477
+ },
3478
+ },
3479
+ ],
3480
+ },
3481
+ },
3482
+ {
3483
+ category: {
3484
+ columnName: 'category',
3485
+ foreignKeyColumn: { id: 'categoryId' },
3486
+ fields: [
3487
+ 'id',
3488
+ 'description',
3489
+ {
3490
+ products: {
3491
+ columnName: 'products',
3492
+ fields: ['product_id'],
3493
+ from: (value) => value.map((product) => product.product_id.toString()),
3494
+ to: (productIds) => productIds.map((productId) => ({
3495
+ product_id: +productId,
3496
+ })),
3497
+ },
3498
+ },
3499
+ {
3500
+ childrenProducts: {
3501
+ columnName: 'children_products',
3502
+ foreignKeyColumn: { category_id: 'id' },
3503
+ fields: [
3504
+ 'id',
3505
+ 'name',
3506
+ 'slug',
3507
+ {
3508
+ categories: {
3509
+ columnName: 'categories',
3510
+ fields: ['category_id'],
3511
+ bindPersistData: (value) => ({
3512
+ categories: { data: value.map((category) => ({ category_id: +category })) },
3513
+ }),
3514
+ to: (categories) => categories.map((categoryId) => +categoryId),
3515
+ from: (categories) => categories?.map((category) => category?.category_id?.toString()) || [],
3516
+ },
3517
+ },
3518
+ ],
3519
+ },
3520
+ },
3521
+ ],
3522
+ },
3523
+ },
3524
+ ],
3525
+ });
3526
+ }
3527
+ deleteByCategory(categoryId) {
3528
+ return this.mutation('delete_category_filter', ['affected_rows'], {
3529
+ where: {
3530
+ type: 'category_filter_bool_exp',
3531
+ required: true,
3532
+ value: { category_id: { _eq: categoryId } },
3533
+ },
3534
+ });
3535
+ }
3536
+ deleteByCategoryAndFilter(categoryId, filterId) {
3537
+ return this.mutation('delete_category_filter', ['affected_rows'], {
3538
+ where: {
3539
+ type: 'category_filter_bool_exp',
3540
+ required: true,
3541
+ value: { category_id: { _eq: categoryId }, filter_id: { _eq: filterId } },
3542
+ },
3543
+ });
3544
+ }
3545
+ }
3546
+
2522
3547
  class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
2523
- constructor({ endpoint, authOptions, interceptors, }, productRepository) {
3548
+ constructor({ endpoint, authOptions, interceptors, }, productRepository, categoryFilterRepository) {
2524
3549
  super({
2525
3550
  tableName: 'category',
2526
3551
  model: Category,
@@ -2535,6 +3560,7 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
2535
3560
  'image',
2536
3561
  'published',
2537
3562
  'shop',
3563
+ { shops: { columnName: 'shops', type: HasuraGraphQLColumnType.Jsonb } },
2538
3564
  'slug',
2539
3565
  { brandCategory: { columnName: 'brand_category' } },
2540
3566
  { brandCategoryBanner: { columnName: 'brand_banner' } },
@@ -2563,7 +3589,17 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
2563
3589
  },
2564
3590
  },
2565
3591
  },
2566
- 'filters',
3592
+ {
3593
+ filters: {
3594
+ columnName: 'filters',
3595
+ foreignKeyColumn: { filter_id: 'id' },
3596
+ fields: [{ filter: ['id', 'description', 'slug', 'enabled'] }],
3597
+ bindPersistData: (value) => ({
3598
+ filters: { data: value.map((filter) => ({ filter_id: filter.id })) },
3599
+ }),
3600
+ from: (filters) => filters?.map((filter) => filter?.filter) || [],
3601
+ },
3602
+ },
2567
3603
  { createdAt: { columnName: 'created_at' } },
2568
3604
  { updatedAt: { columnName: 'updated_at' } },
2569
3605
  {
@@ -2585,39 +3621,77 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
2585
3621
  }),
2586
3622
  },
2587
3623
  },
3624
+ { isCollection: { columnName: 'is_collection' } },
3625
+ { isWishlist: { columnName: 'is_wishlist' } },
3626
+ 'reference',
3627
+ { parentId: { columnName: 'parent_id' } },
3628
+ {
3629
+ parent: {
3630
+ columnName: 'parent',
3631
+ foreignKeyColumn: { id: 'parentId' },
3632
+ fields: ['id', 'name', 'reference', 'slug'],
3633
+ },
3634
+ },
2588
3635
  ],
2589
3636
  });
2590
3637
  this.productRepository = productRepository;
3638
+ this.categoryFilterRepository = categoryFilterRepository;
2591
3639
  }
2592
3640
  async create(params) {
2593
3641
  const { metadata, ...data } = params;
2594
- return super.create({ ...data, metadata: metadata || { description: null, title: null } });
3642
+ return super.create({ ...data, isWishlist: false, metadata: metadata || { description: null, title: null } });
2595
3643
  }
2596
3644
  async get(identifiers) {
2597
3645
  return Number.isNaN(+identifiers.id)
2598
- ? (await this.find({ filters: { firestoreId: identifiers.id } })).data?.[0]
3646
+ ? (await this.find({ filters: { firestoreId: identifiers.id }, options: { enableCount: false } })).data?.[0]
2599
3647
  : super.get(identifiers);
2600
3648
  }
2601
3649
  async update(params) {
2602
- const { products, id: checkId, metadata, ...data } = params;
3650
+ const { products, id: checkId, metadata, filters, ...data } = params;
2603
3651
  const plainData = this.paramsToPlain({ id: checkId });
2604
3652
  const id = await this.getId(plainData.id);
2605
- const category = await super.update({ id, ...data });
3653
+ const category = await super.update({ id, ...data, isWishlist: false });
2606
3654
  category.products = products && (await this.updateProducts(+id, { products }));
2607
3655
  category.metadata = metadata && (await this.updateMetadata(+id, { metadata }));
3656
+ category.filters = filters && (await this.updateFilters(+id, { filters }));
2608
3657
  return category;
2609
3658
  }
2610
3659
  async getCategoryBySlug(slug, shop) {
2611
3660
  if (!slug)
2612
3661
  return null;
2613
- const { data, count } = await this.find({ filters: { slug, shop, published: true } });
2614
- if (count > 1)
2615
- throw new DuplicatedResultsError('Query returned duplicated values');
2616
- if (!count)
3662
+ const { data } = await this.find({
3663
+ filters: {
3664
+ slug,
3665
+ shops: { operator: Where.IN, value: [shop] },
3666
+ published: { operator: Where.EQUALS, value: true },
3667
+ isWishlist: { operator: Where.EQUALS, value: false },
3668
+ },
3669
+ options: {
3670
+ enableCount: false,
3671
+ },
3672
+ });
3673
+ if (!data.length)
2617
3674
  throw new NotFoundError(`Category with slug ${slug} not found`);
3675
+ if (data.length > 1)
3676
+ throw new DuplicatedResultsError('Query returned duplicated values');
2618
3677
  return data.shift();
2619
3678
  }
2620
- async getCategoriesForHome(categoryIds, limit = 4) {
3679
+ async getCategoryByShop(shop) {
3680
+ if (!shop)
3681
+ return;
3682
+ const { data } = await this.find({
3683
+ filters: {
3684
+ shops: { operator: Where.IN, value: [shop] },
3685
+ published: { operator: Where.EQUALS, value: true },
3686
+ isWishlist: { operator: Where.EQUALS, value: false },
3687
+ },
3688
+ options: {
3689
+ enableCount: false,
3690
+ },
3691
+ });
3692
+ return data;
3693
+ }
3694
+ async getCategoriesForHome(categoryIds, limit = 4, gender) {
2621
3695
  if (!categoryIds?.length)
2622
3696
  return [];
2623
3697
  const categoriesFirestore = categoryIds.filter((categoryId) => Number.isNaN(+categoryId));
@@ -2635,7 +3709,7 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
2635
3709
  return [];
2636
3710
  const homeSections = await Promise.all(categories.map(async (category) => ({
2637
3711
  category,
2638
- products: await this.mountCategory(category, { limit, hasStock: true }),
3712
+ products: await this.mountCategory(category, { limit, hasStock: true, gender }),
2639
3713
  })));
2640
3714
  return homeSections;
2641
3715
  }
@@ -2648,6 +3722,7 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
2648
3722
  id: { operator: Where.IN, value: category.products },
2649
3723
  published: true,
2650
3724
  ...(options?.hasStock ? { stock: { quantity: { operator: Where.GT, value: 0 } } } : {}),
3725
+ ...(options?.gender ? { tags: { operator: Where.IN, value: [options?.gender] } } : {}),
2651
3726
  },
2652
3727
  fields: [
2653
3728
  'id',
@@ -2673,67 +3748,254 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
2673
3748
  'tags',
2674
3749
  'type',
2675
3750
  'shoppingCount',
3751
+ 'gender',
3752
+ 'createdAt',
2676
3753
  ],
2677
3754
  ...(options?.limit ? { limits: { limit: options?.limit } } : {}),
3755
+ options: { enableCount: false },
3756
+ });
3757
+ products.push(...productsData);
3758
+ return products;
3759
+ }
3760
+ async getId(id) {
3761
+ if (!Number.isNaN(+id))
3762
+ return id;
3763
+ const { data } = await this.find({ filters: { firestoreId: id }, options: { enableCount: false } });
3764
+ if (data?.[0]?.id)
3765
+ return data?.[0]?.id;
3766
+ throw new NotFoundError(`Category with id ${id} not found`);
3767
+ }
3768
+ async updateProducts(categoryId, { products }) {
3769
+ if ('action' in products && products.action === 'remove') {
3770
+ await this.mutation('delete_category_product', ['affected_rows'], {
3771
+ where: {
3772
+ type: 'category_product_bool_exp',
3773
+ required: true,
3774
+ value: { category_id: { _eq: categoryId } },
3775
+ },
3776
+ });
3777
+ return [];
3778
+ }
3779
+ const plainData = this.paramsToPlain({ products });
3780
+ if (!plainData.products || plainData.products.length <= 0)
3781
+ return [];
3782
+ await this.mutation('delete_category_product', ['affected_rows'], {
3783
+ where: {
3784
+ type: 'category_product_bool_exp',
3785
+ required: true,
3786
+ value: { category_id: { _eq: categoryId } },
3787
+ },
3788
+ });
3789
+ await this.mutation('insert_category_product', ['affected_rows'], {
3790
+ objects: {
3791
+ type: '[category_product_insert_input!]',
3792
+ required: true,
3793
+ value: plainData.products.map((productId) => ({ category_id: categoryId, product_id: productId })),
3794
+ },
3795
+ });
3796
+ return plainData.products;
3797
+ }
3798
+ async updateMetadata(categoryId, { metadata }) {
3799
+ const plainData = this.paramsToPlain({ metadata });
3800
+ if (!plainData.metadata)
3801
+ return null;
3802
+ await this.mutation('update_category_metadata_by_pk', ['category_id'], {
3803
+ pk_columns: {
3804
+ value: { category_id: categoryId },
3805
+ type: 'category_metadata_pk_columns_input',
3806
+ required: true,
3807
+ },
3808
+ _set: {
3809
+ value: omit(metadata, ['category_id']),
3810
+ type: 'category_metadata_set_input',
3811
+ required: true,
3812
+ },
3813
+ });
3814
+ return plainData.metadata;
3815
+ }
3816
+ async updateFilters(categoryId, { filters }) {
3817
+ if ('action' in filters && filters.action === 'remove' && filters.value.length) {
3818
+ for (let i = 0; i < filters.value.length; i++) {
3819
+ await this.categoryFilterRepository.deleteByCategoryAndFilter(categoryId, filters.value[i].id);
3820
+ }
3821
+ return [];
3822
+ }
3823
+ if ('action' in filters && filters.action === 'merge' && filters.value.length) {
3824
+ let filtersList = [];
3825
+ const currentFilters = await this.categoryFilterRepository
3826
+ .find({
3827
+ filters: {
3828
+ categoryId,
3829
+ },
3830
+ })
3831
+ .then((res) => res.data);
3832
+ const currentFiltersId = currentFilters.map((f) => f.id);
3833
+ const filtersUpdatedId = filters.value.map((f) => f.id);
3834
+ const filterToBeDeleted = currentFiltersId.filter((c) => !filtersUpdatedId.includes(c));
3835
+ const filterToBeInserted = filtersUpdatedId.filter((c) => !currentFiltersId.includes(c));
3836
+ for (const filter of filterToBeDeleted) {
3837
+ const index = currentFilters.findIndex((f) => f.id == filter);
3838
+ if (index != -1) {
3839
+ currentFilters.splice(index, 1);
3840
+ }
3841
+ await this.categoryFilterRepository.deleteByCategoryAndFilter(categoryId, filter);
3842
+ }
3843
+ for (const filter of filterToBeInserted) {
3844
+ const newCategoryFilter = await this.categoryFilterRepository.create({
3845
+ filterId: filter,
3846
+ categoryId,
3847
+ });
3848
+ filtersList.push(filter);
3849
+ }
3850
+ return filters.value;
3851
+ }
3852
+ if (Array.isArray(filters) && filters.length) {
3853
+ await this.categoryFilterRepository.deleteByCategory(categoryId);
3854
+ let filtersList = [];
3855
+ for (let i = 0; i < filters.length; i++) {
3856
+ const newCategoryFilter = await this.categoryFilterRepository.create({
3857
+ filterId: filters[i].id,
3858
+ categoryId,
3859
+ });
3860
+ filtersList.push(newCategoryFilter);
3861
+ }
3862
+ return filters;
3863
+ }
3864
+ }
3865
+ async getChildren(parentId) {
3866
+ const { category_tree } = await this.query('category_tree', ['id', 'name', 'parent_id'], {
3867
+ args: {
3868
+ type: 'category_tree_args',
3869
+ value: { parentid: parentId },
3870
+ required: true,
3871
+ },
3872
+ });
3873
+ return category_tree.map((category) => Category.toInstance(category));
3874
+ }
3875
+ async isChild(id, parentId) {
3876
+ const categoryTree = await this.getChildren(parentId);
3877
+ return categoryTree.some((c) => c.id == id.toString());
3878
+ }
3879
+ }
3880
+
3881
+ class FilterHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
3882
+ constructor({ endpoint, authOptions, interceptors, }, filterOptionRepository, categoryFilterRepository) {
3883
+ super({
3884
+ tableName: 'filter',
3885
+ model: Filter,
3886
+ endpoint,
3887
+ authOptions,
3888
+ interceptors,
3889
+ fields: [
3890
+ 'id',
3891
+ 'description',
3892
+ 'slug',
3893
+ 'enabled',
3894
+ { createdAt: { columnName: 'created_at' } },
3895
+ { updatedAt: { columnName: 'updated_at' } },
3896
+ {
3897
+ options: {
3898
+ columnName: 'options',
3899
+ foreignKeyColumn: { filterId: 'id' },
3900
+ fields: [
3901
+ 'id',
3902
+ { filterId: { columnName: 'filter_id' } },
3903
+ 'description',
3904
+ { createdAt: { columnName: 'created_at' } },
3905
+ { updatedAt: { columnName: 'updated_at' } },
3906
+ ],
3907
+ },
3908
+ },
3909
+ ],
2678
3910
  });
2679
- products.push(...productsData);
2680
- return products;
3911
+ this.filterOptionRepository = filterOptionRepository;
3912
+ this.categoryFilterRepository = categoryFilterRepository;
2681
3913
  }
2682
- async getId(id) {
2683
- if (!Number.isNaN(+id))
2684
- return id;
2685
- const { data } = await this.find({ filters: { firestoreId: id } });
2686
- if (data?.[0]?.id)
2687
- return data?.[0]?.id;
2688
- throw new NotFoundError(`Category with id ${id} not found`);
3914
+ async update(params) {
3915
+ const { options, ...data } = params;
3916
+ const filter = await super.update(data);
3917
+ filter.options = await this.updateOptions(+data.id, { options });
3918
+ return filter;
2689
3919
  }
2690
- async updateProducts(categoryId, { products }) {
2691
- if ('action' in products && products.action === 'remove') {
2692
- await this.mutation('delete_category_product', ['affected_rows'], {
2693
- where: {
2694
- type: 'category_product_bool_exp',
2695
- required: true,
2696
- value: { category_id: { _eq: categoryId } },
2697
- },
2698
- });
3920
+ async updateOptions(filterId, { options }) {
3921
+ if (!options)
2699
3922
  return [];
2700
- }
2701
- const plainData = this.paramsToPlain({ products });
2702
- if (!plainData.products || plainData.products.length <= 0)
3923
+ if ('action' in options && options.action === 'remove' && options.value.length) {
3924
+ for (let i = 0; i < options.value.length; i++) {
3925
+ await this.filterOptionRepository.delete({ id: options.value[i].id });
3926
+ }
2703
3927
  return [];
2704
- await this.mutation('delete_category_product', ['affected_rows'], {
2705
- where: {
2706
- type: 'category_product_bool_exp',
2707
- required: true,
2708
- value: { category_id: { _eq: categoryId } },
3928
+ }
3929
+ if ('action' in options && options.action === 'merge' && options.value.length) {
3930
+ let filterOptions = [];
3931
+ for (let i = 0; i < options.value.length; i++) {
3932
+ try {
3933
+ const hasFilter = await this.filterOptionRepository.get({ id: options.value[i].id });
3934
+ if (hasFilter)
3935
+ filterOptions.push(hasFilter);
3936
+ }
3937
+ catch (error) {
3938
+ const newOption = await this.filterOptionRepository.create({ ...options.value[i], filterId });
3939
+ filterOptions.push(newOption);
3940
+ }
3941
+ }
3942
+ return filterOptions;
3943
+ }
3944
+ if (Array.isArray(options) && options.length) {
3945
+ let filterOptions = [];
3946
+ for (let i = 0; i < options.length; i++) {
3947
+ try {
3948
+ const hasFilter = await this.filterOptionRepository.get({ id: options[i].id });
3949
+ if (hasFilter)
3950
+ filterOptions.push(hasFilter);
3951
+ }
3952
+ catch (error) {
3953
+ const newOption = await this.filterOptionRepository.create({ ...options[i], filterId });
3954
+ filterOptions.push(newOption);
3955
+ }
3956
+ }
3957
+ }
3958
+ return [];
3959
+ }
3960
+ async delete(params) {
3961
+ const { data: categoryFilters } = await this.categoryFilterRepository.find({
3962
+ filters: {
3963
+ filterId: params.id,
2709
3964
  },
2710
3965
  });
2711
- await this.mutation('insert_category_product', ['affected_rows'], {
2712
- objects: {
2713
- type: '[category_product_insert_input!]',
3966
+ if (categoryFilters.length)
3967
+ throw new Error('Erro: o filtro está associado a uma ou mais categoria(s)');
3968
+ await this.deleteOptions(+params.id);
3969
+ await super.delete({ id: +params.id });
3970
+ return;
3971
+ }
3972
+ async deleteOptions(filterId) {
3973
+ await this.mutation('delete_filter_option', ['affected_rows'], {
3974
+ where: {
3975
+ type: 'filter_option_bool_exp',
2714
3976
  required: true,
2715
- value: plainData.products.map((productId) => ({ category_id: categoryId, product_id: productId })),
3977
+ value: { filter_id: { _eq: filterId } },
2716
3978
  },
2717
3979
  });
2718
- return plainData.products;
2719
3980
  }
2720
- async updateMetadata(categoryId, { metadata }) {
2721
- const plainData = this.paramsToPlain({ metadata });
2722
- if (!plainData.metadata)
2723
- return null;
2724
- await this.mutation('update_category_metadata_by_pk', ['category_id'], {
2725
- pk_columns: {
2726
- value: { category_id: categoryId },
2727
- type: 'category_metadata_pk_columns_input',
2728
- required: true,
2729
- },
2730
- _set: {
2731
- value: omit(metadata, ['category_id']),
2732
- type: 'category_metadata_set_input',
2733
- required: true,
2734
- },
3981
+ }
3982
+
3983
+ class FilterOptionHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
3984
+ constructor({ endpoint, authOptions, interceptors, }) {
3985
+ super({
3986
+ tableName: 'filter_option',
3987
+ model: FilterOption,
3988
+ endpoint,
3989
+ authOptions,
3990
+ interceptors,
3991
+ fields: [
3992
+ 'id',
3993
+ 'description',
3994
+ { filterId: { columnName: 'filter_id' } },
3995
+ { createdAt: { columnName: 'created_at' } },
3996
+ { updatedAt: { columnName: 'updated_at' } },
3997
+ ],
2735
3998
  });
2736
- return plainData.metadata;
2737
3999
  }
2738
4000
  }
2739
4001
 
@@ -2777,9 +4039,9 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
2777
4039
  whoMustUse: data.who_must_use,
2778
4040
  howToUse: data.how_to_use,
2779
4041
  brand: data.brand_description,
4042
+ ingredients: data.ingredients,
2780
4043
  }),
2781
- bindFindFilter: (sentence) => {
2782
- const filters = Object.values(sentence).shift();
4044
+ bindFindFilter: (filters) => {
2783
4045
  return {
2784
4046
  ...(filters?.description && { description: filters.description }),
2785
4047
  ...(filters.differentials && { differentials: filters.differentials }),
@@ -2792,6 +4054,9 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
2792
4054
  ...(filters.brand && {
2793
4055
  brand_description: filters.brand,
2794
4056
  }),
4057
+ ...(filters.ingredients && {
4058
+ ingredients: filters.ingredients,
4059
+ }),
2795
4060
  };
2796
4061
  },
2797
4062
  bindPersistData: (descriptionData) => ({
@@ -2802,6 +4067,7 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
2802
4067
  }),
2803
4068
  ...(descriptionData.howToUse && { how_to_use: descriptionData.howToUse }),
2804
4069
  ...(descriptionData.brand && { brand_description: descriptionData.brand }),
4070
+ ...(descriptionData.ingredients && { ingredients: descriptionData.ingredients }),
2805
4071
  }),
2806
4072
  },
2807
4073
  },
@@ -2809,6 +4075,7 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
2809
4075
  { whoMustUse: { columnName: 'who_must_use' } },
2810
4076
  { howToUse: { columnName: 'how_to_use' } },
2811
4077
  { brandDescription: { columnName: 'brand_description' } },
4078
+ { ingredients: { columnName: 'ingredients' } },
2812
4079
  { hasVariants: { columnName: 'has_variants' } },
2813
4080
  {
2814
4081
  images: {
@@ -2832,8 +4099,7 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
2832
4099
  subscriberDiscountPercentage: data.subscriber_discount_percentage,
2833
4100
  subscriberPrice: data.subscriber_price,
2834
4101
  }),
2835
- bindFindFilter: (sentence) => {
2836
- const filters = Object.values(sentence).shift();
4102
+ bindFindFilter: (filters) => {
2837
4103
  return {
2838
4104
  ...((filters?.price || filters?.price === 0) && { price: filters.price }),
2839
4105
  ...((filters.fullPrice || filters.fullPrice === 0) && { full_price: filters.fullPrice }),
@@ -2867,27 +4133,29 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
2867
4133
  to: (value) => (isNil(value?.quantity) ? value : value?.quantity),
2868
4134
  },
2869
4135
  },
4136
+ { hasStock: { columnName: 'has_stock' } },
2870
4137
  'slug',
2871
4138
  'type',
2872
4139
  'video',
2873
4140
  'weight',
2874
4141
  'gender',
4142
+ { intGender: { columnName: 'int_gender' } },
2875
4143
  { tags: { columnName: 'tags', type: HasuraGraphQLColumnType.Jsonb } },
4144
+ { filters: { columnName: 'filters', type: HasuraGraphQLColumnType.Jsonb } },
2876
4145
  { isKit: { columnName: 'is_kit' } },
2877
4146
  { createdAt: { columnName: 'created_at' } },
2878
4147
  { updatedAt: { columnName: 'updated_at' } },
4148
+ { rate: { columnName: 'rating' } },
4149
+ { reviewsTotal: { columnName: 'reviews_total' } },
4150
+ { shoppingCount: { columnName: 'shopping_count' } },
4151
+ { categoryId: { columnName: 'category_id' } },
2879
4152
  {
2880
- rate: {
2881
- columnName: 'reviews_aggregate',
2882
- filters: {
2883
- filters: { status: true },
2884
- filterType: 'product_review_bool_exp',
2885
- },
2886
- fields: [{ aggregate: [{ avg: ['rate'] }] }],
2887
- from: (value) => value.aggregate.avg.rate,
4153
+ category: {
4154
+ columnName: 'category',
4155
+ foreignKeyColumn: { id: 'categoryId' },
4156
+ fields: ['id', 'name', 'reference', 'slug'],
2888
4157
  },
2889
4158
  },
2890
- { shoppingCount: { columnName: 'shopping_count' } },
2891
4159
  ];
2892
4160
  this.fields = [
2893
4161
  ...commonFields,
@@ -2964,7 +4232,7 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
2964
4232
  }
2965
4233
  async get(identifiers) {
2966
4234
  const product = Number.isNaN(+identifiers.id)
2967
- ? (await this.find({ filters: { firestoreId: identifiers.id } })).data?.[0]
4235
+ ? (await this.find({ filters: { firestoreId: identifiers.id }, options: { enableCount: false } })).data?.[0]
2968
4236
  : await super.get(identifiers);
2969
4237
  if (product.productId)
2970
4238
  throw new NotFoundError('Product not found, it is a variant');
@@ -2977,10 +4245,25 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
2977
4245
  this.fields
2978
4246
  .map((field) => (typeof field === 'string' ? field : Object.keys(field).shift()))
2979
4247
  .filter((field) => field !== 'reviews');
4248
+ if (options.options?.minimal?.includes('price'))
4249
+ options.options?.minimal.push('price.price', 'price.fullPrice', 'price.subscriberPrice');
4250
+ if (options.options?.maximum?.includes('price'))
4251
+ options.options?.maximum.push('price.price', 'price.fullPrice', 'price.subscriberPrice');
4252
+ options.options?.minimal?.splice(options.options?.minimal.indexOf('price'), 1);
4253
+ options.options?.maximum?.splice(options.options?.maximum.indexOf('price'), 1);
2980
4254
  return super.find({
2981
4255
  ...options,
2982
4256
  filters: { ...filters, productId: { operator: Where.ISNULL } },
2983
- fields: bindFields,
4257
+ fields: [
4258
+ ...bindFields,
4259
+ ...(bindFields.includes('price')
4260
+ ? [
4261
+ 'subscriberPrice',
4262
+ 'subscriberDiscountPercentage',
4263
+ 'fullPrice',
4264
+ ]
4265
+ : []),
4266
+ ],
2984
4267
  });
2985
4268
  }
2986
4269
  async getBySlug(slug) {
@@ -2988,9 +4271,13 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
2988
4271
  filters: {
2989
4272
  slug,
2990
4273
  },
4274
+ fields: this.fields.map((field) => typeof field === 'string' ? field : Object.keys(field).shift()),
4275
+ options: {
4276
+ enableCount: false,
4277
+ },
2991
4278
  });
2992
4279
  const product = result?.data?.shift();
2993
- product.reviews = await this.findReviewsByProduct(+product.id);
4280
+ RoundProductPricesHelper.roundProductPrices(product);
2994
4281
  return product;
2995
4282
  }
2996
4283
  async update(params) {
@@ -3027,6 +4314,17 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
3027
4314
  })),
3028
4315
  ], []);
3029
4316
  }
4317
+ async findCatalog(params, mainGender) {
4318
+ return this.find({
4319
+ ...params,
4320
+ filters: { ...params.filters, published: true },
4321
+ orderBy: {
4322
+ hasStock: 'desc',
4323
+ ...(!mainGender ? {} : { intGender: mainGender === 'female' ? 'desc' : 'asc' }),
4324
+ ...omit(params.orderBy, ['hasStock', 'intGender']),
4325
+ },
4326
+ });
4327
+ }
3030
4328
  async updateCategories(productId, { categories }) {
3031
4329
  if ('action' in categories && categories.action === 'remove') {
3032
4330
  await this.mutation('delete_category_product', ['affected_rows'], {
@@ -3140,7 +4438,7 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
3140
4438
  async getId(id) {
3141
4439
  if (!Number.isNaN(+id))
3142
4440
  return id;
3143
- const { data } = await this.find({ filters: { firestoreId: id } });
4441
+ const { data } = await this.find({ filters: { firestoreId: id }, options: { enableCount: false } });
3144
4442
  if (data?.[0]?.id)
3145
4443
  return data?.[0]?.id;
3146
4444
  throw new NotFoundError(`Product with id ${id} not found`);
@@ -3196,6 +4494,19 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
3196
4494
  });
3197
4495
  return data && data[0] && this.bindReviewToModel(data[0]);
3198
4496
  }
4497
+ async cleanShoppingCountFromIds(ids) {
4498
+ return await this.mutation('update_product', ['affected_rows'], {
4499
+ where: {
4500
+ value: { id: { _nin: ids } },
4501
+ type: 'product_bool_exp',
4502
+ required: true,
4503
+ },
4504
+ _set: {
4505
+ value: { shopping_count: 0 },
4506
+ type: 'product_set_input',
4507
+ },
4508
+ });
4509
+ }
3199
4510
  }
3200
4511
 
3201
4512
  class VariantHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
@@ -3228,7 +4539,7 @@ class VariantHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
3228
4539
  subscriberPrice: data.subscriber_price,
3229
4540
  }),
3230
4541
  bindFindFilter: (sentence) => {
3231
- const filters = Object.values(sentence || {}).shift();
4542
+ const filters = Object.values(sentence).shift();
3232
4543
  return {
3233
4544
  ...((filters?.price || filters?.price === 0) && { price: filters.price }),
3234
4545
  ...((filters.fullPrice || filters.fullPrice === 0) && { full_price: filters.fullPrice }),
@@ -3261,6 +4572,7 @@ class VariantHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
3261
4572
  to: (value) => (isNil(value?.quantity) ? value : value?.quantity),
3262
4573
  },
3263
4574
  },
4575
+ { hasStock: { columnName: 'has_stock' } },
3264
4576
  'weight',
3265
4577
  { name: { to: () => '', from: () => undefined } },
3266
4578
  { hasVariants: { columnName: 'has_variants', to: () => false, from: () => undefined } },
@@ -3298,16 +4610,247 @@ class VariantHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
3298
4610
  async getId(id) {
3299
4611
  if (!Number.isNaN(+id))
3300
4612
  return id;
3301
- const { data } = await this.find({ filters: { firestoreId: id } });
4613
+ const { data } = await this.find({ filters: { firestoreId: id }, options: { enableCount: false } });
3302
4614
  if (data?.[0]?.id)
3303
4615
  return data?.[0]?.id;
3304
4616
  throw new NotFoundError(`Product with id ${id} not found`);
3305
4617
  }
3306
4618
  }
3307
4619
 
4620
+ class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
4621
+ constructor({ endpoint, authOptions, interceptors, }, categoryFilterRepository) {
4622
+ super({
4623
+ tableName: 'category',
4624
+ model: Wishlist,
4625
+ endpoint,
4626
+ authOptions,
4627
+ interceptors,
4628
+ fields: [
4629
+ { id: { columnName: 'id', to: (value) => +value, from: (value) => value.toString() } },
4630
+ { firestoreId: { columnName: 'firestore_id' } },
4631
+ 'name',
4632
+ 'description',
4633
+ 'image',
4634
+ 'published',
4635
+ 'shop',
4636
+ { shops: { columnName: 'shops', type: HasuraGraphQLColumnType.Jsonb } },
4637
+ 'slug',
4638
+ { brandCategory: { columnName: 'brand_category' } },
4639
+ { brandCategoryBanner: { columnName: 'brand_banner' } },
4640
+ { brandCategoryBannerMobile: { columnName: 'brand_banner_mobile' } },
4641
+ { brandLogo: { columnName: 'brand_logo' } },
4642
+ { brandCondition: { columnName: 'brand_condition' } },
4643
+ {
4644
+ conditions: {
4645
+ columnName: 'tag_condition',
4646
+ type: HasuraGraphQLColumnType.Jsonb,
4647
+ from: (tags, row) => ({ brand: row.brand_condition, tags: Array.isArray(tags) ? tags : [] }),
4648
+ bindPersistData: (value) => {
4649
+ return {
4650
+ brand_condition: value.brand,
4651
+ tag_condition: value?.tags || [],
4652
+ };
4653
+ },
4654
+ bindFindFilter: (sentence) => {
4655
+ return {
4656
+ ...(sentence.brand ? { brand_condition: sentence.brand } : {}),
4657
+ ...(sentence.tags ? { tag_condition: sentence.tags } : {}),
4658
+ };
4659
+ },
4660
+ },
4661
+ },
4662
+ {
4663
+ filters: {
4664
+ columnName: 'filters',
4665
+ foreignKeyColumn: { filter_id: 'id' },
4666
+ fields: [{ filter: ['id', 'description', 'slug', 'enabled'] }],
4667
+ bindPersistData: (value) => ({
4668
+ filters: { data: value.map((filter) => ({ filter_id: filter.id })) },
4669
+ }),
4670
+ from: (filters) => filters?.map((filter) => filter?.filter) || [],
4671
+ },
4672
+ },
4673
+ { createdAt: { columnName: 'created_at' } },
4674
+ { updatedAt: { columnName: 'updated_at' } },
4675
+ {
4676
+ products: {
4677
+ columnName: 'products',
4678
+ fields: ['product_id'],
4679
+ from: (value) => value.map((product) => product.product_id.toString()),
4680
+ to: (productIds) => productIds.map((productId) => ({
4681
+ product_id: +productId,
4682
+ })),
4683
+ },
4684
+ },
4685
+ {
4686
+ metadata: {
4687
+ columnName: 'metadata',
4688
+ fields: ['title', 'description'],
4689
+ bindPersistData: (value) => ({
4690
+ metadata: { data: value },
4691
+ }),
4692
+ },
4693
+ },
4694
+ { isCollection: { columnName: 'is_collection' } },
4695
+ { isWishlist: { columnName: 'is_wishlist' } },
4696
+ 'reference',
4697
+ { parentId: { columnName: 'parent_id' } },
4698
+ {
4699
+ parent: {
4700
+ columnName: 'parent',
4701
+ foreignKeyColumn: { id: 'parentId' },
4702
+ fields: ['id', 'name', 'reference', 'slug'],
4703
+ },
4704
+ },
4705
+ { personId: { columnName: 'person_id' } },
4706
+ ],
4707
+ });
4708
+ this.categoryFilterRepository = categoryFilterRepository;
4709
+ }
4710
+ async create(params) {
4711
+ const { metadata, ...data } = params;
4712
+ return super.create({
4713
+ ...data,
4714
+ isWishlist: true,
4715
+ isCollection: true,
4716
+ brandCategory: false,
4717
+ metadata: metadata || { description: data.description, title: data.name },
4718
+ });
4719
+ }
4720
+ async get(identifiers) {
4721
+ const data = await super.get(identifiers);
4722
+ if (!data.isWishlist)
4723
+ throw new NotFoundError(`Category with id ${identifiers.id} is not a wishlist`);
4724
+ return data;
4725
+ }
4726
+ async update(params) {
4727
+ const { products, id: checkId, metadata, filters, ...data } = params;
4728
+ const plainData = this.paramsToPlain({ id: checkId });
4729
+ const id = plainData.id;
4730
+ const category = await super.update({ id, ...data, isWishlist: true, isCollection: true, brandCategory: false });
4731
+ category.products = products && (await this.updateProducts(+id, { products }));
4732
+ category.metadata = metadata && (await this.updateMetadata(+id, { metadata }));
4733
+ return category;
4734
+ }
4735
+ async getWishlistBySlug(slug) {
4736
+ if (!slug)
4737
+ return;
4738
+ const { data } = await this.find({
4739
+ filters: {
4740
+ slug,
4741
+ isWishlist: { operator: Where.EQUALS, value: true },
4742
+ },
4743
+ options: {
4744
+ enableCount: false,
4745
+ },
4746
+ });
4747
+ if (!data.length)
4748
+ throw new NotFoundError(`Wishlist with slug ${slug} not found`);
4749
+ if (data.length > 1)
4750
+ throw new DuplicatedResultsError('Query returned duplicated values');
4751
+ return data.shift();
4752
+ }
4753
+ async getWishlistByPerson(personId) {
4754
+ if (!personId)
4755
+ return;
4756
+ const { data } = await this.find({
4757
+ filters: {
4758
+ personId: { operator: Where.EQUALS, value: personId },
4759
+ isWishlist: { operator: Where.EQUALS, value: true },
4760
+ },
4761
+ options: {
4762
+ enableCount: false,
4763
+ },
4764
+ });
4765
+ if (!data.length)
4766
+ throw new NotFoundError(`Wishlists from person ${personId} not found`);
4767
+ return data;
4768
+ }
4769
+ async updateProducts(categoryId, { products }) {
4770
+ if ('action' in products && products.action === 'remove') {
4771
+ await this.mutation('delete_category_product', ['affected_rows'], {
4772
+ where: {
4773
+ type: 'category_product_bool_exp',
4774
+ required: true,
4775
+ value: { category_id: { _eq: categoryId } },
4776
+ },
4777
+ });
4778
+ await this.categoryFilterRepository.deleteByCategory(categoryId);
4779
+ return [];
4780
+ }
4781
+ const plainData = this.paramsToPlain({ products });
4782
+ if (!plainData.products || plainData.products.length <= 0)
4783
+ return [];
4784
+ await this.mutation('delete_category_product', ['affected_rows'], {
4785
+ where: {
4786
+ type: 'category_product_bool_exp',
4787
+ required: true,
4788
+ value: { category_id: { _eq: categoryId } },
4789
+ },
4790
+ });
4791
+ await this.categoryFilterRepository.deleteByCategory(categoryId);
4792
+ await this.mutation('insert_category_product', ['affected_rows'], {
4793
+ objects: {
4794
+ type: '[category_product_insert_input!]',
4795
+ required: true,
4796
+ value: plainData.products.map((productId) => ({ category_id: categoryId, product_id: productId })),
4797
+ },
4798
+ });
4799
+ return plainData.products;
4800
+ }
4801
+ async updateMetadata(categoryId, { metadata }) {
4802
+ const plainData = this.paramsToPlain({ metadata });
4803
+ if (!plainData.metadata)
4804
+ return;
4805
+ await this.mutation('update_category_metadata_by_pk', ['category_id'], {
4806
+ pk_columns: {
4807
+ value: { category_id: categoryId },
4808
+ type: 'category_metadata_pk_columns_input',
4809
+ required: true,
4810
+ },
4811
+ _set: {
4812
+ value: omit(metadata, ['category_id']),
4813
+ type: 'category_metadata_set_input',
4814
+ required: true,
4815
+ },
4816
+ });
4817
+ return plainData.metadata;
4818
+ }
4819
+ getCategoryBySlug(slug, _shop) {
4820
+ return this.getWishlistBySlug(slug);
4821
+ }
4822
+ async getCategoryByShop(shop) {
4823
+ if (!shop)
4824
+ return;
4825
+ const { data } = await this.find({
4826
+ filters: {
4827
+ shops: { operator: Where.IN, value: [shop] },
4828
+ published: { operator: Where.EQUALS, value: true },
4829
+ isWishlist: { operator: Where.EQUALS, value: true },
4830
+ },
4831
+ options: {
4832
+ enableCount: false,
4833
+ },
4834
+ });
4835
+ return data;
4836
+ }
4837
+ getCategoriesForHome(categoryIds, limit, gender) {
4838
+ return;
4839
+ }
4840
+ mountCategory(category, options) {
4841
+ return;
4842
+ }
4843
+ getChildren(parentId) {
4844
+ return;
4845
+ }
4846
+ isChild(id, parentId) {
4847
+ return;
4848
+ }
4849
+ }
4850
+
3308
4851
  /**
3309
4852
  * Generated bundle index. Do not edit.
3310
4853
  */
3311
4854
 
3312
- export { AccessoryImportances, Address, Area, Authentication, AuthenticationFirebaseAuthService, AxiosAdapter, Base, BaseModel, BeardProblems, BeardSizes, BeautyProductImportances, BeautyProfile, BeautyQuestionsHelper, BillingStatus, BodyProblems, BodyShapes, BodyTattoos, Buy2Win, Buy2WinFirestoreRepository, Category, CategoryFirestoreRepository, CategoryHasuraGraphQL, CategoryHasuraGraphQLRepository, Checkout, CheckoutFirestoreRepository, CheckoutSubscription, CheckoutSubscriptionFirestoreRepository, CheckoutTypes, Coupon, CouponFirestoreRepository, CouponSubtypes, CouponTypes, DuplicatedResultsError, Edition, EditionStatus, Exclusivities, FaceSkinOilinesses, FaceSkinProblems, FaceSkinTones, FamilyIncomes, FilterType, FragranceImportances, GenderDestination, HairColors, HairProblems, HairStrands, HairTypes, Home, HomeFirestoreRepository, InvalidArgumentError, KitProduct, KitProductHasuraGraphQL, Lead, LeadFirestoreRepository, LegacyOrderFirestoreRepository, LineItem, NotFoundError, OfficePosition, Order, OrderFirestoreRepository, OrderStatus, Payment, PaymentFirestoreRepository, PaymentType, Product, ProductFirestoreRepository, ProductHasuraGraphQL, ProductHasuraGraphQLRepository, ProductSpents, ProductVariantFirestoreRepository, ProductsIndex, QuestionsFilters, RecoveryPassword, Register, RegisterFirebaseAuthService, RequiredArgumentError, ShippingMethod, ShopMenu, ShopMenuFirestoreRepository, Shops, SignInMethods, SignOut, Status, Subscription, SubscriptionEditionFirestoreRepository, SubscriptionFirestoreRepository, SubscriptionPayment, SubscriptionPaymentFirestoreRepository, SubscriptionPlan, SubscriptionPlanFirestoreRepository, SubscriptionProductFirestoreRepository, UnauthorizedError, UpdateOptionActions, User, UserAddress, UserAddressFirestoreRepository, UserAlreadyRegisteredError, UserBeautyProfileFirestoreRepository, UserFirestoreRepository, UserPaymentMethod, UserPaymentMethodFirestoreRepository, UserType, Variant, VariantHasuraGraphQL, VariantHasuraGraphQLRepository, WeakPasswordError, Where, get, is, isUUID, parseDateTime, withCreateFirestore, withCreateHasuraGraphQL, withCrudFirestore, withCrudHasuraGraphQL, withDeleteFirestore, withDeleteHasuraGraphQL, withFindFirestore, withFindHasuraGraphQL, withFirestore, withGetFirestore, withGetHasuraGraphQL, withHasuraGraphQL, withHelpers, withSubCollection, withUpdateFirestore, withUpdateHasuraGraphQL };
4855
+ export { AccessoryImportances, Address, Area, Authentication, AuthenticationFirebaseAuthService, AxiosAdapter, Base, BaseModel, BeardProblems, BeardSizes, BeautyProductImportances, BeautyProfile, BeautyQuestionsHelper, BillingStatus, BodyProblems, BodyShapes, BodyTattoos, Buy2Win, Buy2WinFirestoreRepository, CampaignDashboard, CampaignDashboardFirestoreRepository, CampaignHashtag, CampaignHashtagFirestoreRepository, Category, CategoryCollectionChildren, CategoryCollectionChildrenHasuraGraphQLRepository, CategoryFilter, CategoryFilterHasuraGraphQLRepository, CategoryFirestoreRepository, CategoryHasuraGraphQL, CategoryHasuraGraphQLRepository, Checkout, CheckoutFirestoreRepository, CheckoutSubscription, CheckoutSubscriptionFirestoreRepository, CheckoutTypes, ClassNameHelper, Coupon, CouponFirestoreRepository, CouponSubtypes, CouponTypes, Debug, DebugDecoratorHelper, DebugHelper, DebugNamespaces, DuplicatedResultsError, Edition, EditionStatus, Exclusivities, FaceSkinOilinesses, FaceSkinProblems, FaceSkinTones, FamilyIncomes, Filter, FilterHasuraGraphQLRepository, FilterOption, FilterOptionHasuraGraphQLRepository, FilterType, FragranceImportances, GenderDestination, HairColors, HairProblems, HairStrands, HairTypes, Home, HomeFirestoreRepository, InvalidArgumentError, KitProduct, KitProductHasuraGraphQL, Lead, LeadFirestoreRepository, LegacyOrderFirestoreRepository, LineItem, Log, Logger, NotFoundError, OfficePosition, Order, OrderFirestoreRepository, OrderStatus, Payment, PaymentFirestoreRepository, PaymentType, Product, ProductFirestoreRepository, ProductHasuraGraphQL, ProductHasuraGraphQLRepository, ProductSpents, ProductVariantFirestoreRepository, ProductsIndex, QuestionsFilters, RecoveryPassword, ReflectHelper, Register, RegisterFirebaseAuthService, RequiredArgumentError, RoundProductPricesHelper, ShippingMethod, ShopMenu, ShopMenuFirestoreRepository, ShopSettings, ShopSettingsFirestoreRepository, Shops, SignInMethods, SignOut, Status, Subscription, SubscriptionEditionFirestoreRepository, SubscriptionFirestoreRepository, SubscriptionPayment, SubscriptionPaymentFirestoreRepository, SubscriptionPlan, SubscriptionPlanFirestoreRepository, SubscriptionProductFirestoreRepository, Trace, UnauthorizedError, UpdateOptionActions, User, UserAddress, UserAddressFirestoreRepository, UserAlreadyRegisteredError, UserBeautyProfileFirestoreRepository, UserFirestoreRepository, UserPaymentMethod, UserPaymentMethodFirestoreRepository, UserType, Variant, VariantHasuraGraphQL, VariantHasuraGraphQLRepository, WeakPasswordError, Where, Wishlist, WishlistHasuraGraphQLRepository, is, isDebuggable, isUUID, parseDateTime, withCreateFirestore, withCreateHasuraGraphQL, withCrudFirestore, withCrudHasuraGraphQL, withDeleteFirestore, withDeleteHasuraGraphQL, withFindFirestore, withFindHasuraGraphQL, withFirestore, withGetFirestore, withGetHasuraGraphQL, withHasuraGraphQL, withHelpers, withSubCollection, withUpdateFirestore, withUpdateHasuraGraphQL };
3313
4856
  //# sourceMappingURL=infrab4a-connect.mjs.map