@infrab4a/connect 1.0.0-beta.41 → 1.0.0-beta.5

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 (364) hide show
  1. package/bundles/infrab4a-connect.umd.js +212 -2113
  2. package/bundles/infrab4a-connect.umd.js.map +1 -1
  3. package/domain/catalog/models/category.d.ts +4 -5
  4. package/domain/catalog/models/index.d.ts +2 -3
  5. package/domain/catalog/models/product.d.ts +4 -9
  6. package/domain/catalog/models/types/product-review.type.d.ts +8 -10
  7. package/domain/catalog/models/variant.d.ts +3 -7
  8. package/domain/catalog/repositories/category.repository.d.ts +1 -1
  9. package/domain/catalog/repositories/product.repository.d.ts +3 -10
  10. package/domain/catalog/repositories/subscription-product.repository.d.ts +1 -1
  11. package/domain/catalog/repositories/variant.repository.d.ts +1 -1
  12. package/domain/general/model/base-model-with-identifier-fields.d.ts +3 -0
  13. package/domain/general/model/base.model.d.ts +6 -0
  14. package/domain/{generic → general}/model/index.d.ts +1 -0
  15. package/domain/general/model/types/base-model-builder.type.d.ts +5 -0
  16. package/domain/{generic → general}/model/types/index.d.ts +0 -2
  17. package/domain/general/model/types/non-function-properties.type.d.ts +2 -0
  18. package/domain/general/model/types/non-function-property-name.type.d.ts +3 -0
  19. package/domain/general/repository/create.repository.d.ts +5 -0
  20. package/domain/general/repository/crud.repository.d.ts +7 -0
  21. package/domain/general/repository/delete.repository.d.ts +5 -0
  22. package/domain/{generic → general}/repository/enums/where.enum.d.ts +2 -5
  23. package/domain/general/repository/find.repository.d.ts +5 -0
  24. package/domain/general/repository/get.repository.d.ts +5 -0
  25. package/domain/general/repository/read.repository.d.ts +5 -0
  26. package/domain/{generic → general}/repository/types/index.d.ts +0 -1
  27. package/domain/general/repository/types/repository-find-filters.type.d.ts +14 -0
  28. package/domain/{generic → general}/repository/types/repository-update-params.type.d.ts +4 -4
  29. package/domain/general/repository/update.repository.d.ts +5 -0
  30. package/domain/index.d.ts +1 -1
  31. package/domain/location/models/address.d.ts +2 -3
  32. package/domain/shop-settings/models/home.d.ts +3 -3
  33. package/domain/shop-settings/models/shop-menu.d.ts +3 -3
  34. package/domain/shop-settings/repositories/home.repository.d.ts +1 -1
  35. package/domain/shop-settings/repositories/shop-menu.repository.d.ts +1 -1
  36. package/domain/shopping/models/buy-2-win.d.ts +5 -3
  37. package/domain/shopping/models/checkout.d.ts +9 -7
  38. package/domain/shopping/models/coupons/club-coupon.d.ts +7 -0
  39. package/domain/shopping/models/coupons/coupon.d.ts +15 -13
  40. package/domain/shopping/models/coupons/enums/discount-type.enum.d.ts +5 -0
  41. package/domain/shopping/models/coupons/enums/index.d.ts +1 -2
  42. package/domain/shopping/models/coupons/index.d.ts +2 -1
  43. package/domain/shopping/models/coupons/store-coupon.d.ts +8 -0
  44. package/domain/shopping/models/payment.d.ts +5 -3
  45. package/domain/shopping/models/shipping-method.d.ts +5 -3
  46. package/domain/shopping/models/subscription/checkout.d.ts +5 -3
  47. package/domain/shopping/models/subscription/plan.d.ts +5 -3
  48. package/domain/shopping/repositories/buy-2-win.repository.d.ts +1 -1
  49. package/domain/shopping/repositories/checkout.repository.d.ts +1 -1
  50. package/domain/shopping/repositories/coupon.repository.d.ts +1 -1
  51. package/domain/shopping/repositories/order.repository.d.ts +1 -1
  52. package/domain/shopping/repositories/payment.repository.d.ts +1 -1
  53. package/domain/shopping/repositories/subscription/checkout.repository.d.ts +1 -1
  54. package/domain/shopping/repositories/subscription/plan.repository.d.ts +1 -1
  55. package/domain/users/errors/unauthorized.error.d.ts +1 -2
  56. package/domain/users/errors/user-already-registered.error.d.ts +1 -2
  57. package/domain/users/errors/weak-password.error.d.ts +1 -2
  58. package/domain/users/models/beauty-profile.d.ts +5 -4
  59. package/domain/users/models/lead.d.ts +5 -3
  60. package/domain/users/models/subscription/edition.d.ts +5 -4
  61. package/domain/users/models/subscription/payment.d.ts +5 -4
  62. package/domain/users/models/subscription/subscription.d.ts +5 -3
  63. package/domain/users/models/user-address.d.ts +3 -3
  64. package/domain/users/models/user-payment-method.d.ts +4 -4
  65. package/domain/users/models/user.d.ts +10 -11
  66. package/domain/users/repositories/beauty-profile.repository.d.ts +1 -1
  67. package/domain/users/repositories/edition.repository.d.ts +1 -1
  68. package/domain/users/repositories/lead.repository.d.ts +1 -1
  69. package/domain/users/repositories/subscription-payment.repository.d.ts +1 -1
  70. package/domain/users/repositories/subscription.repository.d.ts +1 -1
  71. package/domain/users/repositories/user-address.repository.d.ts +1 -1
  72. package/domain/users/repositories/user-payment-method.repository.d.ts +1 -1
  73. package/domain/users/repositories/user.repository.d.ts +2 -2
  74. package/errors/duplicated-results.error.d.ts +1 -2
  75. package/errors/invalid-argument.error.d.ts +1 -2
  76. package/errors/not-found.error.d.ts +1 -2
  77. package/errors/required-argument.error.d.ts +1 -2
  78. package/esm2015/domain/catalog/models/category.js +2 -5
  79. package/esm2015/domain/catalog/models/index.js +3 -4
  80. package/esm2015/domain/catalog/models/product.js +2 -12
  81. package/esm2015/domain/catalog/models/types/product-review.type.js +1 -1
  82. package/esm2015/domain/catalog/models/variant.js +2 -5
  83. package/esm2015/domain/catalog/repositories/category.repository.js +1 -1
  84. package/esm2015/domain/catalog/repositories/product.repository.js +1 -1
  85. package/esm2015/domain/catalog/repositories/subscription-product.repository.js +1 -1
  86. package/esm2015/domain/catalog/repositories/variant.repository.js +1 -1
  87. package/esm2015/domain/{generic → general}/index.js +1 -1
  88. package/esm2015/domain/general/model/base-model-with-identifier-fields.js +2 -0
  89. package/esm2015/domain/general/model/base.model.js +13 -0
  90. package/esm2015/domain/{generic → general}/model/identifier-fields.js +1 -1
  91. package/esm2015/domain/general/model/index.js +5 -0
  92. package/esm2015/domain/general/model/types/base-model-builder.type.js +2 -0
  93. package/esm2015/domain/general/model/types/index.js +4 -0
  94. package/esm2015/domain/general/model/types/non-function-properties.type.js +2 -0
  95. package/esm2015/domain/general/model/types/non-function-property-name.type.js +2 -0
  96. package/esm2015/domain/general/repository/create.repository.js +2 -0
  97. package/esm2015/domain/general/repository/crud.repository.js +2 -0
  98. package/esm2015/domain/general/repository/delete.repository.js +2 -0
  99. package/esm2015/domain/{generic → general}/repository/enums/index.js +1 -1
  100. package/esm2015/domain/{generic → general}/repository/enums/update-option-actions.enum.js +1 -1
  101. package/esm2015/domain/general/repository/enums/where.enum.js +12 -0
  102. package/esm2015/domain/general/repository/find.repository.js +2 -0
  103. package/esm2015/domain/general/repository/get.repository.js +2 -0
  104. package/esm2015/domain/{generic → general}/repository/index.js +1 -1
  105. package/esm2015/domain/general/repository/read.repository.js +2 -0
  106. package/esm2015/domain/general/repository/types/index.js +6 -0
  107. package/esm2015/domain/general/repository/types/repository-find-filters.type.js +2 -0
  108. package/esm2015/domain/{generic → general}/repository/types/repository-find-result.type.js +1 -1
  109. package/esm2015/domain/{generic → general}/repository/types/repository-limit-options.type.js +1 -1
  110. package/esm2015/domain/{generic → general}/repository/types/repository-order-by-list.type.js +1 -1
  111. package/esm2015/domain/general/repository/types/repository-update-params.type.js +2 -0
  112. package/esm2015/domain/general/repository/update.repository.js +2 -0
  113. package/esm2015/domain/index.js +2 -2
  114. package/esm2015/domain/location/models/address.js +2 -5
  115. package/esm2015/domain/shop-settings/models/home.js +3 -3
  116. package/esm2015/domain/shop-settings/models/shop-menu.js +3 -3
  117. package/esm2015/domain/shop-settings/repositories/home.repository.js +1 -1
  118. package/esm2015/domain/shop-settings/repositories/shop-menu.repository.js +1 -1
  119. package/esm2015/domain/shopping/models/buy-2-win.js +3 -3
  120. package/esm2015/domain/shopping/models/checkout.js +14 -6
  121. package/esm2015/domain/shopping/models/coupons/club-coupon.js +18 -0
  122. package/esm2015/domain/shopping/models/coupons/coupon.js +12 -4
  123. package/esm2015/domain/shopping/models/coupons/enums/discount-type.enum.js +7 -0
  124. package/esm2015/domain/shopping/models/coupons/enums/index.js +2 -3
  125. package/esm2015/domain/shopping/models/coupons/index.js +3 -2
  126. package/esm2015/domain/shopping/models/coupons/store-coupon.js +23 -0
  127. package/esm2015/domain/shopping/models/payment.js +3 -3
  128. package/esm2015/domain/shopping/models/shipping-method.js +3 -3
  129. package/esm2015/domain/shopping/models/subscription/checkout.js +3 -3
  130. package/esm2015/domain/shopping/models/subscription/plan.js +3 -3
  131. package/esm2015/domain/shopping/repositories/buy-2-win.repository.js +1 -1
  132. package/esm2015/domain/shopping/repositories/checkout.repository.js +1 -1
  133. package/esm2015/domain/shopping/repositories/coupon.repository.js +1 -1
  134. package/esm2015/domain/shopping/repositories/order.repository.js +1 -1
  135. package/esm2015/domain/shopping/repositories/payment.repository.js +1 -1
  136. package/esm2015/domain/shopping/repositories/subscription/checkout.repository.js +1 -1
  137. package/esm2015/domain/shopping/repositories/subscription/plan.repository.js +1 -1
  138. package/esm2015/domain/users/errors/unauthorized.error.js +2 -3
  139. package/esm2015/domain/users/errors/user-already-registered.error.js +2 -3
  140. package/esm2015/domain/users/errors/weak-password.error.js +2 -3
  141. package/esm2015/domain/users/models/beauty-profile.js +4 -4
  142. package/esm2015/domain/users/models/lead.js +3 -3
  143. package/esm2015/domain/users/models/subscription/edition.js +4 -4
  144. package/esm2015/domain/users/models/subscription/payment.js +4 -4
  145. package/esm2015/domain/users/models/subscription/subscription.js +3 -3
  146. package/esm2015/domain/users/models/user-address.js +3 -3
  147. package/esm2015/domain/users/models/user-payment-method.js +4 -4
  148. package/esm2015/domain/users/models/user.js +5 -5
  149. package/esm2015/domain/users/repositories/beauty-profile.repository.js +1 -1
  150. package/esm2015/domain/users/repositories/edition.repository.js +1 -1
  151. package/esm2015/domain/users/repositories/lead.repository.js +1 -1
  152. package/esm2015/domain/users/repositories/subscription-payment.repository.js +1 -1
  153. package/esm2015/domain/users/repositories/subscription.repository.js +1 -1
  154. package/esm2015/domain/users/repositories/user-address.repository.js +1 -1
  155. package/esm2015/domain/users/repositories/user-payment-method.repository.js +1 -1
  156. package/esm2015/domain/users/repositories/user.repository.js +1 -1
  157. package/esm2015/errors/duplicated-results.error.js +2 -3
  158. package/esm2015/errors/invalid-argument.error.js +2 -3
  159. package/esm2015/errors/not-found.error.js +2 -3
  160. package/esm2015/errors/required-argument.error.js +2 -3
  161. package/esm2015/infra/elasticsearch/adapters/axios.adapter.js +1 -36
  162. package/esm2015/infra/elasticsearch/adapters/elastic-search.adapter.js +1 -1
  163. package/esm2015/infra/elasticsearch/indexes/products-index.js +1 -35
  164. package/esm2015/infra/firebase/auth/authentication-firebase-auth.service.js +2 -2
  165. package/esm2015/infra/firebase/auth/register-firebase-auth.service.js +1 -1
  166. package/esm2015/infra/firebase/firestore/mixins/with-create-firestore.mixin.js +2 -2
  167. package/esm2015/infra/firebase/firestore/mixins/with-crud-firestore.mixin.js +1 -1
  168. package/esm2015/infra/firebase/firestore/mixins/with-delete-firestore.mixin.js +1 -1
  169. package/esm2015/infra/firebase/firestore/mixins/with-find-firestore.mixin.js +10 -9
  170. package/esm2015/infra/firebase/firestore/mixins/with-firestore.mixin.js +6 -2
  171. package/esm2015/infra/firebase/firestore/mixins/with-get-firestore.mixin.js +1 -1
  172. package/esm2015/infra/firebase/firestore/mixins/with-helpers.mixin.js +1 -1
  173. package/esm2015/infra/firebase/firestore/mixins/with-sub-collection.mixin.js +1 -1
  174. package/esm2015/infra/firebase/firestore/mixins/with-update-firestore.mixin.js +4 -4
  175. package/esm2015/infra/firebase/firestore/models/user-search.js +3 -3
  176. package/esm2015/infra/firebase/firestore/repositories/catalog/category-firestore.repository.js +2 -4
  177. package/esm2015/infra/firebase/firestore/repositories/catalog/product-firestore.repository.js +8 -37
  178. package/esm2015/infra/firebase/firestore/repositories/shopping/coupon-firestore.repository.js +21 -11
  179. package/esm2015/infra/firebase/firestore/repositories/users/user-firestore.repository.js +2 -2
  180. package/esm2015/infra/firebase/firestore/types/firestore-sub.repository.type.js +1 -1
  181. package/esm2015/infra/firebase/firestore/types/firestore.helpers.type.js +1 -1
  182. package/esm2015/infra/firebase/firestore/types/firestore.repository.type.js +1 -1
  183. package/esm2015/infra/index.js +1 -2
  184. package/esm2015/utils/index.js +4 -6
  185. package/esm2015/utils/mixins/index.js +1 -2
  186. package/esm2015/utils/mixins/mixin-ctor.type.js +1 -1
  187. package/esm2015/utils/types/index.js +1 -2
  188. package/fesm2015/infrab4a-connect.js +141 -1369
  189. package/fesm2015/infrab4a-connect.js.map +1 -1
  190. package/infra/elasticsearch/adapters/axios.adapter.d.ts +0 -3
  191. package/infra/elasticsearch/adapters/elastic-search.adapter.d.ts +0 -3
  192. package/infra/elasticsearch/indexes/products-index.d.ts +1 -5
  193. package/infra/firebase/auth/authentication-firebase-auth.service.d.ts +1 -1
  194. package/infra/firebase/auth/register-firebase-auth.service.d.ts +1 -1
  195. package/infra/firebase/firestore/mixins/with-create-firestore.mixin.d.ts +16 -3
  196. package/infra/firebase/firestore/mixins/with-crud-firestore.mixin.d.ts +28 -3
  197. package/infra/firebase/firestore/mixins/with-delete-firestore.mixin.d.ts +14 -3
  198. package/infra/firebase/firestore/mixins/with-find-firestore.mixin.d.ts +19 -3
  199. package/infra/firebase/firestore/mixins/with-firestore.mixin.d.ts +14 -3
  200. package/infra/firebase/firestore/mixins/with-get-firestore.mixin.d.ts +14 -3
  201. package/infra/firebase/firestore/mixins/with-helpers.mixin.d.ts +4 -5
  202. package/infra/firebase/firestore/mixins/with-sub-collection.mixin.d.ts +14 -7
  203. package/infra/firebase/firestore/mixins/with-update-firestore.mixin.d.ts +15 -6
  204. package/infra/firebase/firestore/models/user-search.d.ts +3 -3
  205. package/infra/firebase/firestore/repositories/catalog/category-firestore.repository.d.ts +42 -1
  206. package/infra/firebase/firestore/repositories/catalog/product-firestore.repository.d.ts +44 -5
  207. package/infra/firebase/firestore/repositories/catalog/product-variant-firestore.repository.d.ts +51 -4
  208. package/infra/firebase/firestore/repositories/catalog/subscription-product-firestore.repository.d.ts +42 -1
  209. package/infra/firebase/firestore/repositories/shop-settings/home-firestore.repository.d.ts +42 -1
  210. package/infra/firebase/firestore/repositories/shop-settings/shop-menu-firestore.repository.d.ts +42 -1
  211. package/infra/firebase/firestore/repositories/shopping/buy-2-win-firestore.repository.d.ts +42 -1
  212. package/infra/firebase/firestore/repositories/shopping/checkout-firestore.repository.d.ts +42 -1
  213. package/infra/firebase/firestore/repositories/shopping/checkout-subscription-firestore.repository.d.ts +42 -1
  214. package/infra/firebase/firestore/repositories/shopping/coupon-firestore.repository.d.ts +42 -1
  215. package/infra/firebase/firestore/repositories/shopping/order-firestore.repository.d.ts +42 -1
  216. package/infra/firebase/firestore/repositories/shopping/payment-firestore.repository.d.ts +42 -1
  217. package/infra/firebase/firestore/repositories/shopping/subscription-plan-firestore.repository.d.ts +42 -1
  218. package/infra/firebase/firestore/repositories/users/lead-firestore.repository.d.ts +42 -1
  219. package/infra/firebase/firestore/repositories/users/subscription-edition-firestore.repository.d.ts +51 -4
  220. package/infra/firebase/firestore/repositories/users/subscription-firestore.repository.d.ts +42 -1
  221. package/infra/firebase/firestore/repositories/users/subscription-payment-firestore.repository.d.ts +51 -4
  222. package/infra/firebase/firestore/repositories/users/user-address-firestore.repository.d.ts +51 -4
  223. package/infra/firebase/firestore/repositories/users/user-beauty-profile-firestore.repository.d.ts +51 -4
  224. package/infra/firebase/firestore/repositories/users/user-firestore.repository.d.ts +42 -1
  225. package/infra/firebase/firestore/repositories/users/user-payment-method-firestore.repository.d.ts +51 -4
  226. package/infra/firebase/firestore/repositories/users/user-search-firestore.repository.d.ts +42 -1
  227. package/infra/firebase/firestore/types/firestore-sub.repository.type.d.ts +3 -3
  228. package/infra/firebase/firestore/types/firestore.helpers.type.d.ts +3 -3
  229. package/infra/firebase/firestore/types/firestore.repository.type.d.ts +3 -7
  230. package/infra/index.d.ts +0 -1
  231. package/package.json +3 -5
  232. package/utils/index.d.ts +4 -5
  233. package/utils/mixins/index.d.ts +0 -1
  234. package/utils/mixins/mixin-ctor.type.d.ts +1 -1
  235. package/utils/types/index.d.ts +0 -1
  236. package/domain/catalog/models/kit-product.d.ts +0 -12
  237. package/domain/generic/model/base.model.d.ts +0 -10
  238. package/domain/generic/model/types/base-model-builder.type.d.ts +0 -15
  239. package/domain/generic/model/types/identifier-model.type.d.ts +0 -7
  240. package/domain/generic/model/types/model-base-structure.type.d.ts +0 -6
  241. package/domain/generic/model/types/non-function-properties.type.d.ts +0 -12
  242. package/domain/generic/model/types/non-function-property-name.type.d.ts +0 -4
  243. package/domain/generic/repository/create.repository.d.ts +0 -8
  244. package/domain/generic/repository/crud.repository.d.ts +0 -19
  245. package/domain/generic/repository/delete.repository.d.ts +0 -7
  246. package/domain/generic/repository/find.repository.d.ts +0 -11
  247. package/domain/generic/repository/get.repository.d.ts +0 -5
  248. package/domain/generic/repository/read.repository.d.ts +0 -14
  249. package/domain/generic/repository/types/repository-find-filters.type.d.ts +0 -13
  250. package/domain/generic/repository/types/where-options.type.d.ts +0 -2
  251. package/domain/generic/repository/update.repository.d.ts +0 -6
  252. package/domain/shopping/models/coupons/enums/coupon-subtypes.enum.d.ts +0 -4
  253. package/domain/shopping/models/coupons/enums/coupon-types.enum.d.ts +0 -6
  254. package/domain/shopping/models/coupons/financial-coupon.d.ts +0 -9
  255. package/esm2015/domain/catalog/models/kit-product.js +0 -18
  256. package/esm2015/domain/generic/model/base.model.js +0 -23
  257. package/esm2015/domain/generic/model/index.js +0 -4
  258. package/esm2015/domain/generic/model/types/base-model-builder.type.js +0 -2
  259. package/esm2015/domain/generic/model/types/identifier-model.type.js +0 -2
  260. package/esm2015/domain/generic/model/types/index.js +0 -6
  261. package/esm2015/domain/generic/model/types/model-base-structure.type.js +0 -2
  262. package/esm2015/domain/generic/model/types/non-function-properties.type.js +0 -2
  263. package/esm2015/domain/generic/model/types/non-function-property-name.type.js +0 -2
  264. package/esm2015/domain/generic/repository/create.repository.js +0 -2
  265. package/esm2015/domain/generic/repository/crud.repository.js +0 -2
  266. package/esm2015/domain/generic/repository/delete.repository.js +0 -2
  267. package/esm2015/domain/generic/repository/enums/where.enum.js +0 -15
  268. package/esm2015/domain/generic/repository/find.repository.js +0 -2
  269. package/esm2015/domain/generic/repository/get.repository.js +0 -2
  270. package/esm2015/domain/generic/repository/read.repository.js +0 -2
  271. package/esm2015/domain/generic/repository/types/index.js +0 -7
  272. package/esm2015/domain/generic/repository/types/repository-find-filters.type.js +0 -2
  273. package/esm2015/domain/generic/repository/types/repository-update-params.type.js +0 -2
  274. package/esm2015/domain/generic/repository/types/where-options.type.js +0 -2
  275. package/esm2015/domain/generic/repository/update.repository.js +0 -2
  276. package/esm2015/domain/shopping/models/coupons/enums/coupon-subtypes.enum.js +0 -6
  277. package/esm2015/domain/shopping/models/coupons/enums/coupon-types.enum.js +0 -8
  278. package/esm2015/domain/shopping/models/coupons/financial-coupon.js +0 -28
  279. package/esm2015/infra/hasura-graphql/enums/hasura-graphql-column-type.enum.js +0 -13
  280. package/esm2015/infra/hasura-graphql/enums/hasura-graphql-where.enum.js +0 -15
  281. package/esm2015/infra/hasura-graphql/enums/index.js +0 -3
  282. package/esm2015/infra/hasura-graphql/index.js +0 -5
  283. package/esm2015/infra/hasura-graphql/mixins/helpers/attribute-option.helper.js +0 -31
  284. package/esm2015/infra/hasura-graphql/mixins/helpers/filter-option.helper.js +0 -18
  285. package/esm2015/infra/hasura-graphql/mixins/helpers/graphql-field.helper.js +0 -72
  286. package/esm2015/infra/hasura-graphql/mixins/helpers/index.js +0 -4
  287. package/esm2015/infra/hasura-graphql/mixins/index.js +0 -8
  288. package/esm2015/infra/hasura-graphql/mixins/with-create-hasura-graphql.mixin.js +0 -45
  289. package/esm2015/infra/hasura-graphql/mixins/with-crud-hasura-graphql.mixin.js +0 -10
  290. package/esm2015/infra/hasura-graphql/mixins/with-delete-hasura-graphql.mixin.js +0 -29
  291. package/esm2015/infra/hasura-graphql/mixins/with-find-hasura-graphql.mixin.js +0 -93
  292. package/esm2015/infra/hasura-graphql/mixins/with-get-hasura-graphql.mixin.js +0 -35
  293. package/esm2015/infra/hasura-graphql/mixins/with-hasura-graphql.mixin.js +0 -94
  294. package/esm2015/infra/hasura-graphql/mixins/with-update-hasura-graphql.mixin.js +0 -56
  295. package/esm2015/infra/hasura-graphql/models/category-hasura-graphql.js +0 -4
  296. package/esm2015/infra/hasura-graphql/models/index.js +0 -5
  297. package/esm2015/infra/hasura-graphql/models/kit-product-hasura-graphql.js +0 -15
  298. package/esm2015/infra/hasura-graphql/models/product-hasura-graphql.js +0 -11
  299. package/esm2015/infra/hasura-graphql/models/variant-hasura-graphql.js +0 -9
  300. package/esm2015/infra/hasura-graphql/repositories/catalog/category-hasura-graphql.repository.js +0 -136
  301. package/esm2015/infra/hasura-graphql/repositories/catalog/index.js +0 -4
  302. package/esm2015/infra/hasura-graphql/repositories/catalog/product-hasura-graphql.repository.js +0 -375
  303. package/esm2015/infra/hasura-graphql/repositories/catalog/variant-hasura-graphql.repository.js +0 -100
  304. package/esm2015/infra/hasura-graphql/repositories/index.js +0 -2
  305. package/esm2015/infra/hasura-graphql/types/fields.type.js +0 -2
  306. package/esm2015/infra/hasura-graphql/types/graphql.repository.type.js +0 -2
  307. package/esm2015/infra/hasura-graphql/types/hasura-graphql-auth-options.type.js +0 -2
  308. package/esm2015/infra/hasura-graphql/types/hasura-graphql-fields.type.js +0 -2
  309. package/esm2015/infra/hasura-graphql/types/hasura-graphql-headers.type.js +0 -2
  310. package/esm2015/infra/hasura-graphql/types/index.js +0 -9
  311. package/esm2015/infra/hasura-graphql/types/nested-field.type.js +0 -2
  312. package/esm2015/infra/hasura-graphql/types/query-builder-options.type.js +0 -2
  313. package/esm2015/infra/hasura-graphql/types/variable-options.type.js +0 -2
  314. package/esm2015/utils/is-uuid.js +0 -3
  315. package/esm2015/utils/mixins/merge-constructor-params.type.js +0 -2
  316. package/esm2015/utils/parse-datetime.js +0 -14
  317. package/esm2015/utils/types/array-element.type.js +0 -2
  318. package/infra/hasura-graphql/enums/hasura-graphql-column-type.enum.d.ts +0 -11
  319. package/infra/hasura-graphql/enums/hasura-graphql-where.enum.d.ts +0 -13
  320. package/infra/hasura-graphql/enums/index.d.ts +0 -2
  321. package/infra/hasura-graphql/index.d.ts +0 -4
  322. package/infra/hasura-graphql/mixins/helpers/attribute-option.helper.d.ts +0 -13
  323. package/infra/hasura-graphql/mixins/helpers/filter-option.helper.d.ts +0 -6
  324. package/infra/hasura-graphql/mixins/helpers/graphql-field.helper.d.ts +0 -8
  325. package/infra/hasura-graphql/mixins/helpers/index.d.ts +0 -3
  326. package/infra/hasura-graphql/mixins/index.d.ts +0 -7
  327. package/infra/hasura-graphql/mixins/with-create-hasura-graphql.mixin.d.ts +0 -8
  328. package/infra/hasura-graphql/mixins/with-crud-hasura-graphql.mixin.d.ts +0 -11
  329. package/infra/hasura-graphql/mixins/with-delete-hasura-graphql.mixin.d.ts +0 -7
  330. package/infra/hasura-graphql/mixins/with-find-hasura-graphql.mixin.d.ts +0 -31
  331. package/infra/hasura-graphql/mixins/with-get-hasura-graphql.mixin.d.ts +0 -24
  332. package/infra/hasura-graphql/mixins/with-hasura-graphql.mixin.d.ts +0 -11
  333. package/infra/hasura-graphql/mixins/with-update-hasura-graphql.mixin.d.ts +0 -14
  334. package/infra/hasura-graphql/models/category-hasura-graphql.d.ts +0 -6
  335. package/infra/hasura-graphql/models/index.d.ts +0 -4
  336. package/infra/hasura-graphql/models/kit-product-hasura-graphql.d.ts +0 -6
  337. package/infra/hasura-graphql/models/product-hasura-graphql.d.ts +0 -9
  338. package/infra/hasura-graphql/models/variant-hasura-graphql.d.ts +0 -9
  339. package/infra/hasura-graphql/repositories/catalog/category-hasura-graphql.repository.d.ts +0 -22
  340. package/infra/hasura-graphql/repositories/catalog/index.d.ts +0 -3
  341. package/infra/hasura-graphql/repositories/catalog/product-hasura-graphql.repository.d.ts +0 -26
  342. package/infra/hasura-graphql/repositories/catalog/variant-hasura-graphql.repository.d.ts +0 -13
  343. package/infra/hasura-graphql/repositories/index.d.ts +0 -1
  344. package/infra/hasura-graphql/types/fields.type.d.ts +0 -2
  345. package/infra/hasura-graphql/types/graphql.repository.type.d.ts +0 -21
  346. package/infra/hasura-graphql/types/hasura-graphql-auth-options.type.d.ts +0 -8
  347. package/infra/hasura-graphql/types/hasura-graphql-fields.type.d.ts +0 -36
  348. package/infra/hasura-graphql/types/hasura-graphql-headers.type.d.ts +0 -7
  349. package/infra/hasura-graphql/types/index.d.ts +0 -8
  350. package/infra/hasura-graphql/types/nested-field.type.d.ts +0 -7
  351. package/infra/hasura-graphql/types/query-builder-options.type.d.ts +0 -7
  352. package/infra/hasura-graphql/types/variable-options.type.d.ts +0 -9
  353. package/utils/is-uuid.d.ts +0 -1
  354. package/utils/mixins/merge-constructor-params.type.d.ts +0 -3
  355. package/utils/parse-datetime.d.ts +0 -1
  356. package/utils/types/array-element.type.d.ts +0 -1
  357. /package/domain/{generic → general}/index.d.ts +0 -0
  358. /package/domain/{generic → general}/model/identifier-fields.d.ts +0 -0
  359. /package/domain/{generic → general}/repository/enums/index.d.ts +0 -0
  360. /package/domain/{generic → general}/repository/enums/update-option-actions.enum.d.ts +0 -0
  361. /package/domain/{generic → general}/repository/index.d.ts +0 -0
  362. /package/domain/{generic → general}/repository/types/repository-find-result.type.d.ts +0 -0
  363. /package/domain/{generic → general}/repository/types/repository-limit-options.type.d.ts +0 -0
  364. /package/domain/{generic → general}/repository/types/repository-order-by-list.type.d.ts +0 -0
@@ -1,46 +1,24 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('reflect-metadata'), require('class-transformer'), require('date-fns'), require('lodash'), require('ts-custom-error'), require('ts-md5'), require('axios'), require('firebase'), require('gql-query-builder'), require('node-fetch')) :
3
- typeof define === 'function' && define.amd ? define('@infrab4a/connect', ['exports', 'reflect-metadata', 'class-transformer', 'date-fns', 'lodash', 'ts-custom-error', 'ts-md5', 'axios', 'firebase', 'gql-query-builder', 'node-fetch'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.infrab4a = global.infrab4a || {}, global.infrab4a.connect = {}), null, global["class-transformer"], global["date-fns"], global.lodash, global["ts-custom-error"], global["ts-md5"], global.axios, global.firebase, global["gql-query-builder"], global["node-fetch"]));
5
- })(this, (function (exports, reflectMetadata, classTransformer, dateFns, lodash, tsCustomError, tsMd5, axios, firebase, gqlQueryBuilder, fetch) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('reflect-metadata'), require('class-transformer'), require('date-fns'), require('lodash'), require('axios'), require('firebase'), require('firebase/app')) :
3
+ typeof define === 'function' && define.amd ? define('@infrab4a/connect', ['exports', 'reflect-metadata', 'class-transformer', 'date-fns', 'lodash', 'axios', 'firebase', 'firebase/app'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.infrab4a = global.infrab4a || {}, global.infrab4a.connect = {}), null, global["class-transformer"], global["date-fns"], global.lodash, global.axios, global.firebase, global.firebase$1));
5
+ })(this, (function (exports, reflectMetadata, classTransformer, dateFns, lodash, axios, firebase, firebase$1) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
9
9
  var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
10
10
  var firebase__default = /*#__PURE__*/_interopDefaultLegacy(firebase);
11
- var fetch__default = /*#__PURE__*/_interopDefaultLegacy(fetch);
11
+ var firebase__default$1 = /*#__PURE__*/_interopDefaultLegacy(firebase$1);
12
12
 
13
13
  var BaseModel = /** @class */ (function () {
14
14
  function BaseModel(args) {
15
15
  Object.assign(this, args);
16
16
  }
17
- Object.defineProperty(BaseModel.prototype, "identifier", {
18
- get: function () {
19
- var _this = this;
20
- var fields = this.constructor.identifiersFields.filter(function (field) { return field !== 'identifier'; });
21
- return fields.reduce(function (object, field) {
22
- var _a;
23
- return (Object.assign(Object.assign({}, object), (_a = {}, _a[field] = _this[field], _a)));
24
- }, {});
25
- },
26
- enumerable: false,
27
- configurable: true
28
- });
29
- Object.defineProperty(BaseModel.prototype, "identifiersFields", {
30
- get: function () {
31
- return this.constructor.identifiersFields;
32
- },
33
- enumerable: false,
34
- configurable: true
35
- });
36
17
  BaseModel.toInstance = function (data) {
37
- return classTransformer.plainToInstance(this, data || {});
38
- };
39
- BaseModel.isModel = function (value) {
40
- return value instanceof this;
18
+ return classTransformer.plainToClass(this, data);
41
19
  };
42
20
  BaseModel.prototype.toPlain = function () {
43
- return classTransformer.instanceToPlain(this);
21
+ return classTransformer.classToPlain(this, { exposeUnsetFields: false });
44
22
  };
45
23
  return BaseModel;
46
24
  }());
@@ -48,16 +26,13 @@
48
26
  exports.Where = void 0;
49
27
  (function (Where) {
50
28
  Where["EQUALS"] = "==";
29
+ Where["NOTEQUALS"] = "!=";
51
30
  Where["GT"] = ">";
52
31
  Where["GTE"] = ">=";
53
32
  Where["IN"] = "in";
54
- Where["NOTIN"] = "not in";
55
33
  Where["LT"] = "<";
56
34
  Where["LTE"] = "<=";
57
35
  Where["LIKE"] = "like";
58
- Where["NOTLIKE"] = "not like";
59
- Where["ISNULL"] = "is null";
60
- Where["ISNOTNULL"] = "is not null";
61
36
  })(exports.Where || (exports.Where = {}));
62
37
 
63
38
  exports.UpdateOptionActions = void 0;
@@ -612,13 +587,9 @@
612
587
  function Edition() {
613
588
  return _super !== null && _super.apply(this, arguments) || this;
614
589
  }
615
- Object.defineProperty(Edition, "identifiersFields", {
616
- get: function () {
617
- return ['id', 'subscriptionId'];
618
- },
619
- enumerable: false,
620
- configurable: true
621
- });
590
+ Edition.prototype.identifierFields = function () {
591
+ return ['id'];
592
+ };
622
593
  return Edition;
623
594
  }(BaseModel));
624
595
 
@@ -627,13 +598,9 @@
627
598
  function Payment() {
628
599
  return _super !== null && _super.apply(this, arguments) || this;
629
600
  }
630
- Object.defineProperty(Payment, "identifiersFields", {
631
- get: function () {
632
- return ['id'];
633
- },
634
- enumerable: false,
635
- configurable: true
636
- });
601
+ Payment.prototype.identifierFields = function () {
602
+ return ['id'];
603
+ };
637
604
  return Payment;
638
605
  }(BaseModel));
639
606
  __decorate([
@@ -802,13 +769,9 @@
802
769
  function SubscriptionPayment() {
803
770
  return _super !== null && _super.apply(this, arguments) || this;
804
771
  }
805
- Object.defineProperty(SubscriptionPayment, "identifiersFields", {
806
- get: function () {
807
- return ['id', 'subscriptionId'];
808
- },
809
- enumerable: false,
810
- configurable: true
811
- });
772
+ SubscriptionPayment.prototype.identifierFields = function () {
773
+ return ['id'];
774
+ };
812
775
  return SubscriptionPayment;
813
776
  }(BaseModel));
814
777
  __decorate([
@@ -821,13 +784,6 @@
821
784
  function Address() {
822
785
  return _super !== null && _super.apply(this, arguments) || this;
823
786
  }
824
- Object.defineProperty(Address, "identifiersFields", {
825
- get: function () {
826
- return ['id'];
827
- },
828
- enumerable: false,
829
- configurable: true
830
- });
831
787
  return Address;
832
788
  }(BaseModel));
833
789
 
@@ -842,19 +798,19 @@
842
798
  return Base;
843
799
  }());
844
800
 
845
- var isUUID = function (value) { return lodash.isString(value) && /[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}/.test(value); };
801
+ exports.DiscountType = void 0;
802
+ (function (DiscountType) {
803
+ DiscountType[DiscountType["ABSOLUTE"] = 1] = "ABSOLUTE";
804
+ DiscountType[DiscountType["PERCENTAGE"] = 2] = "PERCENTAGE";
805
+ DiscountType[DiscountType["FREE_SHIPPING"] = 3] = "FREE_SHIPPING";
806
+ })(exports.DiscountType || (exports.DiscountType = {}));
846
807
 
847
- var parseDateTime = function (value) {
848
- if (!lodash.isString(value))
849
- return value;
850
- if (!/^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.test(value) &&
851
- !/^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])T\d{2}:\d{2}:\d{2}/.test(value))
852
- return value;
853
- var date = dateFns.parseISO(value);
854
- if (isNaN(date.getTime()))
855
- return value;
856
- return date;
857
- };
808
+ exports.Exclusivities = void 0;
809
+ (function (Exclusivities) {
810
+ Exclusivities[Exclusivities["ALL_USERS"] = 1] = "ALL_USERS";
811
+ Exclusivities[Exclusivities["SPECIFIC_USER"] = 2] = "SPECIFIC_USER";
812
+ Exclusivities[Exclusivities["COLLABORATORS"] = 3] = "COLLABORATORS";
813
+ })(exports.Exclusivities || (exports.Exclusivities = {}));
858
814
 
859
815
  var Coupon = /** @class */ (function (_super) {
860
816
  __extends(Coupon, _super);
@@ -868,13 +824,17 @@
868
824
  enumerable: false,
869
825
  configurable: true
870
826
  });
871
- Object.defineProperty(Coupon, "identifiersFields", {
872
- get: function () {
873
- return ['id'];
874
- },
875
- enumerable: false,
876
- configurable: true
877
- });
827
+ Coupon.prototype.identifierFields = function () {
828
+ return ['id'];
829
+ };
830
+ Coupon.prototype.calculeDiscount = function (amount) {
831
+ switch (this.discountType) {
832
+ case exports.DiscountType.ABSOLUTE:
833
+ return this.discount < amount ? this.discount : amount;
834
+ case exports.DiscountType.PERCENTAGE:
835
+ return this.discount * 0.01 * amount;
836
+ }
837
+ };
878
838
  return Coupon;
879
839
  }(BaseModel));
880
840
  __decorate([
@@ -891,13 +851,9 @@
891
851
  function SubscriptionPlan() {
892
852
  return _super !== null && _super.apply(this, arguments) || this;
893
853
  }
894
- Object.defineProperty(SubscriptionPlan, "identifiersFields", {
895
- get: function () {
896
- return ['id'];
897
- },
898
- enumerable: false,
899
- configurable: true
900
- });
854
+ SubscriptionPlan.prototype.identifierFields = function () {
855
+ return ['id'];
856
+ };
901
857
  return SubscriptionPlan;
902
858
  }(BaseModel));
903
859
 
@@ -911,13 +867,9 @@
911
867
  delete plain.id;
912
868
  return plain;
913
869
  };
914
- Object.defineProperty(BeautyProfile, "identifiersFields", {
915
- get: function () {
916
- return ['id', 'userId'];
917
- },
918
- enumerable: false,
919
- configurable: true
920
- });
870
+ BeautyProfile.prototype.identifierFields = function () {
871
+ return ['id'];
872
+ };
921
873
  return BeautyProfile;
922
874
  }(BaseModel));
923
875
 
@@ -932,18 +884,14 @@
932
884
  instance.displayName = "" + data.firstName + (!lodash.isNil(data.lastName) ? " " + data.lastName : '');
933
885
  return instance;
934
886
  };
887
+ User.prototype.identifierFields = function () {
888
+ return ['id'];
889
+ };
935
890
  User.prototype.toPlain = function () {
936
891
  var plain = _super.prototype.toPlain.call(this);
937
892
  delete plain.beautyProfile;
938
893
  return plain;
939
894
  };
940
- Object.defineProperty(User, "identifiersFields", {
941
- get: function () {
942
- return ['id'];
943
- },
944
- enumerable: false,
945
- configurable: true
946
- });
947
895
  return User;
948
896
  }(BaseModel));
949
897
  __decorate([
@@ -956,13 +904,9 @@
956
904
  function Subscription() {
957
905
  return _super !== null && _super.apply(this, arguments) || this;
958
906
  }
959
- Object.defineProperty(Subscription, "identifiersFields", {
960
- get: function () {
961
- return ['id'];
962
- },
963
- enumerable: false,
964
- configurable: true
965
- });
907
+ Subscription.prototype.identifierFields = function () {
908
+ return ['id'];
909
+ };
966
910
  return Subscription;
967
911
  }(BaseModel));
968
912
  __decorate([
@@ -999,13 +943,9 @@
999
943
  function UserAddress() {
1000
944
  return _super !== null && _super.apply(this, arguments) || this;
1001
945
  }
1002
- Object.defineProperty(UserAddress, "identifiersFields", {
1003
- get: function () {
1004
- return ['id', 'userId'];
1005
- },
1006
- enumerable: false,
1007
- configurable: true
1008
- });
946
+ UserAddress.prototype.identifierFields = function () {
947
+ return ['id'];
948
+ };
1009
949
  return UserAddress;
1010
950
  }(Address));
1011
951
 
@@ -1014,13 +954,9 @@
1014
954
  function UserPaymentMethod() {
1015
955
  return _super !== null && _super.apply(this, arguments) || this;
1016
956
  }
1017
- Object.defineProperty(UserPaymentMethod, "identifiersFields", {
1018
- get: function () {
1019
- return ['id', 'userId'];
1020
- },
1021
- enumerable: false,
1022
- configurable: true
1023
- });
957
+ UserPaymentMethod.prototype.identifierFields = function () {
958
+ return ['id'];
959
+ };
1024
960
  return UserPaymentMethod;
1025
961
  }(BaseModel));
1026
962
 
@@ -1029,13 +965,9 @@
1029
965
  function Lead() {
1030
966
  return _super !== null && _super.apply(this, arguments) || this;
1031
967
  }
1032
- Object.defineProperty(Lead, "identifiersFields", {
1033
- get: function () {
1034
- return ['id'];
1035
- },
1036
- enumerable: false,
1037
- configurable: true
1038
- });
968
+ Lead.prototype.identifierFields = function () {
969
+ return ['id'];
970
+ };
1039
971
  return Lead;
1040
972
  }(BaseModel));
1041
973
 
@@ -1047,7 +979,7 @@
1047
979
  return _this;
1048
980
  }
1049
981
  return UnauthorizedError;
1050
- }(tsCustomError.CustomError));
982
+ }(Error));
1051
983
 
1052
984
  exports.SignInMethods = void 0;
1053
985
  (function (SignInMethods) {
@@ -1106,7 +1038,7 @@
1106
1038
  return _this;
1107
1039
  }
1108
1040
  return UserAlreadyRegisteredError;
1109
- }(tsCustomError.CustomError));
1041
+ }(Error));
1110
1042
 
1111
1043
  var WeakPasswordError = /** @class */ (function (_super) {
1112
1044
  __extends(WeakPasswordError, _super);
@@ -1117,7 +1049,7 @@
1117
1049
  return _this;
1118
1050
  }
1119
1051
  return WeakPasswordError;
1120
- }(tsCustomError.CustomError));
1052
+ }(Error));
1121
1053
 
1122
1054
  var Register = /** @class */ (function () {
1123
1055
  function Register(registerService, userRepository) {
@@ -1203,6 +1135,13 @@
1203
1135
  return RecoveryPassword;
1204
1136
  }());
1205
1137
 
1138
+ exports.Shops = void 0;
1139
+ (function (Shops) {
1140
+ Shops["MENSMARKET"] = "mensmarket";
1141
+ Shops["GLAMSHOP"] = "Glamshop";
1142
+ Shops["GLAMPOINTS"] = "Glampoints";
1143
+ })(exports.Shops || (exports.Shops = {}));
1144
+
1206
1145
  var Category = /** @class */ (function (_super) {
1207
1146
  __extends(Category, _super);
1208
1147
  function Category() {
@@ -1211,23 +1150,9 @@
1211
1150
  Category.prototype.identifierFields = function () {
1212
1151
  return ['id'];
1213
1152
  };
1214
- Object.defineProperty(Category, "identifiersFields", {
1215
- get: function () {
1216
- return ['id'];
1217
- },
1218
- enumerable: false,
1219
- configurable: true
1220
- });
1221
1153
  return Category;
1222
1154
  }(BaseModel));
1223
1155
 
1224
- exports.Shops = void 0;
1225
- (function (Shops) {
1226
- Shops["MENSMARKET"] = "mensmarket";
1227
- Shops["GLAMSHOP"] = "Glamshop";
1228
- Shops["GLAMPOINTS"] = "Glampoints";
1229
- })(exports.Shops || (exports.Shops = {}));
1230
-
1231
1156
  var Product = /** @class */ (function (_super) {
1232
1157
  __extends(Product, _super);
1233
1158
  function Product() {
@@ -1240,42 +1165,8 @@
1240
1165
  var _a, _b, _c, _d, _e, _f;
1241
1166
  return Object.assign(Object.assign(Object.assign({}, (((_b = (_a = this.description) === null || _a === void 0 ? void 0 : _a[shop]) === null || _b === void 0 ? void 0 : _b.description) ? { description: (_d = (_c = this.description) === null || _c === void 0 ? void 0 : _c[shop]) === null || _d === void 0 ? void 0 : _d.description } : {})), (((_e = this.price) === null || _e === void 0 ? void 0 : _e[shop]) || {})), (((_f = this.stock) === null || _f === void 0 ? void 0 : _f[shop]) || {}));
1242
1167
  };
1243
- Object.defineProperty(Product, "identifiersFields", {
1244
- get: function () {
1245
- return ['id'];
1246
- },
1247
- enumerable: false,
1248
- configurable: true
1249
- });
1250
1168
  return Product;
1251
1169
  }(BaseModel));
1252
- __decorate([
1253
- classTransformer.Type(function () { return KitProduct; }),
1254
- __metadata("design:type", Array)
1255
- ], Product.prototype, "kitProducts", void 0);
1256
-
1257
- var KitProduct = /** @class */ (function (_super) {
1258
- __extends(KitProduct, _super);
1259
- function KitProduct() {
1260
- return _super !== null && _super.apply(this, arguments) || this;
1261
- }
1262
- Object.defineProperty(KitProduct, "identifiersFields", {
1263
- get: function () {
1264
- return ['productId', 'kitProducId'];
1265
- },
1266
- enumerable: false,
1267
- configurable: true
1268
- });
1269
- return KitProduct;
1270
- }(BaseModel));
1271
- __decorate([
1272
- classTransformer.Type(function () { return Product; }),
1273
- __metadata("design:type", Product)
1274
- ], KitProduct.prototype, "kit", void 0);
1275
- __decorate([
1276
- classTransformer.Type(function () { return Product; }),
1277
- __metadata("design:type", Product)
1278
- ], KitProduct.prototype, "product", void 0);
1279
1170
 
1280
1171
  var Variant = /** @class */ (function (_super) {
1281
1172
  __extends(Variant, _super);
@@ -1285,69 +1176,52 @@
1285
1176
  Variant.prototype.identifierFields = function () {
1286
1177
  return ['id'];
1287
1178
  };
1288
- Object.defineProperty(Variant, "identifiersFields", {
1289
- get: function () {
1290
- return ['id', 'productId'];
1291
- },
1292
- enumerable: false,
1293
- configurable: true
1294
- });
1295
1179
  return Variant;
1296
1180
  }(BaseModel));
1297
1181
 
1298
- exports.CouponTypes = void 0;
1299
- (function (CouponTypes) {
1300
- CouponTypes[CouponTypes["FINANCIAL"] = 1] = "FINANCIAL";
1301
- CouponTypes[CouponTypes["PRODUCT"] = 2] = "PRODUCT";
1302
- CouponTypes[CouponTypes["GIFTCARD"] = 3] = "GIFTCARD";
1303
- CouponTypes[CouponTypes["VOUCHER"] = 4] = "VOUCHER";
1304
- })(exports.CouponTypes || (exports.CouponTypes = {}));
1305
-
1306
- exports.CouponSubtypes = void 0;
1307
- (function (CouponSubtypes) {
1308
- CouponSubtypes[CouponSubtypes["ABSOLUTE"] = 1] = "ABSOLUTE";
1309
- CouponSubtypes[CouponSubtypes["PERCENTAGE"] = 2] = "PERCENTAGE";
1310
- })(exports.CouponSubtypes || (exports.CouponSubtypes = {}));
1311
-
1312
- exports.Exclusivities = void 0;
1313
- (function (Exclusivities) {
1314
- Exclusivities[Exclusivities["ALL_USERS"] = 1] = "ALL_USERS";
1315
- Exclusivities[Exclusivities["SPECIFIC_USER"] = 2] = "SPECIFIC_USER";
1316
- Exclusivities[Exclusivities["COLLABORATORS"] = 3] = "COLLABORATORS";
1317
- })(exports.Exclusivities || (exports.Exclusivities = {}));
1318
-
1319
1182
  exports.CheckoutTypes = void 0;
1320
1183
  (function (CheckoutTypes) {
1321
1184
  CheckoutTypes[CheckoutTypes["ECOMMERCE"] = 1] = "ECOMMERCE";
1322
1185
  CheckoutTypes[CheckoutTypes["SUBSCRIPTION"] = 2] = "SUBSCRIPTION";
1323
1186
  })(exports.CheckoutTypes || (exports.CheckoutTypes = {}));
1324
1187
 
1325
- var COUPON_EXPIRATION = 60 * 60 * 24 * 30;
1326
- var FinancialCoupon = /** @class */ (function (_super) {
1327
- __extends(FinancialCoupon, _super);
1328
- function FinancialCoupon() {
1188
+ var ClubCoupon = /** @class */ (function (_super) {
1189
+ __extends(ClubCoupon, _super);
1190
+ function ClubCoupon() {
1329
1191
  var _this = _super.apply(this, __spreadArray([], __read(arguments))) || this;
1330
- _this.type = exports.CouponTypes.FINANCIAL;
1192
+ _this.checkoutType = exports.CheckoutTypes.SUBSCRIPTION;
1331
1193
  return _this;
1332
1194
  }
1333
- FinancialCoupon.isFinancialCoupon = function (coupon) {
1334
- return coupon.type === exports.CouponTypes.FINANCIAL && !!coupon.subtype;
1195
+ ClubCoupon.isClubCoupon = function (coupon) {
1196
+ return coupon instanceof ClubCoupon;
1335
1197
  };
1336
- FinancialCoupon.createCoupon = function (userId) {
1337
- return this.toInstance({
1338
- name: tsMd5.Md5.hashStr(userId + "_" + Date.now).toString(),
1339
- nickname: "" + Date.now(),
1340
- type: exports.CouponTypes.FINANCIAL,
1341
- subtype: exports.CouponSubtypes.PERCENTAGE,
1342
- checkoutType: exports.CheckoutTypes.ECOMMERCE,
1343
- discount: 30,
1344
- user: userId,
1345
- createdAt: new Date(Date.now()),
1346
- expiresIn: new Date(Date.now() + COUPON_EXPIRATION),
1347
- });
1198
+ return ClubCoupon;
1199
+ }(Coupon));
1200
+ __decorate([
1201
+ classTransformer.Expose({ name: 'checkout_type' }),
1202
+ __metadata("design:type", Object)
1203
+ ], ClubCoupon.prototype, "checkoutType", void 0);
1204
+
1205
+ var StoreCoupon = /** @class */ (function (_super) {
1206
+ __extends(StoreCoupon, _super);
1207
+ function StoreCoupon() {
1208
+ var _this = _super.apply(this, __spreadArray([], __read(arguments))) || this;
1209
+ _this.checkoutType = exports.CheckoutTypes.ECOMMERCE;
1210
+ return _this;
1211
+ }
1212
+ StoreCoupon.isStoreCoupon = function (coupon) {
1213
+ return coupon instanceof StoreCoupon;
1348
1214
  };
1349
- return FinancialCoupon;
1215
+ return StoreCoupon;
1350
1216
  }(Coupon));
1217
+ __decorate([
1218
+ classTransformer.Expose({ name: 'checkout_type' }),
1219
+ __metadata("design:type", Object)
1220
+ ], StoreCoupon.prototype, "checkoutType", void 0);
1221
+ __decorate([
1222
+ classTransformer.Type(function () { return Category; }),
1223
+ __metadata("design:type", Array)
1224
+ ], StoreCoupon.prototype, "categories", void 0);
1351
1225
 
1352
1226
  exports.OrderStatus = void 0;
1353
1227
  (function (OrderStatus) {
@@ -1374,13 +1248,9 @@
1374
1248
  function ShippingMethod() {
1375
1249
  return _super !== null && _super.apply(this, arguments) || this;
1376
1250
  }
1377
- Object.defineProperty(ShippingMethod, "identifiersFields", {
1378
- get: function () {
1379
- return ['id'];
1380
- },
1381
- enumerable: false,
1382
- configurable: true
1383
- });
1251
+ ShippingMethod.prototype.identifierFields = function () {
1252
+ return ['id'];
1253
+ };
1384
1254
  return ShippingMethod;
1385
1255
  }(BaseModel));
1386
1256
 
@@ -1389,13 +1259,25 @@
1389
1259
  function Checkout() {
1390
1260
  return _super !== null && _super.apply(this, arguments) || this;
1391
1261
  }
1392
- Object.defineProperty(Checkout, "identifiersFields", {
1262
+ Object.defineProperty(Checkout.prototype, "subTotalPrice", {
1263
+ get: function () {
1264
+ return this.lineItems.reduce(function (total, item) {
1265
+ return total + item.pricePaid;
1266
+ }, 0);
1267
+ },
1268
+ enumerable: false,
1269
+ configurable: true
1270
+ });
1271
+ Object.defineProperty(Checkout.prototype, "totalPrice", {
1393
1272
  get: function () {
1394
- return ['id'];
1273
+ return this.totalPrice - this.discount;
1395
1274
  },
1396
1275
  enumerable: false,
1397
1276
  configurable: true
1398
1277
  });
1278
+ Checkout.prototype.identifierFields = function () {
1279
+ return ['id'];
1280
+ };
1399
1281
  return Checkout;
1400
1282
  }(BaseModel));
1401
1283
  __decorate([
@@ -1419,8 +1301,8 @@
1419
1301
  __metadata("design:type", ShippingMethod)
1420
1302
  ], Checkout.prototype, "shipping", void 0);
1421
1303
  __decorate([
1422
- classTransformer.Type(function () { return Coupon; }),
1423
- __metadata("design:type", Coupon)
1304
+ classTransformer.Type(function () { return StoreCoupon; }),
1305
+ __metadata("design:type", StoreCoupon)
1424
1306
  ], Checkout.prototype, "coupon", void 0);
1425
1307
 
1426
1308
  var Order = /** @class */ (function (_super) {
@@ -1440,13 +1322,9 @@
1440
1322
  function CheckoutSubscription() {
1441
1323
  return _super !== null && _super.apply(this, arguments) || this;
1442
1324
  }
1443
- Object.defineProperty(CheckoutSubscription, "identifiersFields", {
1444
- get: function () {
1445
- return ['id'];
1446
- },
1447
- enumerable: false,
1448
- configurable: true
1449
- });
1325
+ CheckoutSubscription.prototype.identifierFields = function () {
1326
+ return ['id'];
1327
+ };
1450
1328
  return CheckoutSubscription;
1451
1329
  }(BaseModel));
1452
1330
  __decorate([
@@ -1471,13 +1349,9 @@
1471
1349
  function Buy2Win() {
1472
1350
  return _super !== null && _super.apply(this, arguments) || this;
1473
1351
  }
1474
- Object.defineProperty(Buy2Win, "identifiersFields", {
1475
- get: function () {
1476
- return ['id'];
1477
- },
1478
- enumerable: false,
1479
- configurable: true
1480
- });
1352
+ Buy2Win.prototype.identifierFields = function () {
1353
+ return ['id'];
1354
+ };
1481
1355
  return Buy2Win;
1482
1356
  }(BaseModel));
1483
1357
  __decorate([
@@ -1579,13 +1453,9 @@
1579
1453
  function Home() {
1580
1454
  return _super !== null && _super.apply(this, arguments) || this;
1581
1455
  }
1582
- Object.defineProperty(Home, "identifiersFields", {
1583
- get: function () {
1584
- return ['id'];
1585
- },
1586
- enumerable: false,
1587
- configurable: true
1588
- });
1456
+ Home.prototype.identifierFields = function () {
1457
+ return ['id'];
1458
+ };
1589
1459
  return Home;
1590
1460
  }(BaseModel));
1591
1461
 
@@ -1594,13 +1464,9 @@
1594
1464
  function ShopMenu() {
1595
1465
  return _super !== null && _super.apply(this, arguments) || this;
1596
1466
  }
1597
- Object.defineProperty(ShopMenu, "identifiersFields", {
1598
- get: function () {
1599
- return ['id'];
1600
- },
1601
- enumerable: false,
1602
- configurable: true
1603
- });
1467
+ ShopMenu.prototype.identifierFields = function () {
1468
+ return ['id'];
1469
+ };
1604
1470
  return ShopMenu;
1605
1471
  }(BaseModel));
1606
1472
 
@@ -1612,7 +1478,7 @@
1612
1478
  return _this;
1613
1479
  }
1614
1480
  return InvalidArgumentError;
1615
- }(tsCustomError.CustomError));
1481
+ }(Error));
1616
1482
 
1617
1483
  var RequiredArgumentError = /** @class */ (function (_super) {
1618
1484
  __extends(RequiredArgumentError, _super);
@@ -1623,7 +1489,7 @@
1623
1489
  return _this;
1624
1490
  }
1625
1491
  return RequiredArgumentError;
1626
- }(tsCustomError.CustomError));
1492
+ }(Error));
1627
1493
 
1628
1494
  var NotFoundError = /** @class */ (function (_super) {
1629
1495
  __extends(NotFoundError, _super);
@@ -1633,7 +1499,7 @@
1633
1499
  return _this;
1634
1500
  }
1635
1501
  return NotFoundError;
1636
- }(tsCustomError.CustomError));
1502
+ }(Error));
1637
1503
 
1638
1504
  var DuplicatedResultsError = /** @class */ (function (_super) {
1639
1505
  __extends(DuplicatedResultsError, _super);
@@ -1643,35 +1509,12 @@
1643
1509
  return _this;
1644
1510
  }
1645
1511
  return DuplicatedResultsError;
1646
- }(tsCustomError.CustomError));
1512
+ }(Error));
1647
1513
 
1648
1514
  var AxiosAdapter = /** @class */ (function () {
1649
1515
  function AxiosAdapter(config) {
1650
1516
  this.config = config;
1651
1517
  }
1652
- AxiosAdapter.prototype.get = function (index) {
1653
- return __awaiter(this, void 0, void 0, function () {
1654
- var data, error_1;
1655
- return __generator(this, function (_a) {
1656
- switch (_a.label) {
1657
- case 0:
1658
- _a.trys.push([0, 2, , 3]);
1659
- return [4 /*yield*/, axios__default["default"]({
1660
- url: this.config.url + "/" + index,
1661
- method: 'GET',
1662
- headers: { Authorization: "Basic " + this.config.credential },
1663
- })];
1664
- case 1:
1665
- data = (_a.sent()).data;
1666
- return [2 /*return*/, data._source];
1667
- case 2:
1668
- error_1 = _a.sent();
1669
- throw new NotFoundError(error_1.message);
1670
- case 3: return [2 /*return*/];
1671
- }
1672
- });
1673
- });
1674
- };
1675
1518
  AxiosAdapter.prototype.query = function (index, query) {
1676
1519
  return __awaiter(this, void 0, void 0, function () {
1677
1520
  var data;
@@ -1693,60 +1536,14 @@
1693
1536
  });
1694
1537
  });
1695
1538
  };
1696
- AxiosAdapter.prototype.save = function (index, data) {
1697
- return __awaiter(this, void 0, void 0, function () {
1698
- return __generator(this, function (_a) {
1699
- switch (_a.label) {
1700
- case 0: return [4 /*yield*/, axios__default["default"]({
1701
- url: this.config.url + "/" + index,
1702
- method: 'PUT',
1703
- headers: { Authorization: "Basic " + this.config.credential },
1704
- data: data,
1705
- })];
1706
- case 1:
1707
- _a.sent();
1708
- return [2 /*return*/];
1709
- }
1710
- });
1711
- });
1712
- };
1713
- AxiosAdapter.prototype.delete = function (index) {
1714
- return __awaiter(this, void 0, void 0, function () {
1715
- return __generator(this, function (_a) {
1716
- switch (_a.label) {
1717
- case 0: return [4 /*yield*/, axios__default["default"]({
1718
- url: this.config.url + "/" + index,
1719
- method: 'DELETE',
1720
- headers: { Authorization: "Basic " + this.config.credential },
1721
- })];
1722
- case 1:
1723
- _a.sent();
1724
- return [2 /*return*/];
1725
- }
1726
- });
1727
- });
1728
- };
1729
- return AxiosAdapter;
1730
- }());
1731
-
1732
- var ProductsIndex = /** @class */ (function () {
1733
- function ProductsIndex(adapter) {
1734
- this.adapter = adapter;
1735
- }
1736
- ProductsIndex.prototype.get = function (id) {
1737
- return __awaiter(this, void 0, void 0, function () {
1738
- var data;
1739
- return __generator(this, function (_a) {
1740
- switch (_a.label) {
1741
- case 0: return [4 /*yield*/, this.adapter.get("products/_doc/" + id)];
1742
- case 1:
1743
- data = _a.sent();
1744
- return [2 /*return*/, Product.toInstance(data)];
1745
- }
1746
- });
1747
- });
1748
- };
1749
- ProductsIndex.prototype.findById = function (ids, options) {
1539
+ return AxiosAdapter;
1540
+ }());
1541
+
1542
+ var ProductsIndex = /** @class */ (function () {
1543
+ function ProductsIndex(adapter) {
1544
+ this.adapter = adapter;
1545
+ }
1546
+ ProductsIndex.prototype.findById = function (ids, options) {
1750
1547
  return __awaiter(this, void 0, void 0, function () {
1751
1548
  var publishedField, fields, hits;
1752
1549
  var _a;
@@ -1805,64 +1602,6 @@
1805
1602
  });
1806
1603
  });
1807
1604
  };
1808
- ProductsIndex.prototype.save = function (product) {
1809
- return __awaiter(this, void 0, void 0, function () {
1810
- var error_1;
1811
- return __generator(this, function (_a) {
1812
- switch (_a.label) {
1813
- case 0:
1814
- delete product.createdAt;
1815
- delete product.updatedAt;
1816
- delete product.kitProducts;
1817
- _a.label = 1;
1818
- case 1:
1819
- _a.trys.push([1, 4, , 6]);
1820
- if (!product.firestoreId)
1821
- throw new Error('Is not a product from firestore');
1822
- return [4 /*yield*/, this.get(product.firestoreId)];
1823
- case 2:
1824
- _a.sent();
1825
- return [4 /*yield*/, this.adapter.save("products/_doc/" + product.firestoreId, product.toPlain())];
1826
- case 3:
1827
- _a.sent();
1828
- return [3 /*break*/, 6];
1829
- case 4:
1830
- error_1 = _a.sent();
1831
- console.info(error_1.message);
1832
- return [4 /*yield*/, this.adapter.save("products/_doc/" + product.id, product.toPlain())];
1833
- case 5:
1834
- _a.sent();
1835
- return [3 /*break*/, 6];
1836
- case 6: return [2 /*return*/];
1837
- }
1838
- });
1839
- });
1840
- };
1841
- ProductsIndex.prototype.delete = function (product) {
1842
- return __awaiter(this, void 0, void 0, function () {
1843
- var error_2;
1844
- return __generator(this, function (_a) {
1845
- switch (_a.label) {
1846
- case 0:
1847
- _a.trys.push([0, 3, , 5]);
1848
- return [4 /*yield*/, this.get(product.firestoreId)];
1849
- case 1:
1850
- _a.sent();
1851
- return [4 /*yield*/, this.adapter.delete("products/_doc/" + product.firestoreId)];
1852
- case 2:
1853
- _a.sent();
1854
- return [3 /*break*/, 5];
1855
- case 3:
1856
- error_2 = _a.sent();
1857
- return [4 /*yield*/, this.adapter.delete("products/_doc/" + product.id)];
1858
- case 4:
1859
- _a.sent();
1860
- return [3 /*break*/, 5];
1861
- case 5: return [2 /*return*/];
1862
- }
1863
- });
1864
- });
1865
- };
1866
1605
  return ProductsIndex;
1867
1606
  }());
1868
1607
 
@@ -1870,7 +1609,11 @@
1870
1609
  return /** @class */ (function (_super) {
1871
1610
  __extends(class_1, _super);
1872
1611
  function class_1() {
1873
- return _super !== null && _super.apply(this, arguments) || this;
1612
+ var args = [];
1613
+ for (var _i = 0; _i < arguments.length; _i++) {
1614
+ args[_i] = arguments[_i];
1615
+ }
1616
+ return _super.call(this, args) || this;
1874
1617
  }
1875
1618
  class_1.prototype.collection = function (path) {
1876
1619
  return this.firestore.collection(path || this.collectionName).withConverter(this.buildModelInstance());
@@ -1882,7 +1625,7 @@
1882
1625
  fromFirestore: function (snap) {
1883
1626
  var data = snap.data();
1884
1627
  Object.keys(data).forEach(function (key) {
1885
- if (data[key] && typeof data[key] === 'object' && '_seconds' in data[key]) {
1628
+ if (data[key] instanceof firebase__default["default"].firestore.Timestamp) {
1886
1629
  data[key] = data[key].toDate();
1887
1630
  }
1888
1631
  });
@@ -1981,28 +1724,28 @@
1981
1724
  if ((options === null || options === void 0 ? void 0 : options.operator) === exports.Where.IN && Array.isArray(options === null || options === void 0 ? void 0 : options.value))
1982
1725
  return queryReference.where(firestoreFieldName, 'array-contains', options.value);
1983
1726
  if (lodash.isObject(options) && lodash.isNil(options === null || options === void 0 ? void 0 : options.operator) && lodash.isNil(options === null || options === void 0 ? void 0 : options.value)) {
1984
- return Object.keys(options).reduce(function (queryReferenceWithWhere, key) { return _this.buildWhereSentence(queryReferenceWithWhere, fieldName.toString() + "." + key, options[key]); }, queryReference);
1727
+ return Object.keys(options).reduce(function (queryReferenceWithWhere, key) { return _this.buildWhereSentence(queryReferenceWithWhere, fieldName + "." + key, options[key]); }, queryReference);
1985
1728
  }
1986
1729
  return queryReference.where(firestoreFieldName, (options === null || options === void 0 ? void 0 : options.operator) || '==', (options === null || options === void 0 ? void 0 : options.value) || options);
1987
1730
  };
1988
1731
  return _this;
1989
1732
  }
1990
- FindFirestore.prototype.find = function (_a) {
1991
- var _b = _a === void 0 ? {} : _a, filters = _b.filters, limits = _b.limits, orderBy = _b.orderBy;
1733
+ FindFirestore.prototype.find = function (filters, limits, orderBy) {
1992
1734
  return __awaiter(this, void 0, void 0, function () {
1993
1735
  var query, docs, data;
1994
- return __generator(this, function (_a) {
1995
- switch (_a.label) {
1736
+ var _this = this;
1737
+ return __generator(this, function (_b) {
1738
+ switch (_b.label) {
1996
1739
  case 0:
1997
- query = this.collection(this.buildCollectionPathForFind(filters || {}));
1998
- query = this.makeFirestoreWhere(query, filters || {});
1999
- Object.keys(orderBy || {}).forEach(function (fieldName) { return (query = query.orderBy(fieldName, orderBy[fieldName])); });
1740
+ query = this.collection(this.buildCollectionPathForFind(filters));
1741
+ filters === null || filters === void 0 ? void 0 : filters.forEach(function (filterer) { return (query = _this.makeFirestoreWhere(query, filterer)); });
1742
+ orderBy === null || orderBy === void 0 ? void 0 : orderBy.forEach(function (orderer) { return Object.keys(orderer).forEach(function (fieldName) { return (query = query.orderBy(fieldName, orderer[fieldName])); }); });
2000
1743
  return [4 /*yield*/, this.defineLimits(query, filters, limits)];
2001
1744
  case 1:
2002
- query = _a.sent();
1745
+ query = _b.sent();
2003
1746
  return [4 /*yield*/, query.get()];
2004
1747
  case 2:
2005
- docs = _a.sent();
1748
+ docs = _b.sent();
2006
1749
  data = docs.docs.map(function (doc) { return doc.data(); });
2007
1750
  return [2 /*return*/, {
2008
1751
  data: data,
@@ -2013,31 +1756,32 @@
2013
1756
  });
2014
1757
  };
2015
1758
  FindFirestore.prototype.buildCollectionPathForFind = function (filters) {
1759
+ var _a;
2016
1760
  if (!this.isSubCollection(this))
2017
1761
  return this.collectionName;
2018
1762
  var parentIdField = this.parentIdField;
2019
- var parentId = getValueFromFilter(filters === null || filters === void 0 ? void 0 : filters[parentIdField]);
1763
+ var parentId = getValueFromFilter((_a = filters.find(function (groupFilter) { return Boolean(getValueFromFilter(groupFilter[parentIdField])); })) === null || _a === void 0 ? void 0 : _a[parentIdField]);
2020
1764
  return this.parentRepository.collectionName + "/" + parentId + "/" + this.collectionName;
2021
1765
  };
2022
1766
  FindFirestore.prototype.defineLimits = function (query, filters, limits) {
2023
1767
  return __awaiter(this, void 0, void 0, function () {
2024
- var _a, _b;
2025
- return __generator(this, function (_c) {
2026
- switch (_c.label) {
1768
+ var _b, _c;
1769
+ return __generator(this, function (_d) {
1770
+ switch (_d.label) {
2027
1771
  case 0:
2028
1772
  if (!(limits === null || limits === void 0 ? void 0 : limits.offset)) return [3 /*break*/, 3];
2029
- if (!this.model.isModel(limits.offset)) return [3 /*break*/, 2];
2030
- _b = (_a = query).startAfter;
1773
+ if (!(limits.offset instanceof this.model)) return [3 /*break*/, 2];
1774
+ _c = (_b = query).startAfter;
2031
1775
  return [4 /*yield*/, this.collection(this.buildCollectionPathForFind(filters))
2032
- .doc(limits.offset[limits.offset.identifiersFields.shift()])
1776
+ .doc(limits.offset[limits.offset.identifierFields().shift()])
2033
1777
  .get()];
2034
1778
  case 1:
2035
- query = _b.apply(_a, [_c.sent()]);
1779
+ query = _c.apply(_b, [_d.sent()]);
2036
1780
  return [3 /*break*/, 3];
2037
1781
  case 2:
2038
1782
  if (lodash.isNumber(limits.offset) || lodash.isString(limits.offset))
2039
1783
  query = query.startAt(limits.offset);
2040
- _c.label = 3;
1784
+ _d.label = 3;
2041
1785
  case 3:
2042
1786
  if (limits === null || limits === void 0 ? void 0 : limits.limit)
2043
1787
  query = query.limit(limits.limit);
@@ -2086,7 +1830,7 @@
2086
1830
  return __generator(this, function (_b) {
2087
1831
  switch (_b.label) {
2088
1832
  case 0:
2089
- id = (_a = data[data.identifiersFields.shift()]) === null || _a === void 0 ? void 0 : _a.toString();
1833
+ id = (_a = data[data.identifierFields().shift()]) === null || _a === void 0 ? void 0 : _a.toString();
2090
1834
  collectionPath = this.buildCollectionPathForAdd(data);
2091
1835
  if (lodash.isEmpty(id))
2092
1836
  return [2 /*return*/, this.collection(collectionPath).add(data)];
@@ -2136,7 +1880,7 @@
2136
1880
  switch (_b.label) {
2137
1881
  case 0:
2138
1882
  model = new this.model();
2139
- keyField = model.identifiersFields.shift();
1883
+ keyField = model.identifierFields().shift();
2140
1884
  docRef = this.collection(this.buildCollectionPathForUpdate(data)).doc(getValueFromParams(data, keyField).toString());
2141
1885
  return [4 /*yield*/, docRef.set(this.paramsToPlain(data), { merge: true })];
2142
1886
  case 1:
@@ -2156,8 +1900,8 @@
2156
1900
  };
2157
1901
  UpdateFirestore.prototype.paramsToPlain = function (params) {
2158
1902
  var model = this.model;
2159
- if (model.isModel(params))
2160
- return params.toPlain();
1903
+ if (params instanceof model)
1904
+ return params;
2161
1905
  return Object.keys(params).reduce(function (data, currentKey) {
2162
1906
  var _b;
2163
1907
  return (Object.assign(Object.assign({}, data), (_b = {}, _b[currentKey] = getValueByAction(params[currentKey]), _b)));
@@ -2240,13 +1984,9 @@
2240
1984
  function UserSearch() {
2241
1985
  return _super !== null && _super.apply(this, arguments) || this;
2242
1986
  }
2243
- Object.defineProperty(UserSearch, "identifiersFields", {
2244
- get: function () {
2245
- return ['id'];
2246
- },
2247
- enumerable: false,
2248
- configurable: true
2249
- });
1987
+ UserSearch.prototype.identifierFields = function () {
1988
+ return ['id'];
1989
+ };
2250
1990
  return UserSearch;
2251
1991
  }(BaseModel));
2252
1992
 
@@ -2303,7 +2043,7 @@
2303
2043
  var _a;
2304
2044
  return __generator(this, function (_b) {
2305
2045
  switch (_b.label) {
2306
- case 0: return [4 /*yield*/, this.userSearchFirestoreRepository.find((_a = {}, _a[field] = { operator: exports.Where.EQUALS, value: value }, _a))];
2046
+ case 0: return [4 /*yield*/, this.userSearchFirestoreRepository.find([(_a = {}, _a[field] = { operator: exports.Where.EQUALS, value: value }, _a)])];
2307
2047
  case 1:
2308
2048
  result = _b.sent();
2309
2049
  return [2 /*return*/, result.count > 0];
@@ -2531,9 +2271,7 @@
2531
2271
  productIds = chunks_1_1.value;
2532
2272
  if ((options === null || options === void 0 ? void 0 : options.limit) && products.length >= (options === null || options === void 0 ? void 0 : options.limit))
2533
2273
  return [3 /*break*/, 6];
2534
- return [4 /*yield*/, this.collection('productsErpVitrine')
2535
- .where(publishedField, '==', true)
2536
- .where('id', 'in', productIds)];
2274
+ return [4 /*yield*/, this.collection('products').where(publishedField, '==', true).where('id', 'in', productIds)];
2537
2275
  case 3:
2538
2276
  query = _b.sent();
2539
2277
  if (options === null || options === void 0 ? void 0 : options.hasStock)
@@ -2574,22 +2312,20 @@
2574
2312
  function ProductFirestoreRepository(firestore) {
2575
2313
  var _this = _super.call(this) || this;
2576
2314
  _this.firestore = firestore;
2577
- _this.reviews = {};
2578
- _this.collectionName = 'productsErpVitrine';
2315
+ _this.collectionName = 'products';
2579
2316
  _this.model = Product;
2580
2317
  return _this;
2581
2318
  }
2582
- ProductFirestoreRepository.prototype.getBySlug = function (slug) {
2319
+ ProductFirestoreRepository.prototype.getBySlug = function (slug, shop) {
2583
2320
  var _a;
2584
2321
  return __awaiter(this, void 0, void 0, function () {
2585
2322
  var result;
2586
2323
  return __generator(this, function (_b) {
2587
2324
  switch (_b.label) {
2588
- case 0: return [4 /*yield*/, this.find({
2589
- filters: {
2590
- slug: { operator: exports.Where.EQUALS, value: slug },
2591
- },
2592
- })];
2325
+ case 0: return [4 /*yield*/, this.find([
2326
+ { slug: { operator: exports.Where.EQUALS, value: slug } },
2327
+ { shopAvailability: { operator: exports.Where.IN, value: [shop] } },
2328
+ ])];
2593
2329
  case 1:
2594
2330
  result = _b.sent();
2595
2331
  return [2 /*return*/, (_a = result === null || result === void 0 ? void 0 : result.data) === null || _a === void 0 ? void 0 : _a.shift()];
@@ -2597,41 +2333,6 @@
2597
2333
  });
2598
2334
  });
2599
2335
  };
2600
- ProductFirestoreRepository.prototype.fetchReviews = function (status) {
2601
- return __awaiter(this, void 0, void 0, function () {
2602
- var products;
2603
- var _this = this;
2604
- return __generator(this, function (_b) {
2605
- switch (_b.label) {
2606
- case 0: return [4 /*yield*/, this.find()];
2607
- case 1:
2608
- products = (_b.sent()).data;
2609
- products.forEach(function (product) {
2610
- var _a;
2611
- if ([undefined, 0].includes((_a = product.reviews) === null || _a === void 0 ? void 0 : _a.length))
2612
- return;
2613
- var productInfo = {
2614
- productId: product.id,
2615
- productName: product.name,
2616
- productSku: product.sku,
2617
- };
2618
- _this.reviews.pending = [];
2619
- _this.reviews.approved = [];
2620
- _this.reviews.rejected = [];
2621
- product.reviews.forEach(function (review) {
2622
- if ([null, undefined].includes(review.status))
2623
- return _this.reviews.pending.push(Object.assign(Object.assign({}, review), productInfo));
2624
- if (review.status === false)
2625
- return _this.reviews.rejected.push(Object.assign(Object.assign({}, review), productInfo));
2626
- if (!!review.status)
2627
- return _this.reviews.approved.push(Object.assign(Object.assign({}, review), productInfo));
2628
- });
2629
- });
2630
- return [2 /*return*/, this.reviews[status]];
2631
- }
2632
- });
2633
- });
2634
- };
2635
2336
  return ProductFirestoreRepository;
2636
2337
  }(withCrudFirestore(withHelpers(withFirestore(Base)))));
2637
2338
 
@@ -2683,19 +2384,29 @@
2683
2384
  return _this;
2684
2385
  }
2685
2386
  CouponFirestoreRepository.prototype.buildModelInstance = function () {
2686
- var _a = _super.prototype.buildModelInstance.call(this), fromFirestore = _a.fromFirestore, toFirestore = _a.toFirestore;
2387
+ var _this = this;
2687
2388
  return {
2688
2389
  toFirestore: function (data) {
2689
- var plain = toFirestore(data);
2690
- if (!!data.expiresIn)
2691
- plain.expiresIn = data.expiresIn.getTime();
2390
+ var _a;
2391
+ var plain = (data === null || data === void 0 ? void 0 : data.toPlain) ? data.toPlain() : data;
2392
+ if (!!plain.categories)
2393
+ plain.categories = (_a = plain === null || plain === void 0 ? void 0 : plain.categories) === null || _a === void 0 ? void 0 : _a.map(function (category) { return category.id; });
2692
2394
  return plain;
2693
2395
  },
2694
2396
  fromFirestore: function (snap) {
2695
- var instance = fromFirestore(snap);
2696
- if (!lodash.isNil(instance.expiresIn))
2697
- instance.expiresIn = new Date(snap.data().expiresIn);
2698
- return instance;
2397
+ var _a;
2398
+ var data = snap.data();
2399
+ Object.keys(data).forEach(function (key) {
2400
+ if (data[key] instanceof firebase__default["default"].firestore.Timestamp) {
2401
+ data[key] = data[key].toDate();
2402
+ }
2403
+ });
2404
+ data.categories = (_a = data === null || data === void 0 ? void 0 : data.categories) === null || _a === void 0 ? void 0 : _a.map(function (category) { return ({ id: category }); });
2405
+ if (data.checkout_type === exports.CheckoutTypes.SUBSCRIPTION)
2406
+ return ClubCoupon.toInstance(Object.assign({ id: snap.id }, data));
2407
+ if (data.checkout_type === exports.CheckoutTypes.ECOMMERCE)
2408
+ return StoreCoupon.toInstance(Object.assign({ id: snap.id }, data));
2409
+ return _this.model.toInstance(Object.assign({ id: snap.id }, data));
2699
2410
  },
2700
2411
  };
2701
2412
  };
@@ -2870,7 +2581,7 @@
2870
2581
  var credentials, user;
2871
2582
  return __generator(this, function (_a) {
2872
2583
  switch (_a.label) {
2873
- case 0: return [4 /*yield*/, this.firebaseAuth.signInWithPopup(new firebase__default["default"].auth.GoogleAuthProvider())];
2584
+ case 0: return [4 /*yield*/, this.firebaseAuth.signInWithPopup(new firebase__default$1["default"].auth.GoogleAuthProvider())];
2874
2585
  case 1:
2875
2586
  credentials = _a.sent();
2876
2587
  user = credentials.user;
@@ -2951,1594 +2662,14 @@
2951
2662
  return RegisterFirebaseAuthService;
2952
2663
  }());
2953
2664
 
2954
- var AttributeOptionHelper = /** @class */ (function () {
2955
- function AttributeOptionHelper() {
2956
- }
2957
- return AttributeOptionHelper;
2958
- }());
2959
- AttributeOptionHelper.FindByAttribute = function (attributeName, fields) {
2960
- if (fields.includes(attributeName))
2961
- return { columnName: attributeName.toString(), attributeName: attributeName };
2962
- var field = fields.find(function (columnOption) { return lodash.isObject(columnOption) && Object.keys(columnOption).includes(attributeName.toString()); });
2963
- var fieldOption = field === null || field === void 0 ? void 0 : field[attributeName.toString()];
2964
- if (lodash.isNil(fieldOption))
2965
- return { columnName: attributeName.toString(), attributeName: attributeName };
2966
- if (Array.isArray(fieldOption))
2967
- return { columnName: attributeName.toString(), attributeName: attributeName, fields: fieldOption };
2968
- return Object.assign({ attributeName: attributeName, columnName: attributeName.toString() }, fieldOption);
2969
- };
2970
- AttributeOptionHelper.CheckIsColumnOption = function (fieldValue) { return !!fieldValue.columnName; };
2971
- AttributeOptionHelper.FindColumnOptionFromList = function (columnName, fields) {
2972
- if (fields.includes(columnName))
2973
- return { columnName: columnName, attributeName: columnName };
2974
- var field = fields.find(function (columnOption) {
2975
- var _a;
2976
- return lodash.isObject(columnOption) &&
2977
- ((_a = Object.values(columnOption).find(function (option) { return AttributeOptionHelper.CheckIsColumnOption(option) && option.columnName === columnName; })) === null || _a === void 0 ? void 0 : _a.columnName) === columnName;
2978
- }) || {};
2979
- var attributeName = Object.keys(field).find(function (fieldOptionFromList) { return AttributeOptionHelper.CheckIsColumnOption(field[fieldOptionFromList]) ||
2980
- Array.isArray(field[fieldOptionFromList]); });
2981
- var fieldOption = field === null || field === void 0 ? void 0 : field[attributeName];
2982
- if (Array.isArray(fieldOption))
2983
- return { attributeName: attributeName, fields: fieldOption };
2984
- return Object.assign({ attributeName: attributeName || columnName, columnName: columnName }, fieldOption);
2985
- };
2986
-
2987
- var GraphQLFieldHelper = /** @class */ (function () {
2988
- function GraphQLFieldHelper() {
2989
- }
2990
- return GraphQLFieldHelper;
2991
- }());
2992
- GraphQLFieldHelper.CheckIsGraphQLParams = function (params) { return !lodash.isString(params) && Array.isArray(params) && params.length >= 0 && !!params[0].operation; };
2993
- GraphQLFieldHelper.ConvertModelFieldsToGraphQLFields = function (fields) {
2994
- return fields === null || fields === void 0 ? void 0 : fields.map(function (field) {
2995
- var _b, _c;
2996
- if (lodash.isString(field))
2997
- return field.toString();
2998
- var fieldName = Object.keys(field).shift();
2999
- var fieldValue = field[fieldName];
3000
- if (Array.isArray(fieldValue))
3001
- return _b = {}, _b[fieldName] = GraphQLFieldHelper.ConvertModelFieldsToGraphQLFields(fieldValue), _b;
3002
- if (!AttributeOptionHelper.CheckIsColumnOption(fieldValue))
3003
- return;
3004
- if (fieldValue.fields)
3005
- return _c = {},
3006
- _c[fieldValue.columnName || fieldName] = GraphQLFieldHelper.ConvertModelFieldsToGraphQLFields(fieldValue.fields),
3007
- _c;
3008
- return fieldValue.columnName;
3009
- }).filter(function (field) { return !!field; });
3010
- };
3011
- GraphQLFieldHelper.ConvertFieldValueFrom = function (data, fields) { return Object.keys(data).reduce(function (result, columnName) {
3012
- var _b, _c, _d, _e;
3013
- var _f = AttributeOptionHelper.FindColumnOptionFromList(columnName, fields), attributeName = _f.attributeName, attributeFields = _f.fields, from = _f.from;
3014
- if (!!attributeFields && Array.isArray(attributeFields)) {
3015
- if (Array.isArray(data[columnName]))
3016
- return Object.assign(Object.assign({}, result), (_b = {}, _b[attributeName] = from
3017
- ? from(data[columnName], data)
3018
- : data[columnName].map(function (value) { return GraphQLFieldHelper.ConvertFieldValueFrom(value, attributeFields); }), _b));
3019
- if (lodash.isObject(data[columnName]))
3020
- return Object.assign(Object.assign({}, result), (_c = {}, _c[attributeName] = !!from
3021
- ? from(data[columnName])
3022
- : GraphQLFieldHelper.ConvertFieldValueFrom(data[columnName], attributeFields), _c));
3023
- }
3024
- if (!!from)
3025
- return Object.assign(Object.assign({}, result), (_d = {}, _d[attributeName] = from(data[columnName], data), _d));
3026
- return Object.assign(Object.assign({}, result), (_e = {}, _e[attributeName] = parseDateTime(data[columnName]), _e));
3027
- }, {}); };
3028
- GraphQLFieldHelper.ConvertFieldValueTo = function (instance, fields, update) {
3029
- if (update === void 0) { update = false; }
3030
- var _a;
3031
- var data = ((_a = instance.toPlain) === null || _a === void 0 ? void 0 : _a.call(instance)) || instance;
3032
- return Object.keys(data).reduce(function (result, attributeName) {
3033
- var _b, _c, _d;
3034
- var _e = AttributeOptionHelper.FindByAttribute(attributeName, fields), columnName = _e.columnName, attributeFields = _e.fields, foreignKeyColumn = _e.foreignKeyColumn, to = _e.to, bindPersistData = _e.bindPersistData;
3035
- if (bindPersistData)
3036
- return Object.assign(Object.assign({}, result), bindPersistData(data[attributeName], instance));
3037
- if (lodash.isNil(columnName))
3038
- return result;
3039
- if (!!foreignKeyColumn &&
3040
- !lodash.isEmpty(foreignKeyColumn) &&
3041
- !Object.keys(foreignKeyColumn).filter(function (key) { var _a; return !((_a = data[attributeName]) === null || _a === void 0 ? void 0 : _a[key]); }).length)
3042
- return Object.keys(foreignKeyColumn).reduce(function (object, current) {
3043
- var _b;
3044
- var _a;
3045
- return (Object.assign(Object.assign({}, object), (_b = {}, _b[foreignKeyColumn[current]] = (_a = data[attributeName]) === null || _a === void 0 ? void 0 : _a[current], _b)));
3046
- }, Object.assign({}, result));
3047
- if (update && lodash.isObject(data[attributeName]) && !lodash.isNil(attributeFields) && !lodash.isDate(data[attributeName]))
3048
- return result;
3049
- if (!!columnName && Array.isArray(attributeFields) && lodash.isObject(data[attributeName])) {
3050
- var converted = !lodash.isNil(columnName) && to ? to(instance[attributeName], instance) : data[attributeName];
3051
- return Object.assign(Object.assign({}, result), (converted !== undefined
3052
- ? (_b = {},
3053
- _b[columnName] = {
3054
- data: instance[attributeName] instanceof BaseModel
3055
- ? GraphQLFieldHelper.ConvertFieldValueTo(data[attributeName], attributeFields)
3056
- : converted,
3057
- },
3058
- _b) : {}));
3059
- }
3060
- if (!!to)
3061
- return Object.assign(Object.assign({}, result), (_c = {}, _c[columnName] = to(instance[attributeName], instance), _c));
3062
- return Object.assign(Object.assign({}, result), (_d = {}, _d[columnName] = data[attributeName], _d));
3063
- }, {});
3064
- };
3065
-
3066
- var FilterOptionHelper = /** @class */ (function () {
3067
- function FilterOptionHelper() {
3068
- }
3069
- return FilterOptionHelper;
3070
- }());
3071
- FilterOptionHelper.CheckIfIsFilterOption = function (filter) { return !lodash.isNil(filter === null || filter === void 0 ? void 0 : filter.operator); };
3072
- FilterOptionHelper.GetValueFromFilter = function (filter, fieldOption) {
3073
- if (!FilterOptionHelper.CheckIfIsFilterOption(filter))
3074
- return filter;
3075
- if (filter.operator === exports.Where.ISNULL)
3076
- return true;
3077
- if (filter.operator === exports.Where.ISNOTNULL)
3078
- return false;
3079
- var converter = fieldOption.to ? fieldOption.to : function (value) { return value; };
3080
- return Array.isArray(filter.value) && !fieldOption.fields && [exports.Where.IN, exports.Where.NOTIN].includes(filter.operator)
3081
- ? filter.value.map(function (fieldValue) { return converter(fieldValue); })
3082
- : converter(filter.value);
3083
- };
3084
-
3085
- var withCreateHasuraGraphQL = function (MixinBase) {
3086
- return /** @class */ (function (_super) {
3087
- __extends(CreateHasuraGraphQLMixin, _super);
3088
- function CreateHasuraGraphQLMixin() {
3089
- var params = [];
3090
- for (var _i = 0; _i < arguments.length; _i++) {
3091
- params[_i] = arguments[_i];
3092
- }
3093
- var _this = this;
3094
- var options = params === null || params === void 0 ? void 0 : params[0];
3095
- _this = _super.apply(this, __spreadArray([], __read(params))) || this;
3096
- _this.insertGraphQLOperation = (options === null || options === void 0 ? void 0 : options.insertGraphQLOperation) || "insert_" + _this.tableName + "_one";
3097
- _this.insertGraphQLObjectType = (options === null || options === void 0 ? void 0 : options.insertGraphQLObjectType) || _this.tableName + "_insert_input";
3098
- return _this;
3099
- }
3100
- CreateHasuraGraphQLMixin.prototype.create = function (data) {
3101
- return __awaiter(this, void 0, void 0, function () {
3102
- var newData;
3103
- return __generator(this, function (_b) {
3104
- switch (_b.label) {
3105
- case 0: return [4 /*yield*/, this.save(this.model.toInstance(data))];
3106
- case 1:
3107
- newData = _b.sent();
3108
- return [2 /*return*/, this.model.toInstance(newData)];
3109
- }
3110
- });
3111
- });
3112
- };
3113
- CreateHasuraGraphQLMixin.prototype.save = function (data) {
3114
- return __awaiter(this, void 0, void 0, function () {
3115
- var primaryKeyColumns, foreignKeyColumns, result;
3116
- var _this = this;
3117
- return __generator(this, function (_b) {
3118
- switch (_b.label) {
3119
- case 0:
3120
- primaryKeyColumns = this.model.identifiersFields.map(function (field) { return AttributeOptionHelper.FindByAttribute(field, _this.fields).columnName; });
3121
- foreignKeyColumns = this.fields
3122
- .map(function (field) {
3123
- var _b;
3124
- var columnOptions = Object.values(field).shift();
3125
- return (AttributeOptionHelper.CheckIsColumnOption(columnOptions) &&
3126
- columnOptions.foreignKeyColumn && __spreadArray(__spreadArray([], __read(Object.values(columnOptions.foreignKeyColumn))), [
3127
- (_b = {},
3128
- _b[columnOptions.columnName] = Object.keys(columnOptions.foreignKeyColumn).map(function (foreignKeyField) {
3129
- var _a;
3130
- return ((_a = AttributeOptionHelper.FindByAttribute(foreignKeyField, columnOptions === null || columnOptions === void 0 ? void 0 : columnOptions.fields)) === null || _a === void 0 ? void 0 : _a.columnName) ||
3131
- foreignKeyField;
3132
- }),
3133
- _b),
3134
- ]));
3135
- })
3136
- .filter(Boolean)
3137
- .reduce(function (keys, current) { return __spreadArray(__spreadArray([], __read(keys)), __read(current)); }, []);
3138
- return [4 /*yield*/, this.mutation(this.insertGraphQLOperation, __spreadArray(__spreadArray([], __read(primaryKeyColumns)), __read(foreignKeyColumns)), {
3139
- object: { type: this.insertGraphQLObjectType, required: true, value: this.convertDataToHasura(data) },
3140
- })];
3141
- case 1:
3142
- result = _b.sent();
3143
- return [2 /*return*/, Object.assign(Object.assign({}, data.toPlain()), this.convertDataFromHasura(result[this.insertGraphQLOperation]).toPlain())];
3144
- }
3145
- });
3146
- });
3147
- };
3148
- return CreateHasuraGraphQLMixin;
3149
- }(MixinBase));
3150
- };
3151
-
3152
- var withDeleteHasuraGraphQL = function (MixinBase) {
3153
- return /** @class */ (function (_super) {
3154
- __extends(DeleteHasuraGraphQLMixin, _super);
3155
- function DeleteHasuraGraphQLMixin() {
3156
- var params = [];
3157
- for (var _i = 0; _i < arguments.length; _i++) {
3158
- params[_i] = arguments[_i];
3159
- }
3160
- var _this = this;
3161
- var options = params === null || params === void 0 ? void 0 : params[0];
3162
- _this = _super.apply(this, __spreadArray([], __read(params))) || this;
3163
- _this.deleteGraphQLOperation = (options === null || options === void 0 ? void 0 : options.deleteGraphQLOperation) || "delete_" + _this.tableName + "_by_pk";
3164
- return _this;
3165
- }
3166
- DeleteHasuraGraphQLMixin.prototype.delete = function (identifiers) {
3167
- return __awaiter(this, void 0, void 0, function () {
3168
- var instance;
3169
- var _this = this;
3170
- return __generator(this, function (_a) {
3171
- switch (_a.label) {
3172
- case 0:
3173
- instance = this.model.toInstance(identifiers);
3174
- return [4 /*yield*/, this.mutation(this.deleteGraphQLOperation, this.model.identifiersFields.map(function (field) { return AttributeOptionHelper.FindByAttribute(field, _this.fields).columnName; }), this.model.identifiersFields.reduce(function (ids, identifier) {
3175
- var _a;
3176
- if (lodash.isNil(instance[identifier]))
3177
- return ids;
3178
- var columnOption = AttributeOptionHelper.FindByAttribute(identifier, _this.fields);
3179
- var value = columnOption.to(identifiers[identifier.toString()], instance);
3180
- return Object.assign(Object.assign({}, ids), (_a = {}, _a[columnOption.columnName] = {
3181
- type: _this.getAttributeGraphQLTypeOf(columnOption.type || value),
3182
- value: value,
3183
- required: true,
3184
- }, _a));
3185
- }, {}))];
3186
- case 1:
3187
- _a.sent();
3188
- return [2 /*return*/];
3189
- }
3190
- });
3191
- });
3192
- };
3193
- return DeleteHasuraGraphQLMixin;
3194
- }(MixinBase));
3195
- };
3196
-
3197
- var withHasuraGraphQL = function (MixinBase) {
3198
- return /** @class */ (function (_super) {
3199
- __extends(HasuraGraphQLMixin, _super);
3200
- function HasuraGraphQLMixin() {
3201
- var params = [];
3202
- for (var _i = 0; _i < arguments.length; _i++) {
3203
- params[_i] = arguments[_i];
3204
- }
3205
- var _this = this;
3206
- var options = params[0];
3207
- _this = _super.apply(this, __spreadArray([], __read(params))) || this;
3208
- _this.tableName = options.tableName;
3209
- _this.endpoint = options.endpoint;
3210
- _this.authOptions = options.authOptions;
3211
- _this.model = options.model;
3212
- _this.fields = options.fields || _this.model.identifiersFields;
3213
- return _this;
3214
- }
3215
- Object.defineProperty(HasuraGraphQLMixin.prototype, "headers", {
3216
- get: function () {
3217
- return Object.assign(Object.assign(Object.assign({ 'Content-Type': 'application/json' }, (lodash.isNil(this.authOptions.authToken) ? {} : { Authorization: this.authOptions.authToken })), (lodash.isNil(this.authOptions.adminSecret) ? {} : { 'X-Hasura-Admin-Secret': this.authOptions.adminSecret })), (lodash.isNil(this.authOptions.authRole)
3218
- ? {}
3219
- : { 'X-Hasura-Role': this.authOptions.authRole.role, 'X-Hasura-User-Id': this.authOptions.authRole.userId }));
3220
- },
3221
- enumerable: false,
3222
- configurable: true
3223
- });
3224
- HasuraGraphQLMixin.prototype.mutation = function (operation, fields, variables) {
3225
- return __awaiter(this, void 0, void 0, function () {
3226
- var resultQuery;
3227
- return __generator(this, function (_a) {
3228
- resultQuery = gqlQueryBuilder.mutation({
3229
- operation: operation,
3230
- variables: variables,
3231
- fields: GraphQLFieldHelper.ConvertModelFieldsToGraphQLFields(fields),
3232
- });
3233
- return [2 /*return*/, this.fetch(resultQuery)];
3234
- });
3235
- });
3236
- };
3237
- HasuraGraphQLMixin.prototype.query = function (operation, fields, variables) {
3238
- return __awaiter(this, void 0, void 0, function () {
3239
- var resultQuery;
3240
- return __generator(this, function (_a) {
3241
- resultQuery = GraphQLFieldHelper.CheckIsGraphQLParams(operation)
3242
- ? gqlQueryBuilder.query(operation.map(function (option) { return ({
3243
- operation: option.operation,
3244
- variables: option.variables,
3245
- fields: GraphQLFieldHelper.ConvertModelFieldsToGraphQLFields(option.fields),
3246
- }); }))
3247
- : gqlQueryBuilder.query({
3248
- operation: operation,
3249
- variables: variables,
3250
- fields: GraphQLFieldHelper.ConvertModelFieldsToGraphQLFields(fields),
3251
- });
3252
- return [2 /*return*/, this.fetch(resultQuery)];
3253
- });
3254
- });
3255
- };
3256
- HasuraGraphQLMixin.prototype.fetch = function (params) {
3257
- return __awaiter(this, void 0, void 0, function () {
3258
- var headers, response, result;
3259
- return __generator(this, function (_a) {
3260
- switch (_a.label) {
3261
- case 0:
3262
- headers = this.headers;
3263
- return [4 /*yield*/, fetch__default["default"]("" + this.endpoint, {
3264
- method: 'POST',
3265
- body: JSON.stringify(params),
3266
- headers: headers,
3267
- })];
3268
- case 1:
3269
- response = _a.sent();
3270
- return [4 /*yield*/, response.json()];
3271
- case 2:
3272
- result = _a.sent();
3273
- if (!lodash.isNil(result.errors))
3274
- throw new Error(JSON.stringify(result.errors));
3275
- return [2 /*return*/, result.data];
3276
- }
3277
- });
3278
- });
3279
- };
3280
- HasuraGraphQLMixin.prototype.getAttributeGraphQLTypeOf = function (value) {
3281
- if (isUUID(value))
3282
- return 'uuid';
3283
- if (lodash.isString(value))
3284
- return 'String';
3285
- if (lodash.isBoolean(value))
3286
- return 'Boolean';
3287
- if (value instanceof Date)
3288
- return 'timestamptz';
3289
- if (lodash.isInteger(value))
3290
- return 'Int';
3291
- if (lodash.isNumber(value))
3292
- return 'numeric';
3293
- throw new Error('Type not implemented yet');
3294
- };
3295
- HasuraGraphQLMixin.prototype.checkIfIsDateTimeAndParse = function (value) {
3296
- if (!/^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.test(value))
3297
- return value;
3298
- var date = dateFns.parseISO(value);
3299
- if (lodash.isNaN(date.getTime()))
3300
- return value;
3301
- return date;
3302
- };
3303
- HasuraGraphQLMixin.prototype.convertDataFromHasura = function (data) {
3304
- var plain = GraphQLFieldHelper.ConvertFieldValueFrom(data, this.fields);
3305
- return this.model.toInstance(plain);
3306
- };
3307
- HasuraGraphQLMixin.prototype.convertDataToHasura = function (instance, update) {
3308
- if (update === void 0) { update = false; }
3309
- return GraphQLFieldHelper.ConvertFieldValueTo(instance, this.fields, update);
3310
- };
3311
- return HasuraGraphQLMixin;
3312
- }(MixinBase));
3313
- };
3314
-
3315
- var withUpdateHasuraGraphQL = function (MixinBase) {
3316
- var getValueByAction = function (options) {
3317
- if (options instanceof BaseModel)
3318
- return options.toPlain();
3319
- if (lodash.isNil(options === null || options === void 0 ? void 0 : options.action))
3320
- return options;
3321
- if ([exports.UpdateOptionActions.REMOVE_FIELD.toString(), exports.UpdateOptionActions.NULL.toString()].includes(options.action))
3322
- return null;
3323
- return options.value;
3324
- };
3325
- return /** @class */ (function (_super) {
3326
- __extends(UpdateHasuraGraphQLMixin, _super);
3327
- function UpdateHasuraGraphQLMixin() {
3328
- var params = [];
3329
- for (var _i = 0; _i < arguments.length; _i++) {
3330
- params[_i] = arguments[_i];
3331
- }
3332
- var _this = this;
3333
- var options = params === null || params === void 0 ? void 0 : params[0];
3334
- _this = _super.apply(this, __spreadArray([], __read(params))) || this;
3335
- _this.updateGraphQLOperation = (options === null || options === void 0 ? void 0 : options.updateGraphQLOperation) || "update_" + _this.tableName + "_by_pk";
3336
- _this.updateGraphQLObjectType = (options === null || options === void 0 ? void 0 : options.updateGraphQLObjectType) || _this.tableName + "_set_input";
3337
- _this.updateGraphQLPKType = (options === null || options === void 0 ? void 0 : options.updateGraphQLPKType) || _this.tableName + "_pk_columns_input";
3338
- return _this;
3339
- }
3340
- UpdateHasuraGraphQLMixin.prototype.update = function (data) {
3341
- return __awaiter(this, void 0, void 0, function () {
3342
- var plainData;
3343
- var _this = this;
3344
- return __generator(this, function (_b) {
3345
- switch (_b.label) {
3346
- case 0:
3347
- plainData = this.paramsToPlain(data);
3348
- return [4 /*yield*/, this.mutation(this.updateGraphQLOperation, this.model.identifiersFields.map(function (field) { return AttributeOptionHelper.FindByAttribute(field, _this.fields).columnName; }), {
3349
- _set: {
3350
- type: this.updateGraphQLObjectType,
3351
- value: this.convertDataToHasura(this.model.toInstance(plainData), true),
3352
- required: true,
3353
- },
3354
- pk_columns: { type: this.updateGraphQLPKType, value: this.getUpdateModelKeys(plainData), required: true },
3355
- })];
3356
- case 1:
3357
- _b.sent();
3358
- return [2 /*return*/, this.model.toInstance(plainData)];
3359
- }
3360
- });
3361
- });
3362
- };
3363
- UpdateHasuraGraphQLMixin.prototype.paramsToPlain = function (params) {
3364
- var model = this.model;
3365
- if (model.isModel(params))
3366
- return params.toPlain();
3367
- return Object.keys(params).reduce(function (data, currentKey) {
3368
- var _b;
3369
- return (Object.assign(Object.assign({}, data), (params[currentKey] !== undefined && (_b = {}, _b[currentKey] = getValueByAction(params[currentKey]), _b))));
3370
- }, {});
3371
- };
3372
- UpdateHasuraGraphQLMixin.prototype.getUpdateModelKeys = function (data) {
3373
- var _this = this;
3374
- var instance = this.model.toInstance(data);
3375
- return this.model.identifiersFields.reduce(function (ids, identifier) {
3376
- var _b;
3377
- var _a;
3378
- if (lodash.isNil(instance[identifier]))
3379
- return ids;
3380
- var columnOption = AttributeOptionHelper.FindByAttribute(identifier, _this.fields);
3381
- var value = ((_a = columnOption === null || columnOption === void 0 ? void 0 : columnOption.to) === null || _a === void 0 ? void 0 : _a.call(columnOption, data[identifier.toString()], instance)) || data[columnOption.attributeName];
3382
- return Object.assign(Object.assign({}, ids), (_b = {}, _b[columnOption.columnName] = value, _b));
3383
- }, {});
3384
- };
3385
- return UpdateHasuraGraphQLMixin;
3386
- }(MixinBase));
3387
- };
3388
-
3389
- var withGetHasuraGraphQL = function (MixinBase) {
3390
- return /** @class */ (function (_super) {
3391
- __extends(GetHasuraGraphQLMixin, _super);
3392
- function GetHasuraGraphQLMixin() {
3393
- var params = [];
3394
- for (var _i = 0; _i < arguments.length; _i++) {
3395
- params[_i] = arguments[_i];
3396
- }
3397
- var _this = this;
3398
- var options = params === null || params === void 0 ? void 0 : params[0];
3399
- _this = _super.apply(this, __spreadArray([], __read(params))) || this;
3400
- _this.getGraphQLOperation = (options === null || options === void 0 ? void 0 : options.getGraphQLOperation) || _this.tableName + "_by_pk";
3401
- return _this;
3402
- }
3403
- GetHasuraGraphQLMixin.prototype.get = function (identifiers) {
3404
- return __awaiter(this, void 0, void 0, function () {
3405
- var instance, result, data;
3406
- var _this = this;
3407
- return __generator(this, function (_b) {
3408
- switch (_b.label) {
3409
- case 0:
3410
- instance = this.model.toInstance(identifiers);
3411
- return [4 /*yield*/, this.query(this.getGraphQLOperation, this.fields, this.model.identifiersFields.reduce(function (ids, identifier) {
3412
- var _b;
3413
- var _a;
3414
- if (lodash.isNil(instance[identifier]))
3415
- return ids;
3416
- var columnOption = AttributeOptionHelper.FindByAttribute(identifier, _this.fields);
3417
- var value = ((_a = columnOption === null || columnOption === void 0 ? void 0 : columnOption.to) === null || _a === void 0 ? void 0 : _a.call(columnOption, identifiers[identifier.toString()], instance)) || identifiers[identifier.toString()];
3418
- return Object.assign(Object.assign({}, ids), (_b = {}, _b[columnOption.columnName] = {
3419
- type: _this.getAttributeGraphQLTypeOf(columnOption.type || value),
3420
- value: value,
3421
- required: true,
3422
- }, _b));
3423
- }, {}))];
3424
- case 1:
3425
- result = _b.sent();
3426
- data = result[this.getGraphQLOperation];
3427
- if (lodash.isNil(data))
3428
- throw new NotFoundError(instance.constructor.name + " not found");
3429
- return [2 /*return*/, this.convertDataFromHasura(result[this.getGraphQLOperation])];
3430
- }
3431
- });
3432
- });
3433
- };
3434
- return GetHasuraGraphQLMixin;
3435
- }(MixinBase));
3436
- };
3437
-
3438
- var HasuraGraphQLWhere;
3439
- (function (HasuraGraphQLWhere) {
3440
- HasuraGraphQLWhere["EQUALS"] = "_eq";
3441
- HasuraGraphQLWhere["GT"] = "_gt";
3442
- HasuraGraphQLWhere["GTE"] = "_gte";
3443
- HasuraGraphQLWhere["IN"] = "_in";
3444
- HasuraGraphQLWhere["NOTIN"] = "_nin";
3445
- HasuraGraphQLWhere["LT"] = "_lt";
3446
- HasuraGraphQLWhere["LTE"] = "_lte";
3447
- HasuraGraphQLWhere["LIKE"] = "_like";
3448
- HasuraGraphQLWhere["NOTLIKE"] = "_nlike";
3449
- HasuraGraphQLWhere["ISNULL"] = "_is_null";
3450
- HasuraGraphQLWhere["ISNOTNULL"] = "_is_null";
3451
- })(HasuraGraphQLWhere || (HasuraGraphQLWhere = {}));
3452
-
3453
- var HasuraGraphQLColumnType;
3454
- (function (HasuraGraphQLColumnType) {
3455
- HasuraGraphQLColumnType["Int"] = "Int";
3456
- HasuraGraphQLColumnType["Float"] = "Float";
3457
- HasuraGraphQLColumnType["Boolean"] = "Boolean";
3458
- HasuraGraphQLColumnType["String"] = "String";
3459
- HasuraGraphQLColumnType["DateTime"] = "timestampz";
3460
- HasuraGraphQLColumnType["Json"] = "json";
3461
- HasuraGraphQLColumnType["Jsonb"] = "jsonb";
3462
- HasuraGraphQLColumnType["Enum"] = "enum";
3463
- HasuraGraphQLColumnType["Uuid"] = "uuid";
3464
- })(HasuraGraphQLColumnType || (HasuraGraphQLColumnType = {}));
3465
-
3466
- var withFindHasuraGraphQL = function (MixinBase) {
3467
- return /** @class */ (function (_super) {
3468
- __extends(FindHasuraGraphQLMixin, _super);
3469
- function FindHasuraGraphQLMixin() {
3470
- var _this = _super.apply(this, __spreadArray([], __read(arguments))) || this;
3471
- _this.makeGraphQLWhere = function (filter, fields) { return Object.keys(filter).reduce(function (variables, fieldName) {
3472
- var _b;
3473
- var columnOption = AttributeOptionHelper.FindByAttribute(fieldName, fields);
3474
- if (!columnOption.bindFindFilter)
3475
- return Object.assign(Object.assign({}, variables), (_b = {}, _b[columnOption.columnName] = _this.buildWhereSentence(fieldName, filter[fieldName], fields), _b));
3476
- var builtFilter = columnOption.bindFindFilter(filter[fieldName]);
3477
- return Object.assign(Object.assign({}, variables), Object.keys(builtFilter).reduce(function (variablesList, columnName) {
3478
- var _b;
3479
- return (Object.assign(Object.assign({}, variablesList), (_b = {}, _b[columnName] = _this.buildWhereSentence(fieldName, builtFilter[columnName], fields), _b)));
3480
- }, {}));
3481
- }, {}); };
3482
- _this.buildWhereSentence = function (field, options, fields) {
3483
- var _b;
3484
- var fieldSentenceOptions = AttributeOptionHelper.FindByAttribute(field, fields);
3485
- if (!Array.isArray(options) &&
3486
- lodash.isObject(options) &&
3487
- lodash.isNil(options === null || options === void 0 ? void 0 : options.operator) &&
3488
- lodash.isNil(options === null || options === void 0 ? void 0 : options.value) &&
3489
- lodash.isNil(fieldSentenceOptions === null || fieldSentenceOptions === void 0 ? void 0 : fieldSentenceOptions.to))
3490
- return Object.keys(options).reduce(function (variables, key) {
3491
- var _b;
3492
- var fieldOptions = AttributeOptionHelper.FindByAttribute(key, (fieldSentenceOptions === null || fieldSentenceOptions === void 0 ? void 0 : fieldSentenceOptions.fields) || fields);
3493
- var columnName = fieldOptions.columnName;
3494
- var columnFields = fieldOptions.fields;
3495
- return Object.assign(Object.assign({}, variables), (_b = {}, _b[columnName] = _this.buildWhereSentence(key, options[key], columnFields || []), _b));
3496
- }, {});
3497
- if (!Array.isArray(options) && !lodash.isNil(fieldSentenceOptions.fields))
3498
- return _b = {},
3499
- _b[fieldSentenceOptions.fields[0]] = _this.buildOperatorSentence(options, fieldSentenceOptions),
3500
- _b;
3501
- if (lodash.isObject(options) && !FilterOptionHelper.CheckIfIsFilterOption(options))
3502
- options = Object.values(options)[0];
3503
- return Array.isArray(options)
3504
- ? options.reduce(function (whereSentence, option) { return (Object.assign(Object.assign({}, whereSentence), _this.buildOperatorSentence(option, fieldSentenceOptions))); }, {})
3505
- : _this.buildOperatorSentence(options, fieldSentenceOptions);
3506
- };
3507
- _this.buildOperatorSentence = function (options, fieldOption) {
3508
- var _b;
3509
- return (_b = {},
3510
- _b[_this.getHasuraOperator(options, fieldOption)] = FilterOptionHelper.GetValueFromFilter(options, fieldOption),
3511
- _b);
3512
- };
3513
- _this.getHasuraOperator = function (options, fieldOption) { return FilterOptionHelper.CheckIfIsFilterOption(options)
3514
- ? fieldOption.type === HasuraGraphQLColumnType.Jsonb
3515
- ? _this.getHasuraJsonbOperator(options)
3516
- : HasuraGraphQLWhere[Object.keys(HasuraGraphQLWhere).find(function (graphQLOperator) { return graphQLOperator === Object.keys(exports.Where).find(function (operator) { return exports.Where[operator] === (options === null || options === void 0 ? void 0 : options.operator); }); })]
3517
- : HasuraGraphQLWhere.EQUALS; };
3518
- _this.getHasuraJsonbOperator = function (options) { return options.operator === exports.Where.IN
3519
- ? '_contains'
3520
- : options.operator === exports.Where.LIKE
3521
- ? '_has_keys_any'
3522
- : HasuraGraphQLWhere[Object.keys(HasuraGraphQLWhere).find(function (graphQLOperator) { return graphQLOperator === Object.keys(exports.Where).find(function (operator) { return exports.Where[operator] === (options === null || options === void 0 ? void 0 : options.operator); }); })]; };
3523
- return _this;
3524
- }
3525
- FindHasuraGraphQLMixin.prototype.find = function (options) {
3526
- return __awaiter(this, void 0, void 0, function () {
3527
- var _b, filters, limits, orderBy, variablesCount, variables, result, data, count;
3528
- var _this = this;
3529
- return __generator(this, function (_c) {
3530
- switch (_c.label) {
3531
- case 0:
3532
- _b = options || {}, filters = _b.filters, limits = _b.limits, orderBy = _b.orderBy;
3533
- variablesCount = Object.assign(Object.assign({}, (lodash.isNil(orderBy) ? {} : { order_by: { type: this.tableName + "_order_by!", list: true, value: orderBy } })), (lodash.isNil(filters)
3534
- ? {}
3535
- : {
3536
- where: {
3537
- value: this.makeGraphQLWhere(filters, this.fields),
3538
- type: this.tableName + "_bool_exp",
3539
- required: true,
3540
- },
3541
- }));
3542
- variables = Object.assign(Object.assign({}, (lodash.isNil(limits) ? {} : limits)), variablesCount);
3543
- return [4 /*yield*/, this.query([
3544
- {
3545
- operation: this.tableName,
3546
- fields: options.fields
3547
- ? options.fields
3548
- .map(function (fieldName) {
3549
- var _a;
3550
- return (_a = _this.fields.find(function (fieldOption) { return fieldOption === fieldName; })) !== null && _a !== void 0 ? _a : _this.fields.find(function (fieldOption) { return Object.keys(fieldOption).shift() === fieldName; });
3551
- })
3552
- .filter(Boolean)
3553
- : this.fields,
3554
- variables: variables,
3555
- },
3556
- {
3557
- operation: this.tableName + "_aggregate",
3558
- fields: [{ aggregate: ['count'] }],
3559
- variables: variablesCount,
3560
- },
3561
- ])];
3562
- case 1:
3563
- result = _c.sent();
3564
- data = result[this.tableName].map(function (row) { return _this.convertDataFromHasura(row); });
3565
- count = result[this.tableName + "_aggregate"].aggregate.count;
3566
- return [2 /*return*/, { count: count, data: data }];
3567
- }
3568
- });
3569
- });
3570
- };
3571
- return FindHasuraGraphQLMixin;
3572
- }(MixinBase));
3573
- };
3574
-
3575
- var withCrudHasuraGraphQL = function (MixinBase) {
3576
- return /** @class */ (function (_super) {
3577
- __extends(CrudHasuraGraphQLMixin, _super);
3578
- function CrudHasuraGraphQLMixin() {
3579
- return _super !== null && _super.apply(this, arguments) || this;
3580
- }
3581
- return CrudHasuraGraphQLMixin;
3582
- }(withUpdateHasuraGraphQL(withGetHasuraGraphQL(withFindHasuraGraphQL(withDeleteHasuraGraphQL(withCreateHasuraGraphQL(MixinBase)))))));
3583
- };
3584
-
3585
- var CategoryHasuraGraphQL = /** @class */ (function (_super) {
3586
- __extends(CategoryHasuraGraphQL, _super);
3587
- function CategoryHasuraGraphQL() {
3588
- return _super !== null && _super.apply(this, arguments) || this;
3589
- }
3590
- return CategoryHasuraGraphQL;
3591
- }(Category));
3592
-
3593
- var ProductHasuraGraphQL = /** @class */ (function (_super) {
3594
- __extends(ProductHasuraGraphQL, _super);
3595
- function ProductHasuraGraphQL() {
3596
- return _super !== null && _super.apply(this, arguments) || this;
3597
- }
3598
- return ProductHasuraGraphQL;
3599
- }(Product));
3600
- __decorate([
3601
- classTransformer.Type(function () { return KitProductHasuraGraphQL; }),
3602
- __metadata("design:type", Array)
3603
- ], ProductHasuraGraphQL.prototype, "kitProducts", void 0);
3604
-
3605
- var KitProductHasuraGraphQL = /** @class */ (function (_super) {
3606
- __extends(KitProductHasuraGraphQL, _super);
3607
- function KitProductHasuraGraphQL() {
3608
- return _super !== null && _super.apply(this, arguments) || this;
3609
- }
3610
- return KitProductHasuraGraphQL;
3611
- }(KitProduct));
3612
- __decorate([
3613
- classTransformer.Type(function () { return ProductHasuraGraphQL; }),
3614
- __metadata("design:type", ProductHasuraGraphQL)
3615
- ], KitProductHasuraGraphQL.prototype, "kit", void 0);
3616
- __decorate([
3617
- classTransformer.Type(function () { return ProductHasuraGraphQL; }),
3618
- __metadata("design:type", ProductHasuraGraphQL)
3619
- ], KitProductHasuraGraphQL.prototype, "product", void 0);
3620
-
3621
- var VariantHasuraGraphQL = /** @class */ (function (_super) {
3622
- __extends(VariantHasuraGraphQL, _super);
3623
- function VariantHasuraGraphQL() {
3624
- var _this = _super.apply(this, __spreadArray([], __read(arguments))) || this;
3625
- _this.name = '';
3626
- _this.hasVariants = false;
3627
- return _this;
3628
- }
3629
- return VariantHasuraGraphQL;
3630
- }(Variant));
3631
-
3632
- var CategoryHasuraGraphQLRepository = /** @class */ (function (_super_1) {
3633
- __extends(CategoryHasuraGraphQLRepository, _super_1);
3634
- function CategoryHasuraGraphQLRepository(endpoint, authOptions, productRepository) {
3635
- var _this = _super_1.call(this, {
3636
- tableName: 'category',
3637
- model: Category,
3638
- endpoint: endpoint,
3639
- authOptions: authOptions,
3640
- fields: [
3641
- { id: { columnName: 'id', to: function (value) { return +value; }, from: function (value) { return value.toString(); } } },
3642
- { firestoreId: { columnName: 'firestore_id' } },
3643
- 'name',
3644
- 'description',
3645
- 'image',
3646
- 'published',
3647
- 'shop',
3648
- 'slug',
3649
- { brandCategory: { columnName: 'brand_category' } },
3650
- { brandCategoryBanner: { columnName: 'brand_banner' } },
3651
- { brandCategoryBannerMobile: { columnName: 'brand_banner_mobile' } },
3652
- { brandLogo: { columnName: 'brand_logo' } },
3653
- { brandCondition: { columnName: 'brand_condition' } },
3654
- {
3655
- conditions: {
3656
- columnName: 'tag_condition',
3657
- type: HasuraGraphQLColumnType.Jsonb,
3658
- from: function (tags, row) { return ({ brand: row.brand_condition, tags: Array.isArray(tags) ? tags : [] }); },
3659
- bindPersistData: function (value) {
3660
- var _a, _b;
3661
- return {
3662
- brand_condition: value.brand,
3663
- tag_condition: "{\"" + (((_b = (_a = value === null || value === void 0 ? void 0 : value.tags) === null || _a === void 0 ? void 0 : _a.join) === null || _b === void 0 ? void 0 : _b.call(_a, '","')) || '') + "\"}",
3664
- };
3665
- },
3666
- bindFindFilter: function (sentence) {
3667
- return Object.assign(Object.assign({}, (sentence.brand ? { brand_condition: sentence.brand } : {})), (sentence.tags ? { tag_condition: sentence.tags } : {}));
3668
- },
3669
- },
3670
- },
3671
- 'filters',
3672
- { createdAt: { columnName: 'created_at' } },
3673
- { updatedAt: { columnName: 'updated_at' } },
3674
- {
3675
- products: {
3676
- columnName: 'products',
3677
- fields: ['product_id'],
3678
- from: function (value) { return value.map(function (product) { return product.product_id.toString(); }); },
3679
- to: function (productIds) { return productIds.map(function (productId) { return ({
3680
- product_id: +productId,
3681
- }); }); },
3682
- },
3683
- },
3684
- ],
3685
- }) || this;
3686
- _this.productRepository = productRepository;
3687
- return _this;
3688
- }
3689
- CategoryHasuraGraphQLRepository.prototype.get = function (identifiers) {
3690
- var _super = Object.create(null, {
3691
- get: { get: function () { return _super_1.prototype.get; } }
3692
- });
3693
- var _a;
3694
- return __awaiter(this, void 0, void 0, function () {
3695
- var _c;
3696
- return __generator(this, function (_d) {
3697
- switch (_d.label) {
3698
- case 0:
3699
- if (!Number.isNaN(+identifiers.id)) return [3 /*break*/, 2];
3700
- return [4 /*yield*/, this.find({ filters: { firestoreId: identifiers.id } })];
3701
- case 1:
3702
- _c = (_a = (_d.sent()).data) === null || _a === void 0 ? void 0 : _a[0];
3703
- return [3 /*break*/, 3];
3704
- case 2:
3705
- _c = _super.get.call(this, identifiers);
3706
- _d.label = 3;
3707
- case 3: return [2 /*return*/, _c];
3708
- }
3709
- });
3710
- });
3711
- };
3712
- CategoryHasuraGraphQLRepository.prototype.getCategoryBySlug = function (slug, shop) {
3713
- return __awaiter(this, void 0, void 0, function () {
3714
- var _c, data, count;
3715
- return __generator(this, function (_d) {
3716
- switch (_d.label) {
3717
- case 0:
3718
- if (!slug)
3719
- return [2 /*return*/];
3720
- return [4 /*yield*/, this.find({ filters: { slug: slug, shop: shop, published: true } })];
3721
- case 1:
3722
- _c = _d.sent(), data = _c.data, count = _c.count;
3723
- if (count > 1)
3724
- throw new DuplicatedResultsError('Query returned duplicated values');
3725
- if (!count)
3726
- throw new NotFoundError("Category with slug " + slug + " not found");
3727
- return [2 /*return*/, data.shift()];
3728
- }
3729
- });
3730
- });
3731
- };
3732
- CategoryHasuraGraphQLRepository.prototype.getCategoriesForHome = function (categoryIds, limit) {
3733
- if (limit === void 0) { limit = 4; }
3734
- return __awaiter(this, void 0, void 0, function () {
3735
- var _c, categories, count, homeSections;
3736
- var _this = this;
3737
- return __generator(this, function (_d) {
3738
- switch (_d.label) {
3739
- case 0: return [4 /*yield*/, this.find({
3740
- filters: { firestoreId: { operator: exports.Where.IN, value: categoryIds.filter(Boolean) }, published: true },
3741
- })];
3742
- case 1:
3743
- _c = _d.sent(), categories = _c.data, count = _c.count;
3744
- if (!count)
3745
- throw new NotFoundError('Categories not found');
3746
- return [4 /*yield*/, Promise.all(categories.map(function (category) { return __awaiter(_this, void 0, void 0, function () {
3747
- var _c;
3748
- return __generator(this, function (_d) {
3749
- switch (_d.label) {
3750
- case 0:
3751
- _c = {
3752
- category: category
3753
- };
3754
- return [4 /*yield*/, this.mountCategory(category, { limit: limit, hasStock: true })];
3755
- case 1: return [2 /*return*/, (_c.products = _d.sent(),
3756
- _c)];
3757
- }
3758
- });
3759
- }); }))];
3760
- case 2:
3761
- homeSections = _d.sent();
3762
- return [2 /*return*/, homeSections];
3763
- }
3764
- });
3765
- });
3766
- };
3767
- CategoryHasuraGraphQLRepository.prototype.mountCategory = function (category, options) {
3768
- return __awaiter(this, void 0, void 0, function () {
3769
- var products, publishedField, productsData;
3770
- var _c;
3771
- return __generator(this, function (_d) {
3772
- switch (_d.label) {
3773
- case 0:
3774
- if (!category.products)
3775
- throw new RequiredArgumentError(['Category products is empty']);
3776
- products = [];
3777
- publishedField = category.shop === exports.Shops.GLAMSHOP ? 'publishedGlam' : 'published';
3778
- return [4 /*yield*/, this.productRepository.find(Object.assign({ filters: Object.assign((_c = { id: { operator: exports.Where.IN, value: category.products } }, _c[publishedField] = true, _c), ((options === null || options === void 0 ? void 0 : options.hasStock) ? { stock: { quantity: { operator: exports.Where.GT, value: 0 } } } : {})), fields: [
3779
- 'id',
3780
- 'name',
3781
- 'slug',
3782
- 'images',
3783
- 'miniatures',
3784
- 'price',
3785
- 'fullPrice',
3786
- 'subscriberDiscountPercentage',
3787
- 'subscriberPrice',
3788
- 'stock',
3789
- 'published',
3790
- 'publishedGlam',
3791
- 'CEST',
3792
- 'EAN',
3793
- 'NCM',
3794
- 'brand',
3795
- 'costPrice',
3796
- 'hasVariants',
3797
- 'isKit',
3798
- 'shopAvailability',
3799
- 'sku',
3800
- 'rate',
3801
- ] }, ((options === null || options === void 0 ? void 0 : options.limit) ? { limits: { limit: options === null || options === void 0 ? void 0 : options.limit } } : {})))];
3802
- case 1:
3803
- productsData = (_d.sent()).data;
3804
- products.push.apply(products, __spreadArray([], __read(productsData)));
3805
- return [2 /*return*/, products];
3806
- }
3807
- });
3808
- });
3809
- };
3810
- return CategoryHasuraGraphQLRepository;
3811
- }(withCrudHasuraGraphQL(withHasuraGraphQL(Base))));
3812
-
3813
- var ProductHasuraGraphQLRepository = /** @class */ (function (_super_1) {
3814
- __extends(ProductHasuraGraphQLRepository, _super_1);
3815
- function ProductHasuraGraphQLRepository(endpoint, authOptions) {
3816
- var _this = _super_1.call(this, {
3817
- tableName: 'product',
3818
- model: ProductHasuraGraphQL,
3819
- endpoint: endpoint,
3820
- authOptions: authOptions,
3821
- fields: [],
3822
- }) || this;
3823
- _this.bindReviewToModel = function (plain) { return (Object.assign(Object.assign({}, lodash.omit(plain, ['product_id', 'created_at', 'updated_at', 'person_id', 'order_id'])), { createdAt: typeof plain.created_at === 'string' ? new Date(plain.created_at) : plain.created_at, updatedAt: typeof plain.updated_at === 'string' ? new Date(plain.updated_at) : plain.updated_at, personId: plain.person_id, orderId: plain.order_id })); };
3824
- _this.bindReviewToHasura = function (review) { return (Object.assign(Object.assign({}, lodash.omit(review, ['productId', 'createdAt', 'updatedAt', 'personId', 'orderId'])), { person_id: review.personId, order_id: review.orderId })); };
3825
- var commonFields = [
3826
- { id: { columnName: 'id', to: function (value) { return +value; }, from: function (value) { return value.toString(); } } },
3827
- { firestoreId: { columnName: 'firestore_id' } },
3828
- { CEST: { columnName: 'cest' } },
3829
- { EAN: { columnName: 'ean' } },
3830
- { NCM: { columnName: 'ncm' } },
3831
- 'brand',
3832
- { costPrice: { columnName: 'cost_price' } },
3833
- {
3834
- description: {
3835
- columnName: 'description',
3836
- from: function (description) { return Object.values(exports.Shops).reduce(function (shops, shop) {
3837
- var _c;
3838
- return (Object.assign(Object.assign({}, shops), (_c = {}, _c[shop] = { description: description }, _c)));
3839
- }, {}); },
3840
- to: function (value) { return Object.values(value).shift().description; },
3841
- },
3842
- },
3843
- { hasVariants: { columnName: 'has_variants' } },
3844
- { images: { columnName: 'images', to: function (value) { var _a; return "{\"" + (((_a = value === null || value === void 0 ? void 0 : value.join) === null || _a === void 0 ? void 0 : _a.call(value, "\",\"")) || '') + "\"}"; } } },
3845
- { miniatures: { columnName: 'miniatures', to: function (value) { var _a; return "{\"" + (((_a = value === null || value === void 0 ? void 0 : value.join) === null || _a === void 0 ? void 0 : _a.call(value, "\",\"")) || '') + "\"}"; } } },
3846
- 'name',
3847
- {
3848
- price: {
3849
- columnName: 'price',
3850
- from: function (price, data) { return Object.values(exports.Shops).reduce(function (prices, shop) {
3851
- var _c;
3852
- return (Object.assign(Object.assign({}, prices), (_c = {}, _c[shop] = {
3853
- price: price,
3854
- fullPrice: data.full_price,
3855
- subscriberDiscountPercentage: data.subscriber_discount_percentage,
3856
- subscriberPrice: data.subscriber_price,
3857
- }, _c)));
3858
- }, {}); },
3859
- bindFindFilter: function (sentence) {
3860
- var filters = Object.values(sentence).shift();
3861
- return Object.assign(Object.assign(Object.assign(Object.assign({}, (((filters === null || filters === void 0 ? void 0 : filters.price) || (filters === null || filters === void 0 ? void 0 : filters.price) === 0) && { price: filters.price })), ((filters.fullPrice || filters.fullPrice === 0) && { full_price: filters.fullPrice })), ((filters.subscriberDiscountPercentage || filters.subscriberDiscountPercentage === 0) && {
3862
- subscriber_discount_percentage: filters.subscriberDiscountPercentage,
3863
- })), ((filters.subscriberPrice || filters.subscriberPrice === 0) && {
3864
- subscriber_price: filters.subscriberPrice,
3865
- }));
3866
- },
3867
- bindPersistData: function (value) {
3868
- var priceData = Object.values(value).shift();
3869
- return Object.assign(Object.assign(Object.assign(Object.assign({}, ((priceData === null || priceData === void 0 ? void 0 : priceData.price) >= 0 && { price: priceData.price })), (priceData.fullPrice >= 0 && { full_price: priceData.fullPrice })), (priceData.subscriberDiscountPercentage >= 0 && {
3870
- subscriber_discount_percentage: priceData.subscriberDiscountPercentage,
3871
- })), (priceData.subscriberPrice >= 0 && { subscriber_price: priceData.subscriberPrice }));
3872
- },
3873
- },
3874
- },
3875
- { fullPrice: { columnName: 'full_price' } },
3876
- { subscriberDiscountPercentage: { columnName: 'subscriber_discount_percentage' } },
3877
- { subscriberPrice: { columnName: 'subscriber_price' } },
3878
- 'published',
3879
- { publishedGlam: { columnName: 'published_glam' } },
3880
- 'sku',
3881
- {
3882
- stock: {
3883
- columnName: 'stock',
3884
- from: function (quantity) { return ({ quantity: quantity }); },
3885
- to: function (value) { return (lodash.isNil(value === null || value === void 0 ? void 0 : value.quantity) ? value : value === null || value === void 0 ? void 0 : value.quantity); },
3886
- },
3887
- },
3888
- 'slug',
3889
- 'type',
3890
- 'video',
3891
- 'weight',
3892
- {
3893
- shopAvailability: {
3894
- columnName: 'shop_availabilities',
3895
- fields: ['shop'],
3896
- from: function (shop) { return (Array.isArray(shop) ? shop.map(function (row) { return row.shop; }) : []); },
3897
- bindPersistData: function (shops) { return ({ shop_availabilities: { data: shops.map(function (shop) { return ({ shop: shop }); }) } }); },
3898
- },
3899
- },
3900
- { tags: { columnName: 'tags', type: HasuraGraphQLColumnType.Jsonb } },
3901
- { isKit: { columnName: 'is_kit' } },
3902
- { createdAt: { columnName: 'created_at' } },
3903
- { updatedAt: { columnName: 'updated_at' } },
3904
- {
3905
- rate: {
3906
- columnName: 'reviews_aggregate',
3907
- fields: [{ aggregate: [{ avg: ['rate'] }] }],
3908
- from: function (value) { return value.aggregate.avg.rate; },
3909
- },
3910
- },
3911
- ];
3912
- _this.fields = __spreadArray(__spreadArray([], __read(commonFields)), [
3913
- {
3914
- categories: {
3915
- columnName: 'categories',
3916
- fields: ['category_id'],
3917
- bindPersistData: function (value) { return ({
3918
- categories: { data: value.map(function (category) { return ({ category_id: +category }); }) },
3919
- }); },
3920
- to: function (categories) { return categories.map(function (categoryId) { return +categoryId; }); },
3921
- from: function (categories) { return (categories === null || categories === void 0 ? void 0 : categories.map(function (category) { var _a; return (_a = category === null || category === void 0 ? void 0 : category.category_id) === null || _a === void 0 ? void 0 : _a.toString(); })) || []; },
3922
- },
3923
- },
3924
- {
3925
- kitProducts: {
3926
- columnName: 'kit_products',
3927
- foreignKeyColumn: { productId: 'id' },
3928
- fields: [
3929
- { productId: { columnName: 'product_id' } },
3930
- { kitProductId: { columnName: 'kit_product_id' } },
3931
- 'quantity',
3932
- { product: { columnName: 'product', foreignKeyColumn: { id: 'product_id' }, fields: commonFields } },
3933
- ],
3934
- },
3935
- },
3936
- ]);
3937
- return _this;
3938
- }
3939
- Object.defineProperty(ProductHasuraGraphQLRepository.prototype, "reviewsFields", {
3940
- get: function () {
3941
- return [
3942
- 'id',
3943
- 'shop',
3944
- 'rate',
3945
- 'author',
3946
- 'email',
3947
- 'location',
3948
- 'review',
3949
- 'status',
3950
- 'title',
3951
- 'person_id',
3952
- 'points',
3953
- 'order_id',
3954
- 'created_at',
3955
- 'updated_at',
3956
- ];
3957
- },
3958
- enumerable: false,
3959
- configurable: true
3960
- });
3961
- ProductHasuraGraphQLRepository.prototype.create = function (data) {
3962
- var _super = Object.create(null, {
3963
- create: { get: function () { return _super_1.prototype.create; } }
3964
- });
3965
- return __awaiter(this, void 0, void 0, function () {
3966
- var product, _c, error_1;
3967
- return __generator(this, function (_d) {
3968
- switch (_d.label) {
3969
- case 0: return [4 /*yield*/, _super.create.call(this, lodash.omit(data, ['reviews']))];
3970
- case 1:
3971
- product = _d.sent();
3972
- _d.label = 2;
3973
- case 2:
3974
- _d.trys.push([2, 4, , 6]);
3975
- _c = product;
3976
- return [4 /*yield*/, this.updateReviews(+product.id, data)];
3977
- case 3:
3978
- _c.reviews = _d.sent();
3979
- return [3 /*break*/, 6];
3980
- case 4:
3981
- error_1 = _d.sent();
3982
- return [4 /*yield*/, this.delete({ id: product.id })];
3983
- case 5:
3984
- _d.sent();
3985
- throw error_1;
3986
- case 6: return [2 /*return*/, product];
3987
- }
3988
- });
3989
- });
3990
- };
3991
- ProductHasuraGraphQLRepository.prototype.get = function (identifiers) {
3992
- var _super = Object.create(null, {
3993
- get: { get: function () { return _super_1.prototype.get; } }
3994
- });
3995
- var _a;
3996
- return __awaiter(this, void 0, void 0, function () {
3997
- var product, _c, _d;
3998
- return __generator(this, function (_e) {
3999
- switch (_e.label) {
4000
- case 0:
4001
- if (!Number.isNaN(+identifiers.id)) return [3 /*break*/, 2];
4002
- return [4 /*yield*/, this.find({ filters: { firestoreId: identifiers.id } })];
4003
- case 1:
4004
- _c = (_a = (_e.sent()).data) === null || _a === void 0 ? void 0 : _a[0];
4005
- return [3 /*break*/, 4];
4006
- case 2: return [4 /*yield*/, _super.get.call(this, identifiers)];
4007
- case 3:
4008
- _c = _e.sent();
4009
- _e.label = 4;
4010
- case 4:
4011
- product = _c;
4012
- _d = product;
4013
- return [4 /*yield*/, this.findReviewsByProduct(+product.id)];
4014
- case 5:
4015
- _d.reviews = _e.sent();
4016
- return [2 /*return*/, product];
4017
- }
4018
- });
4019
- });
4020
- };
4021
- ProductHasuraGraphQLRepository.prototype.getBySlug = function (slug) {
4022
- var _a;
4023
- return __awaiter(this, void 0, void 0, function () {
4024
- var result, product, _c;
4025
- return __generator(this, function (_d) {
4026
- switch (_d.label) {
4027
- case 0: return [4 /*yield*/, this.find({
4028
- filters: {
4029
- slug: slug,
4030
- },
4031
- })];
4032
- case 1:
4033
- result = _d.sent();
4034
- product = (_a = result === null || result === void 0 ? void 0 : result.data) === null || _a === void 0 ? void 0 : _a.shift();
4035
- _c = product;
4036
- return [4 /*yield*/, this.findReviewsByProduct(+product.id)];
4037
- case 2:
4038
- _c.reviews = _d.sent();
4039
- return [2 /*return*/, product];
4040
- }
4041
- });
4042
- });
4043
- };
4044
- ProductHasuraGraphQLRepository.prototype.update = function (params) {
4045
- var _super = Object.create(null, {
4046
- update: { get: function () { return _super_1.prototype.update; } }
4047
- });
4048
- return __awaiter(this, void 0, void 0, function () {
4049
- var categories, kitProducts, reviews, checkId, shopAvailability, rate, data, plainData, id, product, _c, _d, _e, _f, _g, _h;
4050
- return __generator(this, function (_j) {
4051
- switch (_j.label) {
4052
- case 0:
4053
- categories = params.categories, kitProducts = params.kitProducts, reviews = params.reviews, checkId = params.id, shopAvailability = params.shopAvailability, rate = params.rate, data = __rest(params, ["categories", "kitProducts", "reviews", "id", "shopAvailability", "rate"]);
4054
- plainData = this.paramsToPlain({ id: checkId });
4055
- return [4 /*yield*/, this.getId(plainData.id)];
4056
- case 1:
4057
- id = _j.sent();
4058
- return [4 /*yield*/, _super.update.call(this, Object.assign({ id: id }, data))];
4059
- case 2:
4060
- product = _j.sent();
4061
- _c = product;
4062
- _d = categories;
4063
- if (!_d) return [3 /*break*/, 4];
4064
- return [4 /*yield*/, this.updateCategories(+id, { categories: categories })];
4065
- case 3:
4066
- _d = (_j.sent());
4067
- _j.label = 4;
4068
- case 4:
4069
- _c.categories = _d;
4070
- _e = product;
4071
- _f = kitProducts;
4072
- if (!_f) return [3 /*break*/, 6];
4073
- return [4 /*yield*/, this.updateKitProducts(+id, { kitProducts: kitProducts })];
4074
- case 5:
4075
- _f = (_j.sent());
4076
- _j.label = 6;
4077
- case 6:
4078
- _e.kitProducts = _f;
4079
- _g = product;
4080
- _h = reviews;
4081
- if (!_h) return [3 /*break*/, 8];
4082
- return [4 /*yield*/, this.updateReviews(+id, { reviews: reviews })];
4083
- case 7:
4084
- _h = (_j.sent());
4085
- _j.label = 8;
4086
- case 8:
4087
- _g.reviews = _h;
4088
- return [2 /*return*/, product];
4089
- }
4090
- });
4091
- });
4092
- };
4093
- ProductHasuraGraphQLRepository.prototype.fetchReviews = function (status) {
4094
- return __awaiter(this, void 0, void 0, function () {
4095
- var reviews, data;
4096
- var _c, _d;
4097
- var _this = this;
4098
- return __generator(this, function (_e) {
4099
- switch (_e.label) {
4100
- case 0:
4101
- reviews = {
4102
- status: status === 'pending'
4103
- ? (_c = {}, _c[HasuraGraphQLWhere.ISNULL] = true, _c) : (_d = {}, _d[HasuraGraphQLWhere.EQUALS] = status === 'approved', _d),
4104
- };
4105
- return [4 /*yield*/, this.query('product', ['id', 'name', 'sku', { reviews: { columnName: 'reviews', fields: this.reviewsFields } }], {
4106
- where: { value: { reviews: reviews }, type: 'product_bool_exp', required: true },
4107
- })];
4108
- case 1:
4109
- data = (_e.sent()).product;
4110
- return [2 /*return*/, data.reduce(function (reviews, product) { return __spreadArray(__spreadArray([], __read(reviews)), __read(product.reviews
4111
- .filter(function (review) { return (status === 'pending' && [undefined, null].includes(review.status)) ||
4112
- (status === 'approved' && review.status === true) ||
4113
- (status === 'rejected' && review.status === false); })
4114
- .map(function (review) { return (Object.assign(Object.assign({}, _this.bindReviewToModel(review)), { productId: product.id, productName: product.name, productSku: product.sku })); }))); }, [])];
4115
- }
4116
- });
4117
- });
4118
- };
4119
- ProductHasuraGraphQLRepository.prototype.updateCategories = function (productId, _c) {
4120
- var categories = _c.categories;
4121
- return __awaiter(this, void 0, void 0, function () {
4122
- var plainData;
4123
- return __generator(this, function (_c) {
4124
- switch (_c.label) {
4125
- case 0:
4126
- plainData = this.paramsToPlain({ categories: categories });
4127
- return [4 /*yield*/, this.mutation('delete_category_product', ['affected_rows'], {
4128
- where: {
4129
- type: 'category_product_bool_exp',
4130
- required: true,
4131
- value: { product_id: { _eq: productId } },
4132
- },
4133
- })];
4134
- case 1:
4135
- _c.sent();
4136
- return [4 /*yield*/, this.mutation('insert_category_product', ['affected_rows'], {
4137
- objects: {
4138
- type: '[category_product_insert_input!]',
4139
- required: true,
4140
- value: plainData.categories.map(function (categoryId) { return ({ category_id: categoryId, product_id: productId }); }),
4141
- },
4142
- })];
4143
- case 2:
4144
- _c.sent();
4145
- return [2 /*return*/, plainData.categories];
4146
- }
4147
- });
4148
- });
4149
- };
4150
- ProductHasuraGraphQLRepository.prototype.updateKitProducts = function (productId, _c) {
4151
- var kitProducts = _c.kitProducts;
4152
- return __awaiter(this, void 0, void 0, function () {
4153
- var plainData;
4154
- return __generator(this, function (_c) {
4155
- switch (_c.label) {
4156
- case 0:
4157
- plainData = this.paramsToPlain({ kitProducts: kitProducts });
4158
- return [4 /*yield*/, this.mutation('delete_product_kit', ['affected_rows'], {
4159
- where: {
4160
- type: 'product_kit_bool_exp',
4161
- required: true,
4162
- value: { product_id: { _eq: productId } },
4163
- },
4164
- })];
4165
- case 1:
4166
- _c.sent();
4167
- return [4 /*yield*/, this.mutation('insert_product_kit', ['affected_rows'], {
4168
- objects: {
4169
- type: '[product_kit_insert_input!]',
4170
- required: true,
4171
- value: plainData.kitProducts.map(function (kitProduct) { return ({
4172
- kit_product_id: kitProduct.productId || kitProduct.product.id,
4173
- product_id: productId,
4174
- quantity: kitProduct.quantity,
4175
- }); }),
4176
- },
4177
- })];
4178
- case 2:
4179
- _c.sent();
4180
- return [2 /*return*/, plainData.kitProducts];
4181
- }
4182
- });
4183
- });
4184
- };
4185
- ProductHasuraGraphQLRepository.prototype.updateReviews = function (productId, _c) {
4186
- var reviews = _c.reviews;
4187
- return __awaiter(this, void 0, void 0, function () {
4188
- var reviewIds_1, plainData;
4189
- var _this = this;
4190
- return __generator(this, function (_c) {
4191
- switch (_c.label) {
4192
- case 0:
4193
- if (!reviews)
4194
- return [2 /*return*/, []];
4195
- if (!('action' in reviews && reviews.action === 'remove')) return [3 /*break*/, 3];
4196
- return [4 /*yield*/, Promise.all(reviews.value.map(function (reviewData) { return __awaiter(_this, void 0, void 0, function () {
4197
- var review;
4198
- return __generator(this, function (_c) {
4199
- switch (_c.label) {
4200
- case 0: return [4 /*yield*/, this.findReview(reviewData, productId)];
4201
- case 1:
4202
- review = _c.sent();
4203
- return [2 /*return*/, review === null || review === void 0 ? void 0 : review.id];
4204
- }
4205
- });
4206
- }); }))];
4207
- case 1:
4208
- reviewIds_1 = _c.sent();
4209
- return [4 /*yield*/, this.mutation('delete_product_review', ['affected_rows'], {
4210
- where: { value: { id: { _in: reviewIds_1.filter(Boolean) } }, type: 'product_review_bool_exp', required: true },
4211
- })];
4212
- case 2:
4213
- _c.sent();
4214
- return [2 /*return*/, reviews.value.map(function (review, index) { return !reviewIds_1[index] && review; }).filter(Boolean)];
4215
- case 3:
4216
- plainData = this.paramsToPlain({ reviews: reviews });
4217
- return [2 /*return*/, Promise.all(plainData.reviews.map(function (reviewData) { return __awaiter(_this, void 0, void 0, function () {
4218
- var review, _c, _d;
4219
- return __generator(this, function (_e) {
4220
- switch (_e.label) {
4221
- case 0: return [4 /*yield*/, this.findReview(reviewData, productId)];
4222
- case 1:
4223
- review = _e.sent();
4224
- if (!review.id) return [3 /*break*/, 3];
4225
- _c = this.bindReviewToModel;
4226
- return [4 /*yield*/, this.mutation('update_product_review_by_pk', this.reviewsFields, {
4227
- pk_columns: {
4228
- value: { id: review.id },
4229
- type: 'product_review_pk_columns_input',
4230
- required: true,
4231
- },
4232
- _set: {
4233
- value: lodash.omit(this.bindReviewToHasura(reviewData), ['id', 'product_id']),
4234
- type: 'product_review_set_input',
4235
- required: true,
4236
- },
4237
- })];
4238
- case 2: return [2 /*return*/, _c.apply(this, [(_e.sent()).update_product_review_by_pk])];
4239
- case 3:
4240
- _d = this.bindReviewToModel;
4241
- return [4 /*yield*/, this.mutation('insert_product_review_one', this.reviewsFields, {
4242
- object: {
4243
- value: lodash.omit(Object.assign(Object.assign({}, this.bindReviewToHasura(reviewData)), { product_id: productId }), ['id']),
4244
- type: 'product_review_insert_input',
4245
- required: true,
4246
- },
4247
- })];
4248
- case 4: return [2 /*return*/, _d.apply(this, [(_e.sent()).insert_product_review_one])];
4249
- }
4250
- });
4251
- }); }))];
4252
- }
4253
- });
4254
- });
4255
- };
4256
- ProductHasuraGraphQLRepository.prototype.getId = function (id) {
4257
- var _a, _b;
4258
- return __awaiter(this, void 0, void 0, function () {
4259
- var data;
4260
- return __generator(this, function (_c) {
4261
- switch (_c.label) {
4262
- case 0:
4263
- if (!Number.isNaN(+id))
4264
- return [2 /*return*/, id];
4265
- return [4 /*yield*/, this.find({ filters: { firestoreId: id } })];
4266
- case 1:
4267
- data = (_c.sent()).data;
4268
- if ((_a = data === null || data === void 0 ? void 0 : data[0]) === null || _a === void 0 ? void 0 : _a.id)
4269
- return [2 /*return*/, (_b = data === null || data === void 0 ? void 0 : data[0]) === null || _b === void 0 ? void 0 : _b.id];
4270
- throw new NotFoundError("Product with id " + id + " not found");
4271
- }
4272
- });
4273
- });
4274
- };
4275
- ProductHasuraGraphQLRepository.prototype.findReviewsByProduct = function (productId) {
4276
- return __awaiter(this, void 0, void 0, function () {
4277
- var data;
4278
- var _this = this;
4279
- return __generator(this, function (_c) {
4280
- switch (_c.label) {
4281
- case 0: return [4 /*yield*/, this.query('product_review', this.reviewsFields, {
4282
- where: {
4283
- value: {
4284
- product_id: { _eq: productId },
4285
- },
4286
- type: 'product_review_bool_exp',
4287
- required: true,
4288
- },
4289
- })];
4290
- case 1:
4291
- data = (_c.sent()).product_review;
4292
- return [2 /*return*/, data && data.map(function (review) { return _this.bindReviewToModel(review); })];
4293
- }
4294
- });
4295
- });
4296
- };
4297
- ProductHasuraGraphQLRepository.prototype.findReview = function (review, productId) {
4298
- return __awaiter(this, void 0, void 0, function () {
4299
- var loadedReview;
4300
- return __generator(this, function (_c) {
4301
- switch (_c.label) {
4302
- case 0:
4303
- if (review.id)
4304
- return [2 /*return*/, review];
4305
- if (!review.personId) return [3 /*break*/, 2];
4306
- return [4 /*yield*/, this.getReviewByPersonId(review.personId, productId)];
4307
- case 1:
4308
- loadedReview = _c.sent();
4309
- _c.label = 2;
4310
- case 2:
4311
- if (!(!loadedReview && review.author && review.email)) return [3 /*break*/, 4];
4312
- return [4 /*yield*/, this.getReviewByAuthorAndEmail(review.author, review.email, productId)];
4313
- case 3:
4314
- loadedReview = _c.sent();
4315
- _c.label = 4;
4316
- case 4: return [2 /*return*/, loadedReview || review];
4317
- }
4318
- });
4319
- });
4320
- };
4321
- ProductHasuraGraphQLRepository.prototype.getReviewByPersonId = function (personId, productId) {
4322
- return __awaiter(this, void 0, void 0, function () {
4323
- var data;
4324
- return __generator(this, function (_c) {
4325
- switch (_c.label) {
4326
- case 0: return [4 /*yield*/, this.query('product_review', this.reviewsFields, {
4327
- where: {
4328
- value: {
4329
- product_id: { _eq: productId },
4330
- person_id: { _eq: personId },
4331
- },
4332
- type: "product_review_bool_exp",
4333
- required: true,
4334
- },
4335
- })];
4336
- case 1:
4337
- data = (_c.sent()).product_review;
4338
- return [2 /*return*/, data && data[0] && this.bindReviewToModel(data[0])];
4339
- }
4340
- });
4341
- });
4342
- };
4343
- ProductHasuraGraphQLRepository.prototype.getReviewByAuthorAndEmail = function (author, email, productId) {
4344
- return __awaiter(this, void 0, void 0, function () {
4345
- var data;
4346
- return __generator(this, function (_c) {
4347
- switch (_c.label) {
4348
- case 0: return [4 /*yield*/, this.query('product_review', this.reviewsFields, {
4349
- where: {
4350
- value: {
4351
- product_id: { _eq: productId },
4352
- author: { _eq: author },
4353
- email: { _eq: email },
4354
- },
4355
- type: "product_review_bool_exp",
4356
- required: true,
4357
- },
4358
- })];
4359
- case 1:
4360
- data = (_c.sent()).product_review;
4361
- return [2 /*return*/, data && data[0] && this.bindReviewToModel(data[0])];
4362
- }
4363
- });
4364
- });
4365
- };
4366
- return ProductHasuraGraphQLRepository;
4367
- }(withCrudHasuraGraphQL(withHasuraGraphQL(Base))));
4368
-
4369
- var VariantHasuraGraphQLRepository = /** @class */ (function (_super_1) {
4370
- __extends(VariantHasuraGraphQLRepository, _super_1);
4371
- function VariantHasuraGraphQLRepository(endpoint, authOptions) {
4372
- return _super_1.call(this, {
4373
- tableName: 'product',
4374
- model: VariantHasuraGraphQL,
4375
- endpoint: endpoint,
4376
- authOptions: authOptions,
4377
- fields: [
4378
- { id: { columnName: 'id', to: function (value) { return +value; }, from: function (value) { return value.toString(); } } },
4379
- { firestoreId: { columnName: 'firestore_id' } },
4380
- { productId: { columnName: 'main_product_id', to: function (value) { return +value; }, from: function (value) { return value === null || value === void 0 ? void 0 : value.toString(); } } },
4381
- { EAN: { columnName: 'ean' } },
4382
- { costPrice: { columnName: 'cost_price' } },
4383
- {
4384
- price: {
4385
- columnName: 'price',
4386
- from: function (price, data) { return Object.values(exports.Shops).reduce(function (prices, shop) {
4387
- var _c;
4388
- return (Object.assign(Object.assign({}, prices), (_c = {}, _c[shop] = {
4389
- price: price,
4390
- fullPrice: data.full_price,
4391
- subscriberDiscountPercentage: data.subscriber_discount_percentage,
4392
- subscriberPrice: data.subscriber_price,
4393
- }, _c)));
4394
- }, {}); },
4395
- bindFindFilter: function (sentence) {
4396
- var filters = Object.values(sentence).shift();
4397
- return Object.assign(Object.assign(Object.assign(Object.assign({}, (((filters === null || filters === void 0 ? void 0 : filters.price) || (filters === null || filters === void 0 ? void 0 : filters.price) === 0) && { price: filters.price })), ((filters.fullPrice || filters.fullPrice === 0) && { full_price: filters.fullPrice })), ((filters.subscriberDiscountPercentage || filters.subscriberDiscountPercentage === 0) && {
4398
- subscriber_discount_percentage: filters.subscriberDiscountPercentage,
4399
- })), ((filters.subscriberPrice || filters.subscriberPrice === 0) && {
4400
- subscriber_price: filters.subscriberPrice,
4401
- }));
4402
- },
4403
- bindPersistData: function (value) {
4404
- var priceData = Object.values(value).shift();
4405
- return Object.assign(Object.assign(Object.assign(Object.assign({}, ((priceData === null || priceData === void 0 ? void 0 : priceData.price) >= 0 && { price: priceData.price })), (priceData.fullPrice >= 0 && { full_price: priceData.fullPrice })), (priceData.subscriberDiscountPercentage >= 0 && {
4406
- subscriber_discount_percentage: priceData.subscriberDiscountPercentage,
4407
- })), (priceData.subscriberPrice >= 0 && { subscriber_price: priceData.subscriberPrice }));
4408
- },
4409
- },
4410
- },
4411
- { fullPrice: { columnName: 'full_price' } },
4412
- { subscriberDiscountPercentage: { columnName: 'subscriber_discount_percentage' } },
4413
- { subscriberPrice: { columnName: 'subscriber_price' } },
4414
- 'sku',
4415
- {
4416
- stock: {
4417
- columnName: 'stock',
4418
- from: function (quantity) { return ({ quantity: quantity }); },
4419
- to: function (value) { return (lodash.isNil(value === null || value === void 0 ? void 0 : value.quantity) ? value : value === null || value === void 0 ? void 0 : value.quantity); },
4420
- },
4421
- },
4422
- 'weight',
4423
- { name: { to: function () { return ''; }, from: function () { return undefined; } } },
4424
- { hasVariants: { columnName: 'has_variants', to: function () { return false; }, from: function () { return undefined; } } },
4425
- { createdAt: { columnName: 'created_at' } },
4426
- { updatedAt: { columnName: 'updated_at' } },
4427
- ],
4428
- }) || this;
4429
- }
4430
- VariantHasuraGraphQLRepository.prototype.get = function (identifiers) {
4431
- var _super = Object.create(null, {
4432
- get: { get: function () { return _super_1.prototype.get; } }
4433
- });
4434
- var _a;
4435
- return __awaiter(this, void 0, void 0, function () {
4436
- var _c;
4437
- return __generator(this, function (_d) {
4438
- switch (_d.label) {
4439
- case 0:
4440
- if (!Number.isNaN(+identifiers.id)) return [3 /*break*/, 2];
4441
- return [4 /*yield*/, this.find({ filters: { firestoreId: identifiers.id } })];
4442
- case 1:
4443
- _c = (_a = (_d.sent()).data) === null || _a === void 0 ? void 0 : _a[0];
4444
- return [3 /*break*/, 3];
4445
- case 2:
4446
- _c = _super.get.call(this, identifiers);
4447
- _d.label = 3;
4448
- case 3: return [2 /*return*/, _c];
4449
- }
4450
- });
4451
- });
4452
- };
4453
- VariantHasuraGraphQLRepository.prototype.update = function (params) {
4454
- var _super = Object.create(null, {
4455
- update: { get: function () { return _super_1.prototype.update; } }
4456
- });
4457
- return __awaiter(this, void 0, void 0, function () {
4458
- var productId, checkId, data, dataWithProductId, id, product;
4459
- return __generator(this, function (_c) {
4460
- switch (_c.label) {
4461
- case 0:
4462
- productId = params.productId, checkId = params.id, data = __rest(params, ["productId", "id"]);
4463
- dataWithProductId = this.paramsToPlain({ id: checkId, productId: productId });
4464
- return [4 /*yield*/, this.getId(dataWithProductId.id)];
4465
- case 1:
4466
- id = _c.sent();
4467
- return [4 /*yield*/, _super.update.call(this, Object.assign({ id: id }, data))];
4468
- case 2:
4469
- product = _c.sent();
4470
- product.productId = dataWithProductId.productId;
4471
- return [2 /*return*/, product];
4472
- }
4473
- });
4474
- });
4475
- };
4476
- VariantHasuraGraphQLRepository.prototype.getId = function (id) {
4477
- var _a, _b;
4478
- return __awaiter(this, void 0, void 0, function () {
4479
- var data;
4480
- return __generator(this, function (_c) {
4481
- switch (_c.label) {
4482
- case 0:
4483
- if (!Number.isNaN(+id))
4484
- return [2 /*return*/, id];
4485
- return [4 /*yield*/, this.find({ filters: { firestoreId: id } })];
4486
- case 1:
4487
- data = (_c.sent()).data;
4488
- if ((_a = data === null || data === void 0 ? void 0 : data[0]) === null || _a === void 0 ? void 0 : _a.id)
4489
- return [2 /*return*/, (_b = data === null || data === void 0 ? void 0 : data[0]) === null || _b === void 0 ? void 0 : _b.id];
4490
- throw new NotFoundError("Product with id " + id + " not found");
4491
- }
4492
- });
4493
- });
4494
- };
4495
- return VariantHasuraGraphQLRepository;
4496
- }(withCrudHasuraGraphQL(withHasuraGraphQL(Base))));
4497
-
4498
- /**
4499
- * Generated bundle index. Do not edit.
4500
- */
2665
+ /**
2666
+ * Generated bundle index. Do not edit.
2667
+ */
4501
2668
 
4502
2669
  Object.defineProperty(exports, 'add', {
4503
2670
  enumerable: true,
4504
2671
  get: function () { return dateFns.add; }
4505
2672
  });
4506
- Object.defineProperty(exports, 'addBusinessDays', {
4507
- enumerable: true,
4508
- get: function () { return dateFns.addBusinessDays; }
4509
- });
4510
- Object.defineProperty(exports, 'addDays', {
4511
- enumerable: true,
4512
- get: function () { return dateFns.addDays; }
4513
- });
4514
- Object.defineProperty(exports, 'addMonths', {
4515
- enumerable: true,
4516
- get: function () { return dateFns.addMonths; }
4517
- });
4518
- Object.defineProperty(exports, 'addYears', {
4519
- enumerable: true,
4520
- get: function () { return dateFns.addYears; }
4521
- });
4522
- Object.defineProperty(exports, 'endOfDay', {
4523
- enumerable: true,
4524
- get: function () { return dateFns.endOfDay; }
4525
- });
4526
- Object.defineProperty(exports, 'format', {
4527
- enumerable: true,
4528
- get: function () { return dateFns.format; }
4529
- });
4530
- Object.defineProperty(exports, 'formatISO9075', {
4531
- enumerable: true,
4532
- get: function () { return dateFns.formatISO9075; }
4533
- });
4534
- Object.defineProperty(exports, 'parseISO', {
4535
- enumerable: true,
4536
- get: function () { return dateFns.parseISO; }
4537
- });
4538
- Object.defineProperty(exports, 'startOfDay', {
4539
- enumerable: true,
4540
- get: function () { return dateFns.startOfDay; }
4541
- });
4542
2673
  Object.defineProperty(exports, 'sub', {
4543
2674
  enumerable: true,
4544
2675
  get: function () { return dateFns.sub; }
@@ -4547,9 +2678,9 @@
4547
2678
  enumerable: true,
4548
2679
  get: function () { return lodash.chunk; }
4549
2680
  });
4550
- Object.defineProperty(exports, 'isBoolean', {
2681
+ Object.defineProperty(exports, 'get', {
4551
2682
  enumerable: true,
4552
- get: function () { return lodash.isBoolean; }
2683
+ get: function () { return lodash.get; }
4553
2684
  });
4554
2685
  Object.defineProperty(exports, 'isDate', {
4555
2686
  enumerable: true,
@@ -4559,14 +2690,6 @@
4559
2690
  enumerable: true,
4560
2691
  get: function () { return lodash.isEmpty; }
4561
2692
  });
4562
- Object.defineProperty(exports, 'isInteger', {
4563
- enumerable: true,
4564
- get: function () { return lodash.isInteger; }
4565
- });
4566
- Object.defineProperty(exports, 'isNaN', {
4567
- enumerable: true,
4568
- get: function () { return lodash.isNaN; }
4569
- });
4570
2693
  Object.defineProperty(exports, 'isNil', {
4571
2694
  enumerable: true,
4572
2695
  get: function () { return lodash.isNil; }
@@ -4583,14 +2706,6 @@
4583
2706
  enumerable: true,
4584
2707
  get: function () { return lodash.isString; }
4585
2708
  });
4586
- Object.defineProperty(exports, 'now', {
4587
- enumerable: true,
4588
- get: function () { return lodash.now; }
4589
- });
4590
- Object.defineProperty(exports, 'omit', {
4591
- enumerable: true,
4592
- get: function () { return lodash.omit; }
4593
- });
4594
2709
  Object.defineProperty(exports, 'pick', {
4595
2710
  enumerable: true,
4596
2711
  get: function () { return lodash.pick; }
@@ -4611,22 +2726,18 @@
4611
2726
  exports.Buy2WinFirestoreRepository = Buy2WinFirestoreRepository;
4612
2727
  exports.Category = Category;
4613
2728
  exports.CategoryFirestoreRepository = CategoryFirestoreRepository;
4614
- exports.CategoryHasuraGraphQL = CategoryHasuraGraphQL;
4615
- exports.CategoryHasuraGraphQLRepository = CategoryHasuraGraphQLRepository;
4616
2729
  exports.Checkout = Checkout;
4617
2730
  exports.CheckoutFirestoreRepository = CheckoutFirestoreRepository;
4618
2731
  exports.CheckoutSubscription = CheckoutSubscription;
4619
2732
  exports.CheckoutSubscriptionFirestoreRepository = CheckoutSubscriptionFirestoreRepository;
2733
+ exports.ClubCoupon = ClubCoupon;
4620
2734
  exports.Coupon = Coupon;
4621
2735
  exports.CouponFirestoreRepository = CouponFirestoreRepository;
4622
2736
  exports.DuplicatedResultsError = DuplicatedResultsError;
4623
2737
  exports.Edition = Edition;
4624
- exports.FinancialCoupon = FinancialCoupon;
4625
2738
  exports.Home = Home;
4626
2739
  exports.HomeFirestoreRepository = HomeFirestoreRepository;
4627
2740
  exports.InvalidArgumentError = InvalidArgumentError;
4628
- exports.KitProduct = KitProduct;
4629
- exports.KitProductHasuraGraphQL = KitProductHasuraGraphQL;
4630
2741
  exports.Lead = Lead;
4631
2742
  exports.LeadFirestoreRepository = LeadFirestoreRepository;
4632
2743
  exports.LegacyOrderFirestoreRepository = LegacyOrderFirestoreRepository;
@@ -4638,8 +2749,6 @@
4638
2749
  exports.PaymentFirestoreRepository = PaymentFirestoreRepository;
4639
2750
  exports.Product = Product;
4640
2751
  exports.ProductFirestoreRepository = ProductFirestoreRepository;
4641
- exports.ProductHasuraGraphQL = ProductHasuraGraphQL;
4642
- exports.ProductHasuraGraphQLRepository = ProductHasuraGraphQLRepository;
4643
2752
  exports.ProductVariantFirestoreRepository = ProductVariantFirestoreRepository;
4644
2753
  exports.ProductsIndex = ProductsIndex;
4645
2754
  exports.RecoveryPassword = RecoveryPassword;
@@ -4650,6 +2759,7 @@
4650
2759
  exports.ShopMenu = ShopMenu;
4651
2760
  exports.ShopMenuFirestoreRepository = ShopMenuFirestoreRepository;
4652
2761
  exports.SignOut = SignOut;
2762
+ exports.StoreCoupon = StoreCoupon;
4653
2763
  exports.Subscription = Subscription;
4654
2764
  exports.SubscriptionEditionFirestoreRepository = SubscriptionEditionFirestoreRepository;
4655
2765
  exports.SubscriptionFirestoreRepository = SubscriptionFirestoreRepository;
@@ -4669,27 +2779,16 @@
4669
2779
  exports.UserPaymentMethodFirestoreRepository = UserPaymentMethodFirestoreRepository;
4670
2780
  exports.UserSearchFirestoreRepository = UserSearchFirestoreRepository;
4671
2781
  exports.Variant = Variant;
4672
- exports.VariantHasuraGraphQL = VariantHasuraGraphQL;
4673
- exports.VariantHasuraGraphQLRepository = VariantHasuraGraphQLRepository;
4674
2782
  exports.WeakPasswordError = WeakPasswordError;
4675
- exports.isUUID = isUUID;
4676
- exports.parseDateTime = parseDateTime;
4677
2783
  exports.withCreateFirestore = withCreateFirestore;
4678
- exports.withCreateHasuraGraphQL = withCreateHasuraGraphQL;
4679
2784
  exports.withCrudFirestore = withCrudFirestore;
4680
- exports.withCrudHasuraGraphQL = withCrudHasuraGraphQL;
4681
2785
  exports.withDeleteFirestore = withDeleteFirestore;
4682
- exports.withDeleteHasuraGraphQL = withDeleteHasuraGraphQL;
4683
2786
  exports.withFindFirestore = withFindFirestore;
4684
- exports.withFindHasuraGraphQL = withFindHasuraGraphQL;
4685
2787
  exports.withFirestore = withFirestore;
4686
2788
  exports.withGetFirestore = withGetFirestore;
4687
- exports.withGetHasuraGraphQL = withGetHasuraGraphQL;
4688
- exports.withHasuraGraphQL = withHasuraGraphQL;
4689
2789
  exports.withHelpers = withHelpers;
4690
2790
  exports.withSubCollection = withSubCollection;
4691
2791
  exports.withUpdateFirestore = withUpdateFirestore;
4692
- exports.withUpdateHasuraGraphQL = withUpdateHasuraGraphQL;
4693
2792
 
4694
2793
  Object.defineProperty(exports, '__esModule', { value: true });
4695
2794