@infrab4a/connect 4.9.7-beta.3 → 4.9.7-beta.30

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 (82) hide show
  1. package/index.cjs.js +1048 -616
  2. package/index.esm.js +1041 -617
  3. package/package.json +1 -1
  4. package/src/domain/catalog/models/category-base.d.ts +17 -1
  5. package/src/domain/catalog/models/category-product.d.ts +8 -0
  6. package/src/domain/catalog/models/enums/index.d.ts +1 -0
  7. package/src/domain/catalog/models/enums/wishlist-log.enum.d.ts +7 -0
  8. package/src/domain/catalog/models/filter.d.ts +1 -0
  9. package/src/domain/catalog/models/index.d.ts +1 -0
  10. package/src/domain/catalog/models/product-base.d.ts +4 -1
  11. package/src/domain/catalog/models/types/category-images.type.d.ts +8 -0
  12. package/src/domain/catalog/models/types/category-metadata.type.d.ts +2 -0
  13. package/src/domain/catalog/models/types/category-most-relevant.type.d.ts +4 -0
  14. package/src/domain/catalog/models/types/index.d.ts +4 -1
  15. package/src/domain/catalog/models/types/product-label.type.d.ts +1 -0
  16. package/src/domain/catalog/models/types/report-stock-notification.type.d.ts +21 -0
  17. package/src/domain/catalog/models/variant.d.ts +2 -0
  18. package/src/domain/catalog/models/wishlist.d.ts +3 -0
  19. package/src/domain/catalog/repositories/category-product.repository.d.ts +6 -0
  20. package/src/domain/catalog/repositories/category.repository.d.ts +3 -3
  21. package/src/domain/catalog/repositories/index.d.ts +1 -0
  22. package/src/domain/catalog/repositories/product-reviews.repository.d.ts +1 -0
  23. package/src/domain/catalog/repositories/product-stock-notification.repository.d.ts +9 -1
  24. package/src/domain/catalog/repositories/wishlist.repository.d.ts +6 -1
  25. package/src/domain/general/index.d.ts +3 -0
  26. package/src/domain/general/models/index.d.ts +1 -0
  27. package/src/domain/general/models/log-document.d.ts +15 -0
  28. package/src/domain/general/repositories/index.d.ts +1 -0
  29. package/src/domain/general/repositories/log.repository.d.ts +4 -0
  30. package/src/domain/general/search/index.d.ts +1 -0
  31. package/src/domain/general/search/product-search-index.d.ts +3 -0
  32. package/src/domain/shopping/index.d.ts +1 -0
  33. package/src/domain/shopping/models/buy-2-win.d.ts +2 -0
  34. package/src/domain/shopping/models/coupons/coupon.d.ts +8 -4
  35. package/src/domain/shopping/models/coupons/enums/coupon-category.enum.d.ts +41 -0
  36. package/src/domain/shopping/models/coupons/enums/coupon-channels.enum.d.ts +10 -0
  37. package/src/domain/shopping/models/coupons/enums/coupon-types.enum.d.ts +2 -1
  38. package/src/domain/shopping/models/coupons/enums/index.d.ts +3 -1
  39. package/src/domain/shopping/models/coupons/types/coupon-category.type.d.ts +2 -0
  40. package/src/domain/shopping/models/coupons/types/coupon-channel.type.d.ts +2 -0
  41. package/src/domain/shopping/models/coupons/types/index.d.ts +2 -0
  42. package/src/domain/shopping/models/index.d.ts +1 -0
  43. package/src/domain/shopping/models/order-blocked.d.ts +26 -0
  44. package/src/domain/shopping/models/order.d.ts +4 -0
  45. package/src/domain/shopping/repositories/index.d.ts +1 -0
  46. package/src/domain/shopping/repositories/order-blocked.repository.d.ts +6 -0
  47. package/src/domain/shopping/types/index.d.ts +2 -0
  48. package/src/domain/shopping/types/order-tracking-events.type.d.ts +14 -0
  49. package/src/domain/shopping/types/payment-card-info.type.d.ts +4 -0
  50. package/src/domain/users/models/enums/index.d.ts +1 -0
  51. package/src/domain/users/models/enums/person-types.enum.d.ts +5 -0
  52. package/src/domain/users/models/index.d.ts +3 -2
  53. package/src/domain/users/models/types/index.d.ts +1 -0
  54. package/src/domain/users/models/types/person.type.d.ts +2 -0
  55. package/src/infra/elasticsearch/indexes/products-index.d.ts +39 -1
  56. package/src/infra/firebase/firestore/mixins/with-helpers.mixin.d.ts +1 -1
  57. package/src/infra/firebase/firestore/repositories/catalog/category-firestore.repository.d.ts +2 -2
  58. package/src/infra/firebase/firestore/repositories/general/index.d.ts +1 -0
  59. package/src/infra/firebase/firestore/repositories/general/log-firestore.repository.d.ts +7 -0
  60. package/src/infra/firebase/firestore/repositories/index.d.ts +3 -2
  61. package/src/infra/firebase/firestore/repositories/shopping/index.d.ts +1 -0
  62. package/src/infra/firebase/firestore/repositories/shopping/order-blocked-firestore.repository.ts.d.ts +9 -0
  63. package/src/infra/hasura-graphql/mixins/with-find-hasura-graphql.mixin.d.ts +1 -0
  64. package/src/infra/hasura-graphql/models/wishlist-hasura-graphql.d.ts +4 -0
  65. package/src/infra/hasura-graphql/repositories/catalog/category-hasura-graphql.repository.d.ts +2 -2
  66. package/src/infra/hasura-graphql/repositories/catalog/category-product-hasura-graphql.repository.d.ts +11 -0
  67. package/src/infra/hasura-graphql/repositories/catalog/index.d.ts +1 -0
  68. package/src/infra/hasura-graphql/repositories/catalog/product-hasura-graphql.repository.d.ts +0 -1
  69. package/src/infra/hasura-graphql/repositories/catalog/product-review-hasura-graphql.repository.d.ts +1 -0
  70. package/src/infra/hasura-graphql/repositories/catalog/product-stock-notification-hasura-graphql.repository.d.ts +8 -1
  71. package/src/infra/hasura-graphql/repositories/catalog/wishlist-hasura-graphql.repository.d.ts +18 -15
  72. package/src/infra/index.d.ts +1 -0
  73. package/src/infra/vertex-ai/adapters/index.d.ts +2 -0
  74. package/src/infra/vertex-ai/adapters/vertex-ai-search.adapter.d.ts +10 -0
  75. package/src/infra/vertex-ai/adapters/vertex-axios.adapter.d.ts +15 -0
  76. package/src/infra/vertex-ai/index.d.ts +3 -0
  77. package/src/infra/vertex-ai/indexes/index.d.ts +1 -0
  78. package/src/infra/vertex-ai/indexes/products-vertex-search.d.ts +13 -0
  79. package/src/infra/vertex-ai/types/axios-vertex-search-config.d.ts +4 -0
  80. package/src/infra/vertex-ai/types/index.d.ts +3 -0
  81. package/src/infra/vertex-ai/types/product-bulk.d.ts +4 -0
  82. package/src/infra/vertex-ai/types/product-search.d.ts +21 -0
package/index.cjs.js CHANGED
@@ -42,6 +42,30 @@ class BaseModel {
42
42
  }
43
43
  }
44
44
 
45
+ exports.GenderDestination = void 0;
46
+ (function (GenderDestination) {
47
+ GenderDestination["FEMALE"] = "female";
48
+ GenderDestination["MALE"] = "male";
49
+ GenderDestination["UNISEX"] = "unisex";
50
+ })(exports.GenderDestination || (exports.GenderDestination = {}));
51
+
52
+ exports.Shops = void 0;
53
+ (function (Shops) {
54
+ Shops["MENSMARKET"] = "mensmarket";
55
+ Shops["GLAMSHOP"] = "Glamshop";
56
+ Shops["GLAMPOINTS"] = "Glampoints";
57
+ Shops["ALL"] = "ALL";
58
+ })(exports.Shops || (exports.Shops = {}));
59
+
60
+ exports.WishlistLogType = void 0;
61
+ (function (WishlistLogType) {
62
+ WishlistLogType["CREATE"] = "create";
63
+ WishlistLogType["UPDATE"] = "update";
64
+ WishlistLogType["DELETE"] = "delete";
65
+ WishlistLogType["ADD_PRODUCT"] = "add_product";
66
+ WishlistLogType["REMOVE_PRODUCT"] = "remove_product";
67
+ })(exports.WishlistLogType || (exports.WishlistLogType = {}));
68
+
45
69
  class Filter extends BaseModel {
46
70
  static get identifiersFields() {
47
71
  return ['id'];
@@ -56,6 +80,33 @@ class CategoryBase extends BaseModel {
56
80
  static get identifiersFields() {
57
81
  return ['id'];
58
82
  }
83
+ get glamImages() {
84
+ return this.images && this.images[exports.Shops.GLAMSHOP]
85
+ ? this.images[exports.Shops.GLAMSHOP]
86
+ : {
87
+ brandBanner: null,
88
+ brandBannerMobile: null,
89
+ image: null,
90
+ };
91
+ }
92
+ get mensImages() {
93
+ return this.images && this.images[exports.Shops.MENSMARKET]
94
+ ? this.images[exports.Shops.MENSMARKET]
95
+ : {
96
+ brandBanner: null,
97
+ brandBannerMobile: null,
98
+ image: null,
99
+ };
100
+ }
101
+ get glamMetadata() {
102
+ return this.metadatas.find((metadata) => metadata.shop === exports.Shops.GLAMSHOP);
103
+ }
104
+ get mensMetadata() {
105
+ return this.metadatas.find((metadata) => metadata.shop === exports.Shops.MENSMARKET);
106
+ }
107
+ getMostRelevantByShop(shop) {
108
+ return this.mostRelevants && this.mostRelevants[shop] ? this.mostRelevants[shop] : [];
109
+ }
59
110
  }
60
111
  tslib.__decorate([
61
112
  classTransformer.Type(() => CategoryBase),
@@ -164,20 +215,11 @@ tslib.__decorate([
164
215
  tslib.__metadata("design:type", Category)
165
216
  ], CategoryFilter.prototype, "category", void 0);
166
217
 
167
- exports.GenderDestination = void 0;
168
- (function (GenderDestination) {
169
- GenderDestination["FEMALE"] = "female";
170
- GenderDestination["MALE"] = "male";
171
- GenderDestination["UNISEX"] = "unisex";
172
- })(exports.GenderDestination || (exports.GenderDestination = {}));
173
-
174
- exports.Shops = void 0;
175
- (function (Shops) {
176
- Shops["MENSMARKET"] = "mensmarket";
177
- Shops["GLAMSHOP"] = "Glamshop";
178
- Shops["GLAMPOINTS"] = "Glampoints";
179
- Shops["ALL"] = "ALL";
180
- })(exports.Shops || (exports.Shops = {}));
218
+ class CategoryProduct extends BaseModel {
219
+ static get identifiersFields() {
220
+ return ['categoryId', 'productId'];
221
+ }
222
+ }
181
223
 
182
224
  class FilterOption extends BaseModel {
183
225
  static get identifiersFields() {
@@ -271,6 +313,17 @@ class CampaignHashtag extends BaseModel {
271
313
  }
272
314
  }
273
315
 
316
+ class BeautyProfile extends BaseModel {
317
+ toPlain() {
318
+ const plain = super.toPlain();
319
+ delete plain.id;
320
+ return plain;
321
+ }
322
+ static get identifiersFields() {
323
+ return ['id', 'userId'];
324
+ }
325
+ }
326
+
274
327
  exports.AccessoryImportances = void 0;
275
328
  (function (AccessoryImportances) {
276
329
  AccessoryImportances["NOT_INTERESTED"] = "N\u00E3o tenho interesse";
@@ -447,6 +500,13 @@ exports.OfficePosition = void 0;
447
500
  OfficePosition["Director"] = "Diretor";
448
501
  })(exports.OfficePosition || (exports.OfficePosition = {}));
449
502
 
503
+ exports.PersonTypes = void 0;
504
+ (function (PersonTypes) {
505
+ PersonTypes["GLAMGIRL"] = "glamgirl";
506
+ PersonTypes["BFLU"] = "bflu";
507
+ PersonTypes["NONE"] = "none";
508
+ })(exports.PersonTypes || (exports.PersonTypes = {}));
509
+
450
510
  exports.ProductSpents = void 0;
451
511
  (function (ProductSpents) {
452
512
  ProductSpents["UNTIL_50"] = "At\u00E9 R$50";
@@ -467,6 +527,12 @@ exports.UserType = void 0;
467
527
  UserType["Influencer"] = "Influencer";
468
528
  })(exports.UserType || (exports.UserType = {}));
469
529
 
530
+ class Lead extends BaseModel {
531
+ static get identifiersFields() {
532
+ return ['id'];
533
+ }
534
+ }
535
+
470
536
  class Edition extends BaseModel {
471
537
  static get identifiersFields() {
472
538
  return ['id', 'subscriptionId'];
@@ -1792,40 +1858,6 @@ const parseDateTime = (value) => {
1792
1858
  return date;
1793
1859
  };
1794
1860
 
1795
- exports.CheckoutTypes = void 0;
1796
- (function (CheckoutTypes) {
1797
- CheckoutTypes[CheckoutTypes["ECOMMERCE"] = 1] = "ECOMMERCE";
1798
- CheckoutTypes[CheckoutTypes["SUBSCRIPTION"] = 2] = "SUBSCRIPTION";
1799
- CheckoutTypes[CheckoutTypes["ALL"] = 3] = "ALL";
1800
- })(exports.CheckoutTypes || (exports.CheckoutTypes = {}));
1801
-
1802
- exports.CouponTypes = void 0;
1803
- (function (CouponTypes) {
1804
- CouponTypes[CouponTypes["ABSOLUTE"] = 1] = "ABSOLUTE";
1805
- CouponTypes[CouponTypes["PERCENTAGE"] = 2] = "PERCENTAGE";
1806
- // FINANCIAL = 1,
1807
- // PRODUCT,
1808
- // GIFTCARD,
1809
- // VOUCHER,
1810
- })(exports.CouponTypes || (exports.CouponTypes = {}));
1811
-
1812
- exports.CouponSubtypes = void 0;
1813
- (function (CouponSubtypes) {
1814
- CouponSubtypes[CouponSubtypes["ABSOLUTE"] = 1] = "ABSOLUTE";
1815
- CouponSubtypes[CouponSubtypes["PERCENTAGE"] = 2] = "PERCENTAGE";
1816
- })(exports.CouponSubtypes || (exports.CouponSubtypes = {}));
1817
-
1818
- exports.Exclusivities = void 0;
1819
- (function (Exclusivities) {
1820
- Exclusivities[Exclusivities["ALL_USERS"] = 1] = "ALL_USERS";
1821
- Exclusivities[Exclusivities["SPECIFIC_USER"] = 2] = "SPECIFIC_USER";
1822
- Exclusivities[Exclusivities["COLLABORATORS"] = 3] = "COLLABORATORS";
1823
- Exclusivities[Exclusivities["ACTIVE_SUBSCRIBER"] = 4] = "ACTIVE_SUBSCRIBER";
1824
- Exclusivities[Exclusivities["INACTIVE_SUBSCRIBER"] = 5] = "INACTIVE_SUBSCRIBER";
1825
- Exclusivities[Exclusivities["NON_SUBSCRIBER"] = 6] = "NON_SUBSCRIBER";
1826
- })(exports.Exclusivities || (exports.Exclusivities = {}));
1827
-
1828
- const COUPON_EXPIRATION = +1000 * 60 * 60 * 24 * 30;
1829
1861
  class Coupon extends BaseModel {
1830
1862
  get isInfluencer() {
1831
1863
  return !lodash.isNil(this.influencerEmail);
@@ -1833,30 +1865,6 @@ class Coupon extends BaseModel {
1833
1865
  static get identifiersFields() {
1834
1866
  return ['id'];
1835
1867
  }
1836
- static createCoupon(userId) {
1837
- return this.toInstance({
1838
- nickname: `${Date.now()}`,
1839
- checkoutType: exports.CheckoutTypes.ECOMMERCE,
1840
- discount: {
1841
- subscriber: {
1842
- type: exports.CouponTypes.ABSOLUTE,
1843
- value: 10,
1844
- },
1845
- non_subscriber: {
1846
- type: exports.CouponTypes.ABSOLUTE,
1847
- value: 10,
1848
- },
1849
- subscription: {
1850
- type: exports.CouponTypes.ABSOLUTE,
1851
- value: 10,
1852
- },
1853
- },
1854
- user: userId,
1855
- createdAt: new Date(Date.now()),
1856
- beginAt: new Date(Date.now()),
1857
- expiresIn: new Date(Date.now() + COUPON_EXPIRATION),
1858
- });
1859
- }
1860
1868
  }
1861
1869
 
1862
1870
  class SubscriptionPlan extends BaseModel {
@@ -1865,17 +1873,6 @@ class SubscriptionPlan extends BaseModel {
1865
1873
  }
1866
1874
  }
1867
1875
 
1868
- class BeautyProfile extends BaseModel {
1869
- toPlain() {
1870
- const plain = super.toPlain();
1871
- delete plain.id;
1872
- return plain;
1873
- }
1874
- static get identifiersFields() {
1875
- return ['id', 'userId'];
1876
- }
1877
- }
1878
-
1879
1876
  class User extends BaseModel {
1880
1877
  static toInstance(data) {
1881
1878
  const instance = super.toInstance(data);
@@ -1989,12 +1986,6 @@ class UserPaymentMethod extends BaseModel {
1989
1986
  }
1990
1987
  }
1991
1988
 
1992
- class Lead extends BaseModel {
1993
- static get identifiersFields() {
1994
- return ['id'];
1995
- }
1996
- }
1997
-
1998
1989
  class UnauthorizedError extends tsCustomError.CustomError {
1999
1990
  constructor(message) {
2000
1991
  super(message);
@@ -2148,6 +2139,93 @@ tslib.__decorate([
2148
2139
  tslib.__metadata("design:type", Coupon)
2149
2140
  ], Checkout.prototype, "coupon", void 0);
2150
2141
 
2142
+ exports.CouponCategory = void 0;
2143
+ (function (CouponCategory) {
2144
+ CouponCategory["Reembolso"] = "Reembolso";
2145
+ CouponCategory["Desculpas"] = "Desculpas";
2146
+ CouponCategory["BFlu"] = "BFlu";
2147
+ CouponCategory["ROYAL"] = "Royal";
2148
+ CouponCategory["Glamqueens"] = "Glamqueens";
2149
+ CouponCategory["Glampartner"] = "Glampartner";
2150
+ CouponCategory["Glamgirls"] = "Glamgirls";
2151
+ CouponCategory["Glamdiva"] = "Glamdiva";
2152
+ CouponCategory["Impulsionamento"] = "Impulsionamento";
2153
+ CouponCategory["PaidMedia"] = "Paid Media";
2154
+ CouponCategory["Organic"] = "Organic";
2155
+ CouponCategory["Direct"] = "Direct";
2156
+ CouponCategory["CRM"] = "CRM";
2157
+ CouponCategory["LOJAUNICO"] = "Loja \u00FAnico";
2158
+ CouponCategory["Outros"] = "Outros";
2159
+ })(exports.CouponCategory || (exports.CouponCategory = {}));
2160
+ exports.CouponOldCategories = void 0;
2161
+ (function (CouponOldCategories) {
2162
+ CouponOldCategories["Reembolso"] = "Reembolso";
2163
+ CouponOldCategories["Desculpas"] = "Desculpas";
2164
+ CouponOldCategories["BFlu"] = "BFlu";
2165
+ CouponOldCategories["ROYAL"] = "Royal";
2166
+ CouponOldCategories["Glamqueens"] = "Glamqueens";
2167
+ CouponOldCategories["Glampartner"] = "Glampartner";
2168
+ CouponOldCategories["Glamgirls"] = "Glamgirls";
2169
+ CouponOldCategories["Glamdiva"] = "Glamdiva";
2170
+ CouponOldCategories["Impulsionamento"] = "Impulsionamento";
2171
+ CouponOldCategories["PaidMedia"] = "Paid Media";
2172
+ CouponOldCategories["Organic"] = "Organic";
2173
+ CouponOldCategories["Direct"] = "Direct";
2174
+ CouponOldCategories["CRM"] = "CRM";
2175
+ CouponOldCategories["LOJAUNICO"] = "Loja \u00FAnico";
2176
+ CouponOldCategories["Outros"] = "Outros";
2177
+ })(exports.CouponOldCategories || (exports.CouponOldCategories = {}));
2178
+ exports.CouponCategories = void 0;
2179
+ (function (CouponCategories) {
2180
+ CouponCategories["API_001"] = "API-001";
2181
+ CouponCategories["COMPRE_E_GANHE"] = "COMPRE E GANHE";
2182
+ CouponCategories["DESCONTO"] = "DESCONTO";
2183
+ CouponCategories["REEMBOLSO"] = "REEMBOLSO";
2184
+ CouponCategories["DESCULPAS"] = "DESCULPAS";
2185
+ })(exports.CouponCategories || (exports.CouponCategories = {}));
2186
+
2187
+ exports.CouponChannels = void 0;
2188
+ (function (CouponChannels) {
2189
+ CouponChannels["BANNER"] = "7";
2190
+ CouponChannels["BFLUENCE"] = "3";
2191
+ CouponChannels["CRM"] = "2";
2192
+ CouponChannels["GLAMGIRL"] = "0";
2193
+ CouponChannels["PAID"] = "4";
2194
+ CouponChannels["ROYAL"] = "1";
2195
+ CouponChannels["SAC"] = "8";
2196
+ CouponChannels["SOCIAL"] = "5";
2197
+ })(exports.CouponChannels || (exports.CouponChannels = {}));
2198
+
2199
+ exports.CouponSubtypes = void 0;
2200
+ (function (CouponSubtypes) {
2201
+ CouponSubtypes[CouponSubtypes["ABSOLUTE"] = 1] = "ABSOLUTE";
2202
+ CouponSubtypes[CouponSubtypes["PERCENTAGE"] = 2] = "PERCENTAGE";
2203
+ })(exports.CouponSubtypes || (exports.CouponSubtypes = {}));
2204
+
2205
+ exports.CouponTypes = void 0;
2206
+ (function (CouponTypes) {
2207
+ CouponTypes[CouponTypes["ABSOLUTE"] = 1] = "ABSOLUTE";
2208
+ CouponTypes[CouponTypes["PERCENTAGE"] = 2] = "PERCENTAGE";
2209
+ CouponTypes[CouponTypes["SHIPPING"] = 3] = "SHIPPING";
2210
+ })(exports.CouponTypes || (exports.CouponTypes = {}));
2211
+
2212
+ exports.Exclusivities = void 0;
2213
+ (function (Exclusivities) {
2214
+ Exclusivities[Exclusivities["ALL_USERS"] = 1] = "ALL_USERS";
2215
+ Exclusivities[Exclusivities["SPECIFIC_USER"] = 2] = "SPECIFIC_USER";
2216
+ Exclusivities[Exclusivities["COLLABORATORS"] = 3] = "COLLABORATORS";
2217
+ Exclusivities[Exclusivities["ACTIVE_SUBSCRIBER"] = 4] = "ACTIVE_SUBSCRIBER";
2218
+ Exclusivities[Exclusivities["INACTIVE_SUBSCRIBER"] = 5] = "INACTIVE_SUBSCRIBER";
2219
+ Exclusivities[Exclusivities["NON_SUBSCRIBER"] = 6] = "NON_SUBSCRIBER";
2220
+ })(exports.Exclusivities || (exports.Exclusivities = {}));
2221
+
2222
+ exports.CheckoutTypes = void 0;
2223
+ (function (CheckoutTypes) {
2224
+ CheckoutTypes[CheckoutTypes["ECOMMERCE"] = 1] = "ECOMMERCE";
2225
+ CheckoutTypes[CheckoutTypes["SUBSCRIPTION"] = 2] = "SUBSCRIPTION";
2226
+ CheckoutTypes[CheckoutTypes["ALL"] = 3] = "ALL";
2227
+ })(exports.CheckoutTypes || (exports.CheckoutTypes = {}));
2228
+
2151
2229
  exports.OrderStatus = void 0;
2152
2230
  (function (OrderStatus) {
2153
2231
  OrderStatus["AGUARDANDO_PAGAMENTO"] = "Aguardando pagamento";
@@ -2167,6 +2245,12 @@ tslib.__decorate([
2167
2245
  tslib.__metadata("design:type", Payment)
2168
2246
  ], Order.prototype, "payment", void 0);
2169
2247
 
2248
+ class OrderBlocked extends BaseModel {
2249
+ static get identifiersFields() {
2250
+ return ['id'];
2251
+ }
2252
+ }
2253
+
2170
2254
  class CheckoutSubscription extends BaseModel {
2171
2255
  static get identifiersFields() {
2172
2256
  return ['id'];
@@ -2203,6 +2287,12 @@ class RoundProductPricesHelper {
2203
2287
  }
2204
2288
  }
2205
2289
 
2290
+ class LogDocument extends BaseModel {
2291
+ static get identifiersFields() {
2292
+ return ['id'];
2293
+ }
2294
+ }
2295
+
2206
2296
  exports.FilterType = void 0;
2207
2297
  (function (FilterType) {
2208
2298
  FilterType["ACCESSORY_IMPORTANCE"] = "accessoryImportance";
@@ -2501,8 +2591,6 @@ class ProductsIndex {
2501
2591
  'rate',
2502
2592
  ];
2503
2593
  const filter = [{ term: { published: true } }];
2504
- if (shop && shop !== exports.Shops.ALL)
2505
- filter.push({ term: { tags: shop == exports.Shops.GLAMSHOP ? 'feminino' : 'masculino' } });
2506
2594
  if (size > 9)
2507
2595
  fields.push(...['pricePaid', 'isGift', 'stock', 'weight', 'tags']);
2508
2596
  const query = {
@@ -2558,7 +2646,9 @@ class ProductsIndex {
2558
2646
  RoundProductPricesHelper.roundProductPrices(hit._source);
2559
2647
  return hit;
2560
2648
  });
2561
- return search;
2649
+ return search.hits.map((hit) => {
2650
+ return Object.assign(Object.assign({}, hit._source), { stock: hit._source.stock.quantity });
2651
+ });
2562
2652
  }
2563
2653
  async save(product) {
2564
2654
  try {
@@ -2992,6 +3082,8 @@ const withUpdateFirestore = (MixinBase) => {
2992
3082
  try {
2993
3083
  const identifiers = getValueFromParams(data, keyField);
2994
3084
  const docRef = this.collection(collectionName).getDoc(identifiers.toString());
3085
+ if (!(await docRef.get()).data())
3086
+ throw new NotFoundError(`Document '${collectionName}/${Object.values(identifiers.toString())}' not found`);
2995
3087
  const plainFromData = this.model.toInstance(this.paramsToPlain(data));
2996
3088
  const intercepted = await ((_b = (_a = this.interceptors) === null || _a === void 0 ? void 0 : _a.request) === null || _b === void 0 ? void 0 : _b.call(_a, { instance: plainFromData }));
2997
3089
  const builded = (intercepted === null || intercepted === void 0 ? void 0 : intercepted.instance) || plainFromData;
@@ -3068,275 +3160,101 @@ const withCrudFirestore = (MixinBase) => {
3068
3160
  };
3069
3161
  };
3070
3162
 
3071
- class LeadFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3163
+ class CategoryFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3072
3164
  constructor({ firestore, interceptors }) {
3073
3165
  super({
3074
3166
  firestore,
3075
- collectionName: 'leads',
3076
- model: Lead,
3167
+ collectionName: 'categories',
3168
+ model: Category,
3077
3169
  interceptors,
3078
3170
  });
3079
3171
  }
3080
- }
3081
-
3082
- class SubscriptionEditionFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
3083
- constructor({ firestore, interceptors }, parentRepository) {
3084
- super({
3085
- firestore,
3086
- collectionName: 'editions',
3087
- parentIdField: 'subscriptionId',
3088
- model: Edition,
3089
- interceptors,
3090
- });
3091
- this.parentRepository = parentRepository;
3172
+ async getCategoryBySlug(slug, shop) {
3173
+ const categoryDocs = await this.collection(this.collectionName)
3174
+ .where('slug', '==', slug)
3175
+ .where('shop', '==', shop)
3176
+ .where('published', '==', true)
3177
+ .getDocs();
3178
+ if (categoryDocs.size > 1)
3179
+ throw new DuplicatedResultsError('Query returned duplicated values');
3180
+ if (categoryDocs.empty)
3181
+ throw new NotFoundError(`Document with slug ${slug} not found`);
3182
+ return categoryDocs.docs[0].data();
3092
3183
  }
3093
- }
3094
-
3095
- class SubscriptionFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3096
- constructor({ firestore, interceptors, }) {
3097
- super({
3098
- firestore,
3099
- collectionName: 'subscription',
3100
- model: Subscription,
3101
- interceptors,
3102
- });
3184
+ async getCategoriesForHome(categoryIds, shop, limit = 4) {
3185
+ const categorySnap = await this.collection(this.collectionName)
3186
+ .where('id', 'in', categoryIds.filter(Boolean))
3187
+ .where('published', '==', true)
3188
+ .getDocs();
3189
+ if (categorySnap.empty)
3190
+ throw new NotFoundError('Categories not found');
3191
+ const categories = categorySnap.docs.map((doc) => doc.data());
3192
+ const homeSections = await Promise.all(categories.map(async (category) => ({
3193
+ category,
3194
+ products: await this.mountCategory(category, shop, { limit, hasStock: true }),
3195
+ })));
3196
+ return homeSections;
3197
+ }
3198
+ async mountCategory(category, shop, options) {
3199
+ if (!category.products)
3200
+ throw new RequiredArgumentError(['Category products is empty']);
3201
+ const chunks = lodash.chunk(category.products, 10);
3202
+ const products = [];
3203
+ const wheres = [];
3204
+ for (const productIds of chunks) {
3205
+ if ((options === null || options === void 0 ? void 0 : options.limit) && products.length >= (options === null || options === void 0 ? void 0 : options.limit))
3206
+ break;
3207
+ wheres.push(['published', '==', true], ['id', 'in', productIds]);
3208
+ if (options === null || options === void 0 ? void 0 : options.hasStock)
3209
+ wheres.push(['stock.quantity', '>', 0]);
3210
+ if (options === null || options === void 0 ? void 0 : options.gender)
3211
+ wheres.push(['tags', 'array-contains', options === null || options === void 0 ? void 0 : options.gender]);
3212
+ const productSnap = await wheres
3213
+ .reduce((collection, where) => collection.where(...where), (options === null || options === void 0 ? void 0 : options.limit)
3214
+ ? this.collection('productsErpVitrine').limit(options.limit)
3215
+ : this.collection('productsErpVitrine'))
3216
+ .getDocs();
3217
+ if (productSnap.empty)
3218
+ continue;
3219
+ products.push(...productSnap.docs);
3220
+ }
3221
+ return is(products);
3222
+ }
3223
+ getCategoryByShop(shop) {
3224
+ return;
3225
+ }
3226
+ getChildren(parentId) {
3227
+ return;
3228
+ }
3229
+ isChild(id, parentId) {
3230
+ return;
3103
3231
  }
3104
3232
  }
3233
+ tslib.__decorate([
3234
+ Log(),
3235
+ tslib.__metadata("design:type", Function),
3236
+ tslib.__metadata("design:paramtypes", [String, String]),
3237
+ tslib.__metadata("design:returntype", Promise)
3238
+ ], CategoryFirestoreRepository.prototype, "getCategoryBySlug", null);
3239
+ tslib.__decorate([
3240
+ Log(),
3241
+ tslib.__metadata("design:type", Function),
3242
+ tslib.__metadata("design:paramtypes", [Array, String, Object]),
3243
+ tslib.__metadata("design:returntype", Promise)
3244
+ ], CategoryFirestoreRepository.prototype, "getCategoriesForHome", null);
3245
+ tslib.__decorate([
3246
+ Log(),
3247
+ tslib.__metadata("design:type", Function),
3248
+ tslib.__metadata("design:paramtypes", [Category, String, Object]),
3249
+ tslib.__metadata("design:returntype", Promise)
3250
+ ], CategoryFirestoreRepository.prototype, "mountCategory", null);
3105
3251
 
3106
- class SubscriptionMaterializationFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3252
+ class ProductFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3107
3253
  constructor({ firestore, interceptors }) {
3108
3254
  super({
3109
3255
  firestore,
3110
- collectionName: 'subscriptionMaterialization',
3111
- model: SubscriptionMaterialization,
3112
- interceptors,
3113
- });
3114
- }
3115
- }
3116
-
3117
- class SubscriptionPaymentFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
3118
- constructor({ firestore, interceptors }, parentRepository) {
3119
- super({
3120
- firestore,
3121
- collectionName: 'payments',
3122
- parentIdField: 'subscriptionId',
3123
- model: SubscriptionPayment,
3124
- interceptors,
3125
- });
3126
- this.parentRepository = parentRepository;
3127
- }
3128
- }
3129
-
3130
- class SubscriptionSummaryFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3131
- constructor({ firestore, interceptors, }) {
3132
- super({
3133
- firestore,
3134
- collectionName: 'subscriptionSummary',
3135
- model: SubscriptionSummary,
3136
- interceptors,
3137
- });
3138
- }
3139
- }
3140
-
3141
- class UserAddressFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
3142
- constructor({ firestore, interceptors }, parentRepository) {
3143
- super({
3144
- firestore,
3145
- collectionName: 'address',
3146
- parentIdField: 'userId',
3147
- model: UserAddress,
3148
- interceptors,
3149
- });
3150
- this.parentRepository = parentRepository;
3151
- }
3152
- }
3153
-
3154
- class UserBeautyProfileFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
3155
- constructor({ firestore, interceptors }, parentRepository) {
3156
- super({
3157
- firestore,
3158
- collectionName: 'CX',
3159
- parentIdField: 'userId',
3160
- model: BeautyProfile,
3161
- interceptors,
3162
- });
3163
- this.parentRepository = parentRepository;
3164
- }
3165
- }
3166
-
3167
- class UserFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3168
- constructor({ firestore, interceptors }) {
3169
- super({
3170
- firestore,
3171
- collectionName: 'users',
3172
- model: User,
3173
- interceptors,
3174
- });
3175
- }
3176
- async get(identifiers) {
3177
- const user = await super.get({ id: identifiers.id });
3178
- user.beautyProfile = await this.getBeautyProfile(user.id);
3179
- user.isSubscriber = await this.checkIfIsSubscriber(user.id);
3180
- return user;
3181
- }
3182
- async checkIfExistsByField(field, value) {
3183
- const result = await this.find({ filters: { [field]: value } });
3184
- return result.count > 0;
3185
- }
3186
- buildModelInstance() {
3187
- const { fromFirestore, toFirestore } = super.buildModelInstance();
3188
- return {
3189
- toFirestore: (data) => {
3190
- const plain = toFirestore(data);
3191
- delete plain.isSubscriber;
3192
- return plain;
3193
- },
3194
- fromFirestore,
3195
- };
3196
- }
3197
- async getBeautyProfile(userId) {
3198
- const beautyProfile = await this.firestore
3199
- .getCollection(`${this.collectionName}/${userId}/CX`)
3200
- .withConverter(this.buildBeautyProfileModelInstance())
3201
- .getDoc('beautyProfile')
3202
- .get();
3203
- return beautyProfile.data();
3204
- }
3205
- async checkIfIsSubscriber(userId) {
3206
- const docs = await this.collection('subscription')
3207
- .where('user.id', '==', userId)
3208
- .where('status', '==', 'active')
3209
- .getDocs();
3210
- return !!docs && !!docs.size;
3211
- }
3212
- buildBeautyProfileModelInstance() {
3213
- return {
3214
- toFirestore: (data) => data.toPlain(),
3215
- fromFirestore: (snap) => BeautyProfile.toInstance(snap.data()),
3216
- };
3217
- }
3218
- }
3219
- tslib.__decorate([
3220
- Log(),
3221
- tslib.__metadata("design:type", Function),
3222
- tslib.__metadata("design:paramtypes", [Object]),
3223
- tslib.__metadata("design:returntype", Promise)
3224
- ], UserFirestoreRepository.prototype, "get", null);
3225
- tslib.__decorate([
3226
- Log(),
3227
- tslib.__metadata("design:type", Function),
3228
- tslib.__metadata("design:paramtypes", [String, String]),
3229
- tslib.__metadata("design:returntype", Promise)
3230
- ], UserFirestoreRepository.prototype, "checkIfExistsByField", null);
3231
-
3232
- class UserPaymentMethodFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
3233
- constructor({ firestore, interceptors }, parentRepository) {
3234
- super({
3235
- firestore,
3236
- collectionName: 'payment_method',
3237
- parentIdField: 'userId',
3238
- model: UserPaymentMethod,
3239
- interceptors,
3240
- });
3241
- this.parentRepository = parentRepository;
3242
- }
3243
- }
3244
-
3245
- class CategoryFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3246
- constructor({ firestore, interceptors }) {
3247
- super({
3248
- firestore,
3249
- collectionName: 'categories',
3250
- model: Category,
3251
- interceptors,
3252
- });
3253
- }
3254
- async getCategoryBySlug(slug, shop) {
3255
- const categoryDocs = await this.collection(this.collectionName)
3256
- .where('slug', '==', slug)
3257
- .where('shop', '==', shop)
3258
- .where('published', '==', true)
3259
- .getDocs();
3260
- if (categoryDocs.size > 1)
3261
- throw new DuplicatedResultsError('Query returned duplicated values');
3262
- if (categoryDocs.empty)
3263
- throw new NotFoundError(`Document with slug ${slug} not found`);
3264
- return categoryDocs.docs[0].data();
3265
- }
3266
- async getCategoriesForHome(categoryIds, limit = 4, gender) {
3267
- const categorySnap = await this.collection(this.collectionName)
3268
- .where('id', 'in', categoryIds.filter(Boolean))
3269
- .where('published', '==', true)
3270
- .getDocs();
3271
- if (categorySnap.empty)
3272
- throw new NotFoundError('Categories not found');
3273
- const categories = categorySnap.docs.map((doc) => doc.data());
3274
- const homeSections = await Promise.all(categories.map(async (category) => ({
3275
- category,
3276
- products: await this.mountCategory(category, { limit, hasStock: true, gender }),
3277
- })));
3278
- return homeSections;
3279
- }
3280
- async mountCategory(category, options) {
3281
- if (!category.products)
3282
- throw new RequiredArgumentError(['Category products is empty']);
3283
- const chunks = lodash.chunk(category.products, 10);
3284
- const products = [];
3285
- const wheres = [];
3286
- for (const productIds of chunks) {
3287
- if ((options === null || options === void 0 ? void 0 : options.limit) && products.length >= (options === null || options === void 0 ? void 0 : options.limit))
3288
- break;
3289
- wheres.push(['published', '==', true], ['id', 'in', productIds]);
3290
- if (options === null || options === void 0 ? void 0 : options.hasStock)
3291
- wheres.push(['stock.quantity', '>', 0]);
3292
- if (options === null || options === void 0 ? void 0 : options.gender)
3293
- wheres.push(['tags', 'array-contains', options === null || options === void 0 ? void 0 : options.gender]);
3294
- const productSnap = await wheres
3295
- .reduce((collection, where) => collection.where(...where), (options === null || options === void 0 ? void 0 : options.limit)
3296
- ? this.collection('productsErpVitrine').limit(options.limit)
3297
- : this.collection('productsErpVitrine'))
3298
- .getDocs();
3299
- if (productSnap.empty)
3300
- continue;
3301
- products.push(...productSnap.docs);
3302
- }
3303
- return is(products);
3304
- }
3305
- getCategoryByShop(shop) {
3306
- return;
3307
- }
3308
- getChildren(parentId) {
3309
- return;
3310
- }
3311
- isChild(id, parentId) {
3312
- return;
3313
- }
3314
- }
3315
- tslib.__decorate([
3316
- Log(),
3317
- tslib.__metadata("design:type", Function),
3318
- tslib.__metadata("design:paramtypes", [String, String]),
3319
- tslib.__metadata("design:returntype", Promise)
3320
- ], CategoryFirestoreRepository.prototype, "getCategoryBySlug", null);
3321
- tslib.__decorate([
3322
- Log(),
3323
- tslib.__metadata("design:type", Function),
3324
- tslib.__metadata("design:paramtypes", [Array, Object, String]),
3325
- tslib.__metadata("design:returntype", Promise)
3326
- ], CategoryFirestoreRepository.prototype, "getCategoriesForHome", null);
3327
- tslib.__decorate([
3328
- Log(),
3329
- tslib.__metadata("design:type", Function),
3330
- tslib.__metadata("design:paramtypes", [Category, Object]),
3331
- tslib.__metadata("design:returntype", Promise)
3332
- ], CategoryFirestoreRepository.prototype, "mountCategory", null);
3333
-
3334
- class ProductFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3335
- constructor({ firestore, interceptors }) {
3336
- super({
3337
- firestore,
3338
- collectionName: 'productsErpVitrine',
3339
- model: Product,
3256
+ collectionName: 'productsErpVitrine',
3257
+ model: Product,
3340
3258
  interceptors,
3341
3259
  });
3342
3260
  this.reviews = {};
@@ -3426,6 +3344,101 @@ class SubscriptionProductFirestoreRepository extends withCrudFirestore(withHelpe
3426
3344
  }
3427
3345
  }
3428
3346
 
3347
+ class LogFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3348
+ constructor({ firestore, interceptors, }) {
3349
+ super({
3350
+ firestore,
3351
+ collectionName: 'logs',
3352
+ model: LogDocument,
3353
+ interceptors,
3354
+ });
3355
+ }
3356
+ }
3357
+
3358
+ class HomeFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3359
+ constructor({ firestore, interceptors }) {
3360
+ super({
3361
+ firestore,
3362
+ collectionName: 'dms',
3363
+ model: Home,
3364
+ interceptors,
3365
+ });
3366
+ this.homeCategoryGroupToPlain = (homeCategoryGroup) => {
3367
+ var _a, _b, _c;
3368
+ return ({
3369
+ category: ((_a = homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.category) === null || _a === void 0 ? void 0 : _a.toPlain)
3370
+ ? (_b = homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.category) === null || _b === void 0 ? void 0 : _b.toPlain()
3371
+ : homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.category,
3372
+ products: ((_c = homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.products) === null || _c === void 0 ? void 0 : _c.map((product) => ((product === null || product === void 0 ? void 0 : product.toPlain) ? product === null || product === void 0 ? void 0 : product.toPlain() : product)).filter(Boolean)) || [],
3373
+ });
3374
+ };
3375
+ this.plainToHomeCategoryGroup = (homeCategoryGroup) => {
3376
+ var _a;
3377
+ return ({
3378
+ category: Category.toInstance(homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.category),
3379
+ products: (_a = homeCategoryGroup.products) === null || _a === void 0 ? void 0 : _a.map((product) => Product.toInstance(product)),
3380
+ });
3381
+ };
3382
+ }
3383
+ buildModelInstance() {
3384
+ const { fromFirestore, toFirestore } = super.buildModelInstance();
3385
+ return {
3386
+ toFirestore: (data) => {
3387
+ const modifiedData = this.homeToFirestore(data);
3388
+ return toFirestore(modifiedData);
3389
+ },
3390
+ fromFirestore: (snap) => {
3391
+ const instance = fromFirestore(snap);
3392
+ return this.homeFromFirestore(instance);
3393
+ },
3394
+ };
3395
+ }
3396
+ homeToFirestore(home) {
3397
+ var _a, _b, _c, _d;
3398
+ if ((_a = home.data) === null || _a === void 0 ? void 0 : _a.data) {
3399
+ home.data.data.discoverProducts = ((_b = home.data.data.discoverProducts) === null || _b === void 0 ? void 0 : _b.map(this.homeCategoryGroupToPlain)) || [];
3400
+ home.data.data.featuredProducts = ((_c = home.data.data.featuredProducts) === null || _c === void 0 ? void 0 : _c.map(this.homeCategoryGroupToPlain)) || [];
3401
+ home.data.data.verticalProducts = ((_d = home.data.data.verticalProducts) === null || _d === void 0 ? void 0 : _d.map(this.homeCategoryGroupToPlain)) || [];
3402
+ }
3403
+ return home;
3404
+ }
3405
+ homeFromFirestore(home) {
3406
+ var _a;
3407
+ if ((_a = home.data) === null || _a === void 0 ? void 0 : _a.data) {
3408
+ home.data.data.discoverProducts = home.data.data.discoverProducts.map(this.plainToHomeCategoryGroup);
3409
+ home.data.data.featuredProducts = home.data.data.featuredProducts.map(this.plainToHomeCategoryGroup);
3410
+ home.data.data.verticalProducts = home.data.data.verticalProducts.map(this.plainToHomeCategoryGroup);
3411
+ home.data.createdAt =
3412
+ home.data.createdAt instanceof firestore.Timestamp ? home.data.createdAt.toDate() : home.data.createdAt;
3413
+ home.data.expiresAt =
3414
+ home.data.expiresAt instanceof firestore.Timestamp ? home.data.expiresAt.toDate() : home.data.expiresAt;
3415
+ }
3416
+ return home;
3417
+ }
3418
+ }
3419
+
3420
+ class ShopMenuFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3421
+ constructor({ firestore, interceptors }) {
3422
+ super({
3423
+ firestore,
3424
+ collectionName: 'shopMenus',
3425
+ model: ShopMenu,
3426
+ interceptors,
3427
+ });
3428
+ }
3429
+ }
3430
+
3431
+ class ShopSettingsFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3432
+ constructor({ firestore, interceptors, }) {
3433
+ super({
3434
+ firestore,
3435
+ collectionName: 'shopSettings',
3436
+ model: ShopSettings,
3437
+ interceptors,
3438
+ });
3439
+ }
3440
+ }
3441
+
3429
3442
  class Buy2WinFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3430
3443
  constructor({ firestore, interceptors }) {
3431
3444
  super({
@@ -3509,156 +3522,287 @@ class CouponFirestoreRepository extends withCrudFirestore(withHelpers(withFirest
3509
3522
  }
3510
3523
  }
3511
3524
 
3512
- class OrderFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3513
- constructor({ firestore, interceptors }) {
3525
+ class OrderFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3526
+ constructor({ firestore, interceptors }) {
3527
+ super({
3528
+ firestore,
3529
+ collectionName: 'orders',
3530
+ model: Order,
3531
+ interceptors,
3532
+ fields: {
3533
+ status: FirestoreFieldType.String,
3534
+ },
3535
+ });
3536
+ this.orderFromFirestore = (order) => {
3537
+ var _a;
3538
+ if (!!((_a = order === null || order === void 0 ? void 0 : order.lineItems) === null || _a === void 0 ? void 0 : _a.length)) {
3539
+ order.lineItems = order.lineItems.map((lineItem) => {
3540
+ const prices = !!lineItem.price;
3541
+ const shopPrice = prices[order.shop];
3542
+ if (!!shopPrice)
3543
+ lineItem.price = shopPrice;
3544
+ return lineItem;
3545
+ });
3546
+ }
3547
+ return order;
3548
+ };
3549
+ }
3550
+ buildModelInstance() {
3551
+ const { fromFirestore, toFirestore } = super.buildModelInstance();
3552
+ return {
3553
+ toFirestore: (data) => toFirestore((data === null || data === void 0 ? void 0 : data.toPlain) ? data.toPlain() : data),
3554
+ fromFirestore: (snap) => {
3555
+ const instance = fromFirestore(snap);
3556
+ return this.orderFromFirestore(instance);
3557
+ },
3558
+ };
3559
+ }
3560
+ }
3561
+
3562
+ class LegacyOrderFirestoreRepository extends OrderFirestoreRepository {
3563
+ constructor({ firestore, interceptors }) {
3564
+ super({
3565
+ firestore,
3566
+ interceptors,
3567
+ });
3568
+ this.collectionName = 'legacyOrders';
3569
+ }
3570
+ }
3571
+
3572
+ class OrderBlockedFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3573
+ constructor({ firestore, interceptors, }) {
3574
+ super({
3575
+ firestore,
3576
+ collectionName: 'paymentBlockedAttempts',
3577
+ model: OrderBlocked,
3578
+ interceptors,
3579
+ });
3580
+ }
3581
+ async createBlockedOrderOrPayment(checkout, blockType, type, limiteRange, card = null) {
3582
+ var _a, _b, _c, _d, _e, _f, _g, _h;
3583
+ return this.create(OrderBlocked.toInstance({
3584
+ customer: {
3585
+ name: ((_a = checkout.user) === null || _a === void 0 ? void 0 : _a.displayName) || '',
3586
+ cpf: ((_b = checkout.user) === null || _b === void 0 ? void 0 : _b.cpf) || '',
3587
+ id: (_c = checkout.user) === null || _c === void 0 ? void 0 : _c.id,
3588
+ email: ((_d = checkout.user) === null || _d === void 0 ? void 0 : _d.email) || '',
3589
+ phoneNumber: '+55' + ((_e = checkout.user) === null || _e === void 0 ? void 0 : _e.phone),
3590
+ isSubscriber: (_f = checkout.user) === null || _f === void 0 ? void 0 : _f.isSubscriber,
3591
+ subscriptionPlan: ((_g = checkout.user) === null || _g === void 0 ? void 0 : _g.subscriptionPlan) || '',
3592
+ shippingAddress: Object.assign(Object.assign({}, checkout.shippingAddress), { zip: this.formatZip((_h = checkout.shippingAddress) === null || _h === void 0 ? void 0 : _h.zip) }),
3593
+ },
3594
+ blockType,
3595
+ limiteRange,
3596
+ type,
3597
+ card,
3598
+ checkout: {
3599
+ id: checkout.id,
3600
+ shop: checkout.shop,
3601
+ total: checkout.totalPrice,
3602
+ },
3603
+ date: new Date(),
3604
+ }));
3605
+ }
3606
+ formatZip(zip) {
3607
+ if (zip.length === 8)
3608
+ return zip.substring(0, 5) + '-' + zip.substring(5, 8);
3609
+ return zip;
3610
+ }
3611
+ }
3612
+
3613
+ class PaymentFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3614
+ constructor({ firestore, interceptors }) {
3615
+ super({
3616
+ firestore,
3617
+ collectionName: 'payments',
3618
+ model: Payment,
3619
+ interceptors,
3620
+ });
3621
+ }
3622
+ }
3623
+
3624
+ class SubscriptionPlanFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3625
+ constructor({ firestore, interceptors, }) {
3626
+ super({
3627
+ firestore,
3628
+ collectionName: 'subscriptionPlans',
3629
+ model: SubscriptionPlan,
3630
+ interceptors,
3631
+ });
3632
+ }
3633
+ }
3634
+
3635
+ class LeadFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3636
+ constructor({ firestore, interceptors }) {
3637
+ super({
3638
+ firestore,
3639
+ collectionName: 'leads',
3640
+ model: Lead,
3641
+ interceptors,
3642
+ });
3643
+ }
3644
+ }
3645
+
3646
+ class SubscriptionEditionFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
3647
+ constructor({ firestore, interceptors }, parentRepository) {
3648
+ super({
3649
+ firestore,
3650
+ collectionName: 'editions',
3651
+ parentIdField: 'subscriptionId',
3652
+ model: Edition,
3653
+ interceptors,
3654
+ });
3655
+ this.parentRepository = parentRepository;
3656
+ }
3657
+ }
3658
+
3659
+ class SubscriptionFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3660
+ constructor({ firestore, interceptors, }) {
3661
+ super({
3662
+ firestore,
3663
+ collectionName: 'subscription',
3664
+ model: Subscription,
3665
+ interceptors,
3666
+ });
3667
+ }
3668
+ }
3669
+
3670
+ class SubscriptionMaterializationFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3671
+ constructor({ firestore, interceptors }) {
3672
+ super({
3673
+ firestore,
3674
+ collectionName: 'subscriptionMaterialization',
3675
+ model: SubscriptionMaterialization,
3676
+ interceptors,
3677
+ });
3678
+ }
3679
+ }
3680
+
3681
+ class SubscriptionPaymentFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
3682
+ constructor({ firestore, interceptors }, parentRepository) {
3514
3683
  super({
3515
3684
  firestore,
3516
- collectionName: 'orders',
3517
- model: Order,
3685
+ collectionName: 'payments',
3686
+ parentIdField: 'subscriptionId',
3687
+ model: SubscriptionPayment,
3518
3688
  interceptors,
3519
- fields: {
3520
- status: FirestoreFieldType.String,
3521
- },
3522
3689
  });
3523
- this.orderFromFirestore = (order) => {
3524
- var _a;
3525
- if (!!((_a = order === null || order === void 0 ? void 0 : order.lineItems) === null || _a === void 0 ? void 0 : _a.length)) {
3526
- order.lineItems = order.lineItems.map((lineItem) => {
3527
- const prices = !!lineItem.price;
3528
- const shopPrice = prices[order.shop];
3529
- if (!!shopPrice)
3530
- lineItem.price = shopPrice;
3531
- return lineItem;
3532
- });
3533
- }
3534
- return order;
3535
- };
3536
- }
3537
- buildModelInstance() {
3538
- const { fromFirestore, toFirestore } = super.buildModelInstance();
3539
- return {
3540
- toFirestore: (data) => toFirestore((data === null || data === void 0 ? void 0 : data.toPlain) ? data.toPlain() : data),
3541
- fromFirestore: (snap) => {
3542
- const instance = fromFirestore(snap);
3543
- return this.orderFromFirestore(instance);
3544
- },
3545
- };
3690
+ this.parentRepository = parentRepository;
3546
3691
  }
3547
3692
  }
3548
3693
 
3549
- class LegacyOrderFirestoreRepository extends OrderFirestoreRepository {
3550
- constructor({ firestore, interceptors }) {
3694
+ class SubscriptionSummaryFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3695
+ constructor({ firestore, interceptors, }) {
3551
3696
  super({
3552
3697
  firestore,
3698
+ collectionName: 'subscriptionSummary',
3699
+ model: SubscriptionSummary,
3553
3700
  interceptors,
3554
3701
  });
3555
- this.collectionName = 'legacyOrders';
3556
3702
  }
3557
3703
  }
3558
3704
 
3559
- class PaymentFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3560
- constructor({ firestore, interceptors }) {
3705
+ class UserAddressFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
3706
+ constructor({ firestore, interceptors }, parentRepository) {
3561
3707
  super({
3562
3708
  firestore,
3563
- collectionName: 'payments',
3564
- model: Payment,
3709
+ collectionName: 'address',
3710
+ parentIdField: 'userId',
3711
+ model: UserAddress,
3565
3712
  interceptors,
3566
3713
  });
3714
+ this.parentRepository = parentRepository;
3567
3715
  }
3568
3716
  }
3569
3717
 
3570
- class SubscriptionPlanFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3571
- constructor({ firestore, interceptors, }) {
3718
+ class UserBeautyProfileFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
3719
+ constructor({ firestore, interceptors }, parentRepository) {
3572
3720
  super({
3573
3721
  firestore,
3574
- collectionName: 'subscriptionPlans',
3575
- model: SubscriptionPlan,
3722
+ collectionName: 'CX',
3723
+ parentIdField: 'userId',
3724
+ model: BeautyProfile,
3576
3725
  interceptors,
3577
3726
  });
3727
+ this.parentRepository = parentRepository;
3578
3728
  }
3579
3729
  }
3580
3730
 
3581
- class HomeFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3731
+ class UserFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3582
3732
  constructor({ firestore, interceptors }) {
3583
3733
  super({
3584
3734
  firestore,
3585
- collectionName: 'dms',
3586
- model: Home,
3735
+ collectionName: 'users',
3736
+ model: User,
3587
3737
  interceptors,
3588
3738
  });
3589
- this.homeCategoryGroupToPlain = (homeCategoryGroup) => {
3590
- var _a, _b, _c;
3591
- return ({
3592
- category: ((_a = homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.category) === null || _a === void 0 ? void 0 : _a.toPlain)
3593
- ? (_b = homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.category) === null || _b === void 0 ? void 0 : _b.toPlain()
3594
- : homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.category,
3595
- products: ((_c = homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.products) === null || _c === void 0 ? void 0 : _c.map((product) => ((product === null || product === void 0 ? void 0 : product.toPlain) ? product === null || product === void 0 ? void 0 : product.toPlain() : product)).filter(Boolean)) || [],
3596
- });
3597
- };
3598
- this.plainToHomeCategoryGroup = (homeCategoryGroup) => {
3599
- var _a;
3600
- return ({
3601
- category: Category.toInstance(homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.category),
3602
- products: (_a = homeCategoryGroup.products) === null || _a === void 0 ? void 0 : _a.map((product) => Product.toInstance(product)),
3603
- });
3604
- };
3739
+ }
3740
+ async get(identifiers) {
3741
+ const user = await super.get({ id: identifiers.id });
3742
+ user.beautyProfile = await this.getBeautyProfile(user.id);
3743
+ user.isSubscriber = await this.checkIfIsSubscriber(user.id);
3744
+ return user;
3745
+ }
3746
+ async checkIfExistsByField(field, value) {
3747
+ const result = await this.find({ filters: { [field]: value } });
3748
+ return result.count > 0;
3605
3749
  }
3606
3750
  buildModelInstance() {
3607
3751
  const { fromFirestore, toFirestore } = super.buildModelInstance();
3608
3752
  return {
3609
3753
  toFirestore: (data) => {
3610
- const modifiedData = this.homeToFirestore(data);
3611
- return toFirestore(modifiedData);
3612
- },
3613
- fromFirestore: (snap) => {
3614
- const instance = fromFirestore(snap);
3615
- return this.homeFromFirestore(instance);
3754
+ const plain = toFirestore(data);
3755
+ delete plain.isSubscriber;
3756
+ return plain;
3616
3757
  },
3758
+ fromFirestore,
3617
3759
  };
3618
3760
  }
3619
- homeToFirestore(home) {
3620
- var _a, _b, _c, _d;
3621
- if ((_a = home.data) === null || _a === void 0 ? void 0 : _a.data) {
3622
- home.data.data.discoverProducts = ((_b = home.data.data.discoverProducts) === null || _b === void 0 ? void 0 : _b.map(this.homeCategoryGroupToPlain)) || [];
3623
- home.data.data.featuredProducts = ((_c = home.data.data.featuredProducts) === null || _c === void 0 ? void 0 : _c.map(this.homeCategoryGroupToPlain)) || [];
3624
- home.data.data.verticalProducts = ((_d = home.data.data.verticalProducts) === null || _d === void 0 ? void 0 : _d.map(this.homeCategoryGroupToPlain)) || [];
3625
- }
3626
- return home;
3761
+ async getBeautyProfile(userId) {
3762
+ const beautyProfile = await this.firestore
3763
+ .getCollection(`${this.collectionName}/${userId}/CX`)
3764
+ .withConverter(this.buildBeautyProfileModelInstance())
3765
+ .getDoc('beautyProfile')
3766
+ .get();
3767
+ return beautyProfile.data();
3627
3768
  }
3628
- homeFromFirestore(home) {
3629
- var _a;
3630
- if ((_a = home.data) === null || _a === void 0 ? void 0 : _a.data) {
3631
- home.data.data.discoverProducts = home.data.data.discoverProducts.map(this.plainToHomeCategoryGroup);
3632
- home.data.data.featuredProducts = home.data.data.featuredProducts.map(this.plainToHomeCategoryGroup);
3633
- home.data.data.verticalProducts = home.data.data.verticalProducts.map(this.plainToHomeCategoryGroup);
3634
- home.data.createdAt =
3635
- home.data.createdAt instanceof firestore.Timestamp ? home.data.createdAt.toDate() : home.data.createdAt;
3636
- home.data.expiresAt =
3637
- home.data.expiresAt instanceof firestore.Timestamp ? home.data.expiresAt.toDate() : home.data.expiresAt;
3638
- }
3639
- return home;
3769
+ async checkIfIsSubscriber(userId) {
3770
+ const docs = await this.collection('subscription')
3771
+ .where('user.id', '==', userId)
3772
+ .where('status', '==', 'active')
3773
+ .getDocs();
3774
+ return !!docs && !!docs.size;
3640
3775
  }
3641
- }
3642
-
3643
- class ShopMenuFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3644
- constructor({ firestore, interceptors }) {
3645
- super({
3646
- firestore,
3647
- collectionName: 'shopMenus',
3648
- model: ShopMenu,
3649
- interceptors,
3650
- });
3776
+ buildBeautyProfileModelInstance() {
3777
+ return {
3778
+ toFirestore: (data) => data.toPlain(),
3779
+ fromFirestore: (snap) => BeautyProfile.toInstance(snap.data()),
3780
+ };
3651
3781
  }
3652
3782
  }
3783
+ tslib.__decorate([
3784
+ Log(),
3785
+ tslib.__metadata("design:type", Function),
3786
+ tslib.__metadata("design:paramtypes", [Object]),
3787
+ tslib.__metadata("design:returntype", Promise)
3788
+ ], UserFirestoreRepository.prototype, "get", null);
3789
+ tslib.__decorate([
3790
+ Log(),
3791
+ tslib.__metadata("design:type", Function),
3792
+ tslib.__metadata("design:paramtypes", [String, String]),
3793
+ tslib.__metadata("design:returntype", Promise)
3794
+ ], UserFirestoreRepository.prototype, "checkIfExistsByField", null);
3653
3795
 
3654
- class ShopSettingsFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3655
- constructor({ firestore, interceptors, }) {
3796
+ class UserPaymentMethodFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
3797
+ constructor({ firestore, interceptors }, parentRepository) {
3656
3798
  super({
3657
3799
  firestore,
3658
- collectionName: 'shopSettings',
3659
- model: ShopSettings,
3800
+ collectionName: 'payment_method',
3801
+ parentIdField: 'userId',
3802
+ model: UserPaymentMethod,
3660
3803
  interceptors,
3661
3804
  });
3805
+ this.parentRepository = parentRepository;
3662
3806
  }
3663
3807
  }
3664
3808
 
@@ -4211,7 +4355,7 @@ const withHasuraGraphQL = (MixinBase) => {
4211
4355
  const response = await axios__default["default"](request);
4212
4356
  if (!lodash.isNil(response.data.errors)) {
4213
4357
  this.logger.error({ req: request, res: response.data.errors });
4214
- throw new Error(response.data.errors);
4358
+ throw new Error(JSON.stringify(response.data.errors));
4215
4359
  }
4216
4360
  this.logger.log({ req: request, res: response.data });
4217
4361
  return response.data.data;
@@ -4352,6 +4496,7 @@ const withFindHasuraGraphQL = (MixinBase) => {
4352
4496
  return class FindHasuraGraphQLMixin extends MixinBase {
4353
4497
  constructor() {
4354
4498
  super(...arguments);
4499
+ this.lastDistinct = {};
4355
4500
  this.bindOrderByAttributes = (orderBy, fields) => Object.keys(orderBy).reduce((acc, current) => [
4356
4501
  ...acc,
4357
4502
  {
@@ -4387,9 +4532,10 @@ const withFindHasuraGraphQL = (MixinBase) => {
4387
4532
  });
4388
4533
  }
4389
4534
  async find(params) {
4390
- var _a, _b, _c, _d, _e, _f, _g, _h;
4535
+ var _a, _b, _c, _d, _e, _f, _g;
4391
4536
  this.logger = DebugHelper.from(this, 'find');
4392
4537
  const { filters, limits, orderBy, options } = params || {};
4538
+ const tableFiltersNamed = `${this.tableName}:${JSON.stringify(filters)}`;
4393
4539
  const enableCount = (_a = options === null || options === void 0 ? void 0 : options.enableCount) !== null && _a !== void 0 ? _a : true;
4394
4540
  const variablesFilters = lodash.isNil(filters)
4395
4541
  ? {}
@@ -4440,8 +4586,8 @@ const withFindHasuraGraphQL = (MixinBase) => {
4440
4586
  },
4441
4587
  ]
4442
4588
  : []),
4443
- ...((!((_b = params.limits) === null || _b === void 0 ? void 0 : _b.offset) &&
4444
- ((_d = (_c = params.options) === null || _c === void 0 ? void 0 : _c.distinct) === null || _d === void 0 ? void 0 : _d.map((distinct) => {
4589
+ ...((!this.lastDistinct[tableFiltersNamed] &&
4590
+ ((_c = (_b = params.options) === null || _b === void 0 ? void 0 : _b.distinct) === null || _c === void 0 ? void 0 : _c.map((distinct) => {
4445
4591
  var _a, _b;
4446
4592
  const distinctOption = (_a = this.fields.find((fieldOption) => fieldOption === distinct)) !== null && _a !== void 0 ? _a : this.fields.find((fieldOption) => Object.keys(fieldOption).shift() === distinct);
4447
4593
  const fieldName = ((_b = Object.values(distinctOption).shift()) === null || _b === void 0 ? void 0 : _b.columnName) || distinct;
@@ -4462,28 +4608,27 @@ const withFindHasuraGraphQL = (MixinBase) => {
4462
4608
  []),
4463
4609
  ]);
4464
4610
  const data = result[this.tableName].map((row) => this.convertDataFromHasura(row));
4465
- return Object.assign(Object.assign(Object.assign({ data, count: enableCount ? result[`${this.tableName}_aggregate`].aggregate.count : Infinity }, (((_e = options === null || options === void 0 ? void 0 : options.minimal) === null || _e === void 0 ? void 0 : _e.length)
4611
+ return Object.assign(Object.assign(Object.assign({ data, count: enableCount ? result[`${this.tableName}_aggregate`].aggregate.count : Infinity }, (((_d = options === null || options === void 0 ? void 0 : options.minimal) === null || _d === void 0 ? void 0 : _d.length)
4466
4612
  ? {
4467
4613
  minimal: options.minimal.reduce((minimals, current) => {
4468
4614
  var _a;
4469
4615
  return (Object.assign(Object.assign({}, minimals), lodash.set(minimals, current, result[`${this.tableName}_aggregate`].aggregate.min[((_a = AttributeOptionHelper.FindByAttribute(current.toString().split('.').pop(), this.fields)) === null || _a === void 0 ? void 0 : _a.columnName) || current])));
4470
4616
  }, {}),
4471
4617
  }
4472
- : {})), (((_f = options === null || options === void 0 ? void 0 : options.maximum) === null || _f === void 0 ? void 0 : _f.length)
4618
+ : {})), (((_e = options === null || options === void 0 ? void 0 : options.maximum) === null || _e === void 0 ? void 0 : _e.length)
4473
4619
  ? {
4474
4620
  maximum: options.maximum.reduce((maximums, current) => {
4475
4621
  var _a;
4476
4622
  return (Object.assign(Object.assign({}, maximums), lodash.set(maximums, current, result[`${this.tableName}_aggregate`].aggregate.max[((_a = AttributeOptionHelper.FindByAttribute(current.toString().split('.').pop(), this.fields)) === null || _a === void 0 ? void 0 : _a.columnName) || current])));
4477
4623
  }, {}),
4478
4624
  }
4479
- : {})), (!((_g = params.limits) === null || _g === void 0 ? void 0 : _g.offset) &&
4480
- ((_h = options === null || options === void 0 ? void 0 : options.distinct) === null || _h === void 0 ? void 0 : _h.length) && {
4481
- distinct: options === null || options === void 0 ? void 0 : options.distinct.reduce((distinct, current) => {
4625
+ : {})), (((_f = options === null || options === void 0 ? void 0 : options.distinct) === null || _f === void 0 ? void 0 : _f.length) && {
4626
+ distinct: (_g = this.lastDistinct[tableFiltersNamed]) !== null && _g !== void 0 ? _g : (this.lastDistinct[tableFiltersNamed] = options === null || options === void 0 ? void 0 : options.distinct.reduce((distinct, current) => {
4482
4627
  var _a, _b;
4483
4628
  const distinctOption = (_a = this.fields.find((fieldOption) => fieldOption === current)) !== null && _a !== void 0 ? _a : this.fields.find((fieldOption) => Object.keys(fieldOption).shift() === current);
4484
4629
  const fieldName = ((_b = Object.values(distinctOption).shift()) === null || _b === void 0 ? void 0 : _b.columnName) || current;
4485
4630
  return Object.assign(Object.assign({}, distinct), { [current.toString()]: result[`${this.tableName}_${current.toString()}_distinct`].map((obj) => obj[fieldName]) });
4486
- }, {}),
4631
+ }, {})),
4487
4632
  }));
4488
4633
  }
4489
4634
  };
@@ -4578,6 +4723,7 @@ class CategoryFilterHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHa
4578
4723
  fields: [
4579
4724
  'id',
4580
4725
  'description',
4726
+ 'title',
4581
4727
  'slug',
4582
4728
  'enabled',
4583
4729
  { createdAt: { columnName: 'created_at' } },
@@ -4689,6 +4835,7 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
4689
4835
  'name',
4690
4836
  'description',
4691
4837
  'image',
4838
+ { images: { columnName: 'images', type: HasuraGraphQLColumnType.Jsonb } },
4692
4839
  'published',
4693
4840
  'shop',
4694
4841
  { shops: { columnName: 'shops', type: HasuraGraphQLColumnType.Jsonb } },
@@ -4721,11 +4868,11 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
4721
4868
  filters: {
4722
4869
  columnName: 'filters',
4723
4870
  foreignKeyColumn: { filter_id: 'id' },
4724
- fields: [{ filter: ['id', 'description', 'slug', 'enabled'] }],
4871
+ fields: [{ filter: ['id', 'title', 'description', 'slug', 'enabled'] }],
4725
4872
  bindPersistData: (value) => ({
4726
4873
  filters: { data: value.map((filter) => ({ filter_id: filter.id })) },
4727
4874
  }),
4728
- from: (filters) => (filters === null || filters === void 0 ? void 0 : filters.map((filter) => filter === null || filter === void 0 ? void 0 : filter.filter)) || [],
4875
+ from: (filters) => (filters === null || filters === void 0 ? void 0 : filters.map((filter) => filter === null || filter === void 0 ? void 0 : filter.filter).filter((filter) => filter.enabled)) || [],
4729
4876
  },
4730
4877
  },
4731
4878
  { createdAt: { columnName: 'created_at' } },
@@ -4744,12 +4891,21 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
4744
4891
  {
4745
4892
  metadata: {
4746
4893
  columnName: 'metadata',
4747
- fields: ['title', 'description'],
4894
+ fields: ['shop', 'title', 'description'],
4748
4895
  bindPersistData: (value) => ({
4749
4896
  metadata: { data: value },
4750
4897
  }),
4751
4898
  },
4752
4899
  },
4900
+ {
4901
+ metadatas: {
4902
+ columnName: 'metadatas',
4903
+ fields: ['shop', 'title', 'description'],
4904
+ bindPersistData: (value) => ({
4905
+ metadatas: { data: value },
4906
+ }),
4907
+ },
4908
+ },
4753
4909
  { isCollection: { columnName: 'is_collection' } },
4754
4910
  { isWishlist: { columnName: 'is_wishlist' } },
4755
4911
  'reference',
@@ -4764,14 +4920,29 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
4764
4920
  'theme',
4765
4921
  { bannerUrl: { columnName: 'banner_url' } },
4766
4922
  { mostRelevant: { columnName: 'most_relevant', type: HasuraGraphQLColumnType.Jsonb } },
4923
+ { mostRelevants: { columnName: 'most_relevants', type: HasuraGraphQLColumnType.Jsonb } },
4767
4924
  ],
4768
4925
  });
4769
4926
  this.productRepository = productRepository;
4770
4927
  this.categoryFilterRepository = categoryFilterRepository;
4771
4928
  }
4772
4929
  async create(params) {
4773
- const { metadata } = params, data = tslib.__rest(params, ["metadata"]);
4774
- return super.create(Object.assign(Object.assign({}, data), { isWishlist: false, metadata: metadata || { description: null, title: null } }));
4930
+ const { images, mostRelevants, metadatas } = params, data = tslib.__rest(params, ["images", "mostRelevants", "metadatas"]);
4931
+ return super.create(Object.assign(Object.assign({}, data), { isWishlist: false, metadatas: metadatas || [{ shop: null, description: null, title: null }], mostRelevants: mostRelevants || {
4932
+ [exports.Shops.GLAMSHOP]: null,
4933
+ [exports.Shops.MENSMARKET]: null,
4934
+ }, images: images || {
4935
+ [exports.Shops.GLAMSHOP]: {
4936
+ brandBanner: null,
4937
+ brandBannerMobile: null,
4938
+ image: null,
4939
+ },
4940
+ [exports.Shops.MENSMARKET]: {
4941
+ brandBanner: null,
4942
+ brandBannerMobile: null,
4943
+ image: null,
4944
+ },
4945
+ } }));
4775
4946
  }
4776
4947
  async get(identifiers) {
4777
4948
  var _a;
@@ -4780,12 +4951,12 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
4780
4951
  : super.get(identifiers);
4781
4952
  }
4782
4953
  async update(params) {
4783
- const { products, id: checkId, metadata, filters } = params, data = tslib.__rest(params, ["products", "id", "metadata", "filters"]);
4954
+ const { products, id: checkId, metadatas, filters } = params, data = tslib.__rest(params, ["products", "id", "metadatas", "filters"]);
4784
4955
  const plainData = this.paramsToPlain({ id: checkId });
4785
4956
  const id = await this.getId(plainData.id);
4786
4957
  const category = await super.update(Object.assign(Object.assign({ id }, data), { isWishlist: false }));
4787
4958
  category.products = products && (await this.updateProducts(+id, { products }));
4788
- category.metadata = metadata && (await this.updateMetadata(+id, { metadata }));
4959
+ category.metadatas = metadatas && (await this.updateMetadata(+id, { metadatas }));
4789
4960
  category.filters = filters && (await this.updateFilters(+id, { filters }));
4790
4961
  return category;
4791
4962
  }
@@ -4823,7 +4994,7 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
4823
4994
  });
4824
4995
  return data;
4825
4996
  }
4826
- async getCategoriesForHome(categoryIds, limit = 4, gender) {
4997
+ async getCategoriesForHome(categoryIds, shop, limit = 4) {
4827
4998
  if (!(categoryIds === null || categoryIds === void 0 ? void 0 : categoryIds.length))
4828
4999
  return [];
4829
5000
  const categoriesFirestore = categoryIds.filter((categoryId) => Number.isNaN(+categoryId));
@@ -4835,22 +5006,32 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
4835
5006
  }).then(({ data }) => data)));
4836
5007
  if (categoriesHasura.length)
4837
5008
  categories.push(...(await this.find({
4838
- filters: { id: { operator: exports.Where.IN, value: categoriesHasura.filter(Boolean) }, published: true },
5009
+ filters: {
5010
+ id: { operator: exports.Where.IN, value: categoriesHasura.filter(Boolean) },
5011
+ published: true,
5012
+ },
4839
5013
  }).then(({ data }) => data)));
4840
5014
  if (!categories.length)
4841
5015
  return [];
4842
5016
  const homeSections = await Promise.all(categories.map(async (category) => ({
4843
5017
  category,
4844
- products: await this.mountCategory(category, { limit, hasStock: true, gender }),
5018
+ products: await this.mountCategory(category, shop, { limit, hasStock: true }),
4845
5019
  })));
4846
5020
  return homeSections;
4847
5021
  }
4848
- async mountCategory(category, options) {
5022
+ async mountCategory(category, shop, options) {
4849
5023
  var _a;
4850
5024
  if (!((_a = category === null || category === void 0 ? void 0 : category.products) === null || _a === void 0 ? void 0 : _a.length))
4851
5025
  return [];
5026
+ const mostRelevants = category.getMostRelevantByShop(shop);
5027
+ const mostRelevantProductsIds = [...new Set(mostRelevants.concat(category.products))];
4852
5028
  const products = [];
4853
- const { data: productsData } = await this.productRepository.find(Object.assign(Object.assign({ filters: Object.assign(Object.assign({ id: { operator: exports.Where.IN, value: category.products }, published: true }, ((options === null || options === void 0 ? void 0 : options.hasStock) ? { stock: { quantity: { operator: exports.Where.GT, value: 0 } } } : {})), ((options === null || options === void 0 ? void 0 : options.gender) ? { tags: { operator: exports.Where.IN, value: [options === null || options === void 0 ? void 0 : options.gender] } } : {})), fields: [
5029
+ const { data: productsData } = await this.productRepository.findCatalog({
5030
+ filters: {
5031
+ id: { operator: exports.Where.IN, value: mostRelevantProductsIds },
5032
+ published: true,
5033
+ },
5034
+ fields: [
4854
5035
  'id',
4855
5036
  'name',
4856
5037
  'slug',
@@ -4876,12 +5057,29 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
4876
5057
  'shoppingCount',
4877
5058
  'gender',
4878
5059
  'createdAt',
4879
- ] }, ((options === null || options === void 0 ? void 0 : options.limit) ? { limits: { limit: options === null || options === void 0 ? void 0 : options.limit } } : {})), { options: { enableCount: false } }));
4880
- products.push(...productsData);
5060
+ ],
5061
+ options: { enableCount: false },
5062
+ orderBy: {
5063
+ shoppingCount: 'desc',
5064
+ rate: 'desc',
5065
+ stock: 'desc',
5066
+ name: 'asc',
5067
+ },
5068
+ }, shop === exports.Shops.MENSMARKET ? 'male' : 'female');
5069
+ const mostRelevantWithouyStock = productsData.filter((product) => mostRelevants.includes(product.id) && product.stock.quantity <= 0);
5070
+ const firstProducts = productsData
5071
+ .filter((product) => mostRelevants.includes(product.id) && product.stock.quantity > 0)
5072
+ .sort((a, b) => mostRelevants.indexOf(a.id) - mostRelevants.indexOf(b.id));
5073
+ const lastProducts = productsData
5074
+ .filter((product) => !mostRelevants.includes(product.id) && product.stock.quantity > 0)
5075
+ .concat(mostRelevantWithouyStock);
5076
+ const categoryMostRelevants = firstProducts.concat(lastProducts);
5077
+ const resultFinal = categoryMostRelevants.slice(0, options.limit);
5078
+ products.push(...resultFinal);
4881
5079
  return products;
4882
5080
  }
4883
5081
  async getChildren(parentId) {
4884
- const { category_tree } = await this.query('category_tree', ['id', 'name', 'parent_id', 'slug', 'reference'], {
5082
+ const { category_tree } = await this.query('category_tree', ['id', 'name', 'parent_id', 'slug', 'reference', 'published', 'shops'], {
4885
5083
  args: {
4886
5084
  type: 'category_tree_args',
4887
5085
  value: { parentid: parentId },
@@ -4914,29 +5112,6 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
4914
5112
  });
4915
5113
  return [];
4916
5114
  }
4917
- const plainData = this.paramsToPlain({ products });
4918
- if (!plainData.products || plainData.products.length <= 0)
4919
- return [];
4920
- const category = await this.get({ id: categoryId.toString() });
4921
- await this.mutation('delete_category_product', ['affected_rows'], {
4922
- where: {
4923
- type: 'category_product_bool_exp',
4924
- required: true,
4925
- value: {
4926
- category_id: { _eq: categoryId },
4927
- product_id: { _in: category.products.filter((productId) => !plainData.products.includes(productId)) },
4928
- },
4929
- },
4930
- });
4931
- await this.mutation('insert_category_product', ['affected_rows'], {
4932
- objects: {
4933
- type: '[category_product_insert_input!]',
4934
- required: true,
4935
- value: plainData.products
4936
- .filter((productId) => !category.products.includes(productId))
4937
- .map((productId) => ({ category_id: categoryId, product_id: productId })),
4938
- },
4939
- });
4940
5115
  const productsOrder = products.map((product, index) => {
4941
5116
  return {
4942
5117
  id: product,
@@ -4945,7 +5120,7 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
4945
5120
  });
4946
5121
  const updateQueries = productsOrder.map((product) => ({
4947
5122
  where: {
4948
- category_id: { _eq: category.id },
5123
+ category_id: { _eq: categoryId },
4949
5124
  product_id: { _eq: product.id },
4950
5125
  },
4951
5126
  _set: {
@@ -4959,25 +5134,39 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
4959
5134
  required: true,
4960
5135
  },
4961
5136
  });
5137
+ const plainData = this.paramsToPlain({ products });
4962
5138
  return plainData.products;
4963
5139
  }
4964
- async updateMetadata(categoryId, { metadata }) {
4965
- const plainData = this.paramsToPlain({ metadata });
4966
- if (!plainData.metadata)
4967
- return null;
4968
- await this.mutation('update_category_metadata_by_pk', ['category_id'], {
4969
- pk_columns: {
4970
- value: { category_id: categoryId },
4971
- type: 'category_metadata_pk_columns_input',
4972
- required: true,
4973
- },
4974
- _set: {
4975
- value: lodash.omit(metadata, ['category_id']),
4976
- type: 'category_metadata_set_input',
4977
- required: true,
4978
- },
4979
- });
4980
- return plainData.metadata;
5140
+ async updateMetadata(categoryId, { metadatas }) {
5141
+ if (Array.isArray(metadatas) && !metadatas.length)
5142
+ return [];
5143
+ if (Array.isArray(metadatas) && metadatas.length) {
5144
+ await this.mutation('delete_category_metadata', ['affected_rows'], {
5145
+ where: {
5146
+ type: 'category_metadata_bool_exp',
5147
+ required: true,
5148
+ value: { category_id: { _eq: categoryId } },
5149
+ },
5150
+ });
5151
+ await this.mutation('insert_category_metadata', ['affected_rows'], {
5152
+ objects: {
5153
+ type: '[category_metadata_insert_input!]',
5154
+ required: true,
5155
+ value: metadatas.map((m) => (Object.assign({ category_id: categoryId }, m))),
5156
+ },
5157
+ });
5158
+ return metadatas;
5159
+ }
5160
+ if ('action' in metadatas && metadatas.action === 'remove' && metadatas.value.length) {
5161
+ await this.mutation('delete_category_metadata', ['affected_rows'], {
5162
+ where: {
5163
+ type: 'category_metadata_bool_exp',
5164
+ required: true,
5165
+ value: { category_id: { _eq: categoryId } },
5166
+ },
5167
+ });
5168
+ return [];
5169
+ }
4981
5170
  }
4982
5171
  async updateFilters(categoryId, { filters }) {
4983
5172
  if ('action' in filters && filters.action === 'remove' && filters.value.length) {
@@ -5039,13 +5228,13 @@ tslib.__decorate([
5039
5228
  tslib.__decorate([
5040
5229
  Log(),
5041
5230
  tslib.__metadata("design:type", Function),
5042
- tslib.__metadata("design:paramtypes", [Array, Object, String]),
5231
+ tslib.__metadata("design:paramtypes", [Array, String, Object]),
5043
5232
  tslib.__metadata("design:returntype", Promise)
5044
5233
  ], CategoryHasuraGraphQLRepository.prototype, "getCategoriesForHome", null);
5045
5234
  tslib.__decorate([
5046
5235
  Log(),
5047
5236
  tslib.__metadata("design:type", Function),
5048
- tslib.__metadata("design:paramtypes", [Category, Object]),
5237
+ tslib.__metadata("design:paramtypes", [Category, String, Object]),
5049
5238
  tslib.__metadata("design:returntype", Promise)
5050
5239
  ], CategoryHasuraGraphQLRepository.prototype, "mountCategory", null);
5051
5240
  tslib.__decorate([
@@ -5061,6 +5250,40 @@ tslib.__decorate([
5061
5250
  tslib.__metadata("design:returntype", Promise)
5062
5251
  ], CategoryHasuraGraphQLRepository.prototype, "isChild", null);
5063
5252
 
5253
+ class CategoryProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
5254
+ constructor({ endpoint, authOptions, interceptors, }) {
5255
+ super({
5256
+ tableName: 'category_product',
5257
+ model: CategoryProduct,
5258
+ endpoint,
5259
+ authOptions,
5260
+ interceptors,
5261
+ fields: [{ productId: { columnName: 'product_id' } }, { categoryId: { columnName: 'category_id' } }, 'order'],
5262
+ });
5263
+ }
5264
+ async removeProductFromCategory(categoryId, productId) {
5265
+ await this.mutation('delete_category_product', ['affected_rows'], {
5266
+ where: {
5267
+ type: 'category_product_bool_exp',
5268
+ required: true,
5269
+ value: {
5270
+ product_id: { _eq: productId },
5271
+ category_id: { _eq: categoryId },
5272
+ },
5273
+ },
5274
+ });
5275
+ }
5276
+ async addProductToCategory(categoryId, productId) {
5277
+ await this.mutation('insert_category_product', ['affected_rows'], {
5278
+ objects: {
5279
+ type: '[category_product_insert_input!]',
5280
+ required: true,
5281
+ value: [{ category_id: categoryId, product_id: productId }],
5282
+ },
5283
+ });
5284
+ }
5285
+ }
5286
+
5064
5287
  class FilterHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
5065
5288
  constructor({ endpoint, authOptions, interceptors, }, filterOptionRepository, categoryFilterRepository) {
5066
5289
  super({
@@ -5071,6 +5294,7 @@ class FilterHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGrap
5071
5294
  interceptors,
5072
5295
  fields: [
5073
5296
  'id',
5297
+ 'title',
5074
5298
  'description',
5075
5299
  'slug',
5076
5300
  'enabled',
@@ -5326,6 +5550,7 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
5326
5550
  { subscriberPrice: { columnName: 'subscriber_price' } },
5327
5551
  'published',
5328
5552
  'outlet',
5553
+ 'label',
5329
5554
  'sku',
5330
5555
  {
5331
5556
  stock: {
@@ -5357,6 +5582,8 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
5357
5582
  fields: ['id', 'name', 'reference', 'slug'],
5358
5583
  },
5359
5584
  },
5585
+ 'group',
5586
+ 'validity',
5360
5587
  ];
5361
5588
  this.fields = [
5362
5589
  ...commonFields,
@@ -5458,6 +5685,8 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
5458
5685
  enableCount: false,
5459
5686
  },
5460
5687
  });
5688
+ if (!result.data.length)
5689
+ return null;
5461
5690
  const product = (_a = result === null || result === void 0 ? void 0 : result.data) === null || _a === void 0 ? void 0 : _a.shift();
5462
5691
  RoundProductPricesHelper.roundProductPrices(product);
5463
5692
  return product;
@@ -5467,7 +5696,6 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
5467
5696
  const plainData = this.paramsToPlain({ id: checkId });
5468
5697
  const id = await this.getId(plainData.id);
5469
5698
  const product = await super.update(Object.assign({ id }, data));
5470
- product.categories = categories && (await this.updateCategories(+id, { categories }));
5471
5699
  product.kitProducts = kitProducts && (await this.updateKitProducts(+id, { kitProducts }));
5472
5700
  product.reviews = reviews && (await this.updateReviews(+id, { reviews }));
5473
5701
  product.metadata = metadata && (await this.updateMetadata(+id, { metadata }));
@@ -5531,42 +5759,6 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
5531
5759
  getReviewStatus(review) {
5532
5760
  return review.status === true ? 'approved' : review.status === false ? 'rejected' : 'pending';
5533
5761
  }
5534
- async updateCategories(productId, { categories }) {
5535
- if ('action' in categories && categories.action === 'remove') {
5536
- await this.mutation('delete_category_product', ['affected_rows'], {
5537
- where: {
5538
- type: 'category_product_bool_exp',
5539
- required: true,
5540
- value: { product_id: { _eq: productId } },
5541
- },
5542
- });
5543
- return [];
5544
- }
5545
- const plainData = this.paramsToPlain({ categories });
5546
- if (!plainData.categories || plainData.categories.length <= 0)
5547
- return [];
5548
- const product = await this.get({ id: productId.toString() });
5549
- await this.mutation('delete_category_product', ['affected_rows'], {
5550
- where: {
5551
- type: 'category_product_bool_exp',
5552
- required: true,
5553
- value: {
5554
- product_id: { _eq: productId },
5555
- category_id: { _in: product.categories.filter((categoryId) => !plainData.categories.includes(categoryId)) },
5556
- },
5557
- },
5558
- });
5559
- await this.mutation('insert_category_product', ['affected_rows'], {
5560
- objects: {
5561
- type: '[category_product_insert_input!]',
5562
- required: true,
5563
- value: plainData.categories
5564
- .filter((categoryId) => !product.categories.includes(categoryId))
5565
- .map((categoryId) => ({ category_id: categoryId, product_id: productId })),
5566
- },
5567
- });
5568
- return plainData.categories;
5569
- }
5570
5762
  async updateKitProducts(productId, { kitProducts }) {
5571
5763
  const plainData = this.paramsToPlain({ kitProducts });
5572
5764
  await this.mutation('delete_product_kit', ['affected_rows'], {
@@ -5757,6 +5949,24 @@ class ProductReviewsHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHa
5757
5949
  ],
5758
5950
  });
5759
5951
  }
5952
+ async updateManyStatus(reviews) {
5953
+ return await this.mutation('update_product_review_many', ['affected_rows'], {
5954
+ updates: {
5955
+ type: '[product_review_updates!]',
5956
+ required: true,
5957
+ value: [
5958
+ {
5959
+ _set: { status: true },
5960
+ where: { id: { _in: reviews.filter((review) => review.status).map((review) => review.id) } },
5961
+ },
5962
+ {
5963
+ _set: { status: false },
5964
+ where: { id: { _in: reviews.filter((review) => !review.status).map((review) => review.id) } },
5965
+ },
5966
+ ],
5967
+ },
5968
+ });
5969
+ }
5760
5970
  aproveReview(id) {
5761
5971
  return this.update({ id, status: true });
5762
5972
  }
@@ -5811,6 +6021,31 @@ class ProductStockNotificationHasuraGraphQLRepository extends withCrudHasuraGrap
5811
6021
  email,
5812
6022
  });
5813
6023
  }
6024
+ async getNotificationsReport(params, orderBy, pagination) {
6025
+ const query = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (params.productId && { product_id: { _eq: params.productId } })), (params.ean && { ean: { _eq: params.ean } })), (params.sku && { sku: { _eq: params.sku } })), (params.name && { name: { _iregex: params.name } })), (params.categoryId && { category_id: { _eq: params.categoryId } })), (params.category && { category: { _iregex: params.category } })), (params.reference && { category_reference: { _eq: params.reference } })), (params.emailsCount && { emails_registered: { _eq: params.emailsCount } }));
6026
+ const orderByField = {
6027
+ [orderBy.field]: orderBy.direction,
6028
+ };
6029
+ const { report_stock_notification } = await this.query('report_stock_notification', ['product_id', 'ean', 'sku', 'name', 'stock', 'category_id', 'category', 'reference', 'emails_registered'], {
6030
+ where: {
6031
+ type: 'report_stock_notification_bool_exp',
6032
+ value: query,
6033
+ required: true,
6034
+ },
6035
+ order_by: {
6036
+ type: '[report_stock_notification_order_by]',
6037
+ value: orderByField,
6038
+ required: true,
6039
+ },
6040
+ });
6041
+ const data = (pagination === null || pagination === void 0 ? void 0 : pagination.limit)
6042
+ ? report_stock_notification.slice(pagination === null || pagination === void 0 ? void 0 : pagination.offset, (pagination === null || pagination === void 0 ? void 0 : pagination.offset) + (pagination === null || pagination === void 0 ? void 0 : pagination.limit))
6043
+ : report_stock_notification;
6044
+ return {
6045
+ data,
6046
+ count: report_stock_notification.length,
6047
+ };
6048
+ }
5814
6049
  }
5815
6050
 
5816
6051
  class VariantHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
@@ -5884,6 +6119,8 @@ class VariantHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
5884
6119
  type: HasuraGraphQLColumnType.Jsonb,
5885
6120
  },
5886
6121
  },
6122
+ 'group',
6123
+ 'validity',
5887
6124
  ],
5888
6125
  });
5889
6126
  }
@@ -5919,11 +6156,14 @@ class VariantHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
5919
6156
  }
5920
6157
  }
5921
6158
 
6159
+ class WishlistHasuraGraphQL extends Wishlist {
6160
+ }
6161
+
5922
6162
  class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
5923
- constructor({ endpoint, authOptions, interceptors, }, categoryFilterRepository) {
6163
+ constructor({ endpoint, authOptions, interceptors, }, categoryProductRepository) {
5924
6164
  super({
5925
6165
  tableName: 'category',
5926
- model: Wishlist,
6166
+ model: WishlistHasuraGraphQL,
5927
6167
  endpoint,
5928
6168
  authOptions,
5929
6169
  interceptors,
@@ -5984,12 +6224,21 @@ class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
5984
6224
  {
5985
6225
  metadata: {
5986
6226
  columnName: 'metadata',
5987
- fields: ['title', 'description'],
6227
+ fields: ['shop', 'title', 'description'],
5988
6228
  bindPersistData: (value) => ({
5989
6229
  metadata: { data: value },
5990
6230
  }),
5991
6231
  },
5992
6232
  },
6233
+ {
6234
+ metadatas: {
6235
+ columnName: 'metadatas',
6236
+ fields: ['shop', 'title', 'description'],
6237
+ bindPersistData: (value) => ({
6238
+ metadatas: { data: value },
6239
+ }),
6240
+ },
6241
+ },
5993
6242
  { isCollection: { columnName: 'is_collection' } },
5994
6243
  { isWishlist: { columnName: 'is_wishlist' } },
5995
6244
  'reference',
@@ -6004,15 +6253,34 @@ class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
6004
6253
  { personId: { columnName: 'person_id' } },
6005
6254
  { personName: { columnName: 'person_name' } },
6006
6255
  { personPhoto: { columnName: 'person_photo' } },
6256
+ { personType: { columnName: 'person_type' } },
6257
+ { personIsSubscriber: { columnName: 'person_is_subscriber' } },
6007
6258
  'theme',
6008
6259
  { bannerUrl: { columnName: 'banner_url' } },
6260
+ { personHasPhoto: { columnName: 'person_has_photo' } },
6261
+ { mostRelevants: { columnName: 'most_relevants', type: HasuraGraphQLColumnType.Jsonb } },
6009
6262
  ],
6010
6263
  });
6011
- this.categoryFilterRepository = categoryFilterRepository;
6264
+ this.categoryProductRepository = categoryProductRepository;
6012
6265
  }
6013
6266
  async create(params) {
6014
- const { metadata } = params, data = tslib.__rest(params, ["metadata"]);
6015
- return super.create(Object.assign(Object.assign({}, data), { isWishlist: true, isCollection: true, brandCategory: false, metadata: metadata || { description: data.description, title: data.name } }));
6267
+ var _a;
6268
+ const { images, mostRelevants, metadatas } = params, data = tslib.__rest(params, ["images", "mostRelevants", "metadatas"]);
6269
+ return super.create(Object.assign(Object.assign({}, data), { isWishlist: true, isCollection: true, brandCategory: false, metadatas: metadatas || [{ shop: (_a = data.shop) !== null && _a !== void 0 ? _a : null, description: data.description, title: data.name }], mostRelevants: mostRelevants || {
6270
+ [exports.Shops.GLAMSHOP]: null,
6271
+ [exports.Shops.MENSMARKET]: null,
6272
+ }, images: images || {
6273
+ [exports.Shops.GLAMSHOP]: {
6274
+ brandBanner: null,
6275
+ brandBannerMobile: null,
6276
+ image: null,
6277
+ },
6278
+ [exports.Shops.MENSMARKET]: {
6279
+ brandBanner: null,
6280
+ brandBannerMobile: null,
6281
+ image: null,
6282
+ },
6283
+ } }));
6016
6284
  }
6017
6285
  async get(identifiers) {
6018
6286
  const data = await super.get(identifiers);
@@ -6025,12 +6293,11 @@ class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
6025
6293
  return await super.find(Object.assign(Object.assign({}, rest), { filters: Object.assign(Object.assign({}, filters), { isWishlist: { operator: exports.Where.EQUALS, value: true } }) }));
6026
6294
  }
6027
6295
  async update(params) {
6028
- const { products, id: checkId, metadata, filters } = params, data = tslib.__rest(params, ["products", "id", "metadata", "filters"]);
6296
+ const { products, id: checkId, metadatas, filters } = params, data = tslib.__rest(params, ["products", "id", "metadatas", "filters"]);
6029
6297
  const plainData = this.paramsToPlain({ id: checkId });
6030
6298
  const id = plainData.id;
6031
6299
  const category = await super.update(Object.assign(Object.assign({ id }, data), { isWishlist: true, isCollection: true, brandCategory: false }));
6032
- category.products = products && (await this.updateProducts(+id, { products }));
6033
- category.metadata = metadata && (await this.updateMetadata(+id, { metadata }));
6300
+ category.metadatas = metadatas && (await this.updateMetadata(+id, { metadatas }));
6034
6301
  return category;
6035
6302
  }
6036
6303
  async getWishlistBySlug(slug) {
@@ -6062,12 +6329,18 @@ class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
6062
6329
  options: {
6063
6330
  enableCount: false,
6064
6331
  },
6332
+ orderBy: {
6333
+ id: 'asc',
6334
+ },
6335
+ limits: {
6336
+ limit: 1,
6337
+ },
6065
6338
  });
6066
6339
  if (!data.length)
6067
6340
  throw new NotFoundError(`Wishlists from person ${personId} not found`);
6068
6341
  return data;
6069
6342
  }
6070
- getCategoryBySlug(slug, _shop) {
6343
+ async getCategoryBySlug(slug, _shop) {
6071
6344
  return this.getWishlistBySlug(slug);
6072
6345
  }
6073
6346
  async getCategoryByShop(shop) {
@@ -6085,10 +6358,17 @@ class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
6085
6358
  });
6086
6359
  return data;
6087
6360
  }
6088
- getCategoriesForHome(categoryIds, limit, gender) {
6361
+ async findBfluOrGlamgirlWishlists(params, shops) {
6362
+ var _a, _b;
6363
+ return this.find(Object.assign(Object.assign({}, params), { filters: Object.assign(Object.assign({}, params.filters), { published: true, shops: { operator: exports.Where.LIKE, value: shops }, personType: (_b = (_a = params.filters) === null || _a === void 0 ? void 0 : _a.personType) !== null && _b !== void 0 ? _b : {
6364
+ operator: exports.Where.IN,
6365
+ value: [exports.PersonTypes.BFLU, exports.PersonTypes.GLAMGIRL],
6366
+ } }), orderBy: Object.assign({ personHasPhoto: 'desc' }, lodash.omit(params.orderBy, ['personHasPhoto'])) }));
6367
+ }
6368
+ getCategoriesForHome(categoryIds, gender, limit) {
6089
6369
  return;
6090
6370
  }
6091
- mountCategory(category, options) {
6371
+ mountCategory(category, shop, options) {
6092
6372
  return;
6093
6373
  }
6094
6374
  getChildren(parentId) {
@@ -6097,61 +6377,46 @@ class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
6097
6377
  isChild(id, parentId) {
6098
6378
  return;
6099
6379
  }
6100
- async updateProducts(categoryId, { products }) {
6101
- if ('action' in products && products.action === 'remove') {
6102
- await this.mutation('delete_category_product', ['affected_rows'], {
6103
- where: {
6104
- type: 'category_product_bool_exp',
6105
- required: true,
6106
- value: { category_id: { _eq: categoryId } },
6107
- },
6108
- });
6109
- await this.categoryFilterRepository.deleteByCategory(categoryId);
6380
+ async updateMetadata(categoryId, { metadatas }) {
6381
+ if (Array.isArray(metadatas) && !metadatas.length)
6110
6382
  return [];
6383
+ if (Array.isArray(metadatas) && metadatas.length) {
6384
+ const metadataUpdated = [];
6385
+ for (const data of metadatas) {
6386
+ const update = await this.mutation('update_category_metadata_by_pk', ['category_id', 'shop'], {
6387
+ pk_columns: {
6388
+ value: { category_id: categoryId, shop: data.shop },
6389
+ type: 'category_metadata_pk_columns_input',
6390
+ required: true,
6391
+ },
6392
+ _set: {
6393
+ value: lodash.omit(data, ['category_id', 'shop']),
6394
+ type: 'category_metadata_set_input',
6395
+ required: true,
6396
+ },
6397
+ });
6398
+ metadataUpdated.push(update);
6399
+ }
6400
+ return metadataUpdated;
6111
6401
  }
6112
- const plainData = this.paramsToPlain({ products });
6113
- if (!plainData.products || plainData.products.length <= 0)
6402
+ if ('action' in metadatas && metadatas.action === 'remove' && metadatas.value.length) {
6403
+ for (let i = 0; i < metadatas.value.length; i++) {
6404
+ await this.mutation('delete_category_metadata', ['affected_rows'], {
6405
+ where: {
6406
+ type: 'category_metadata_bool_exp',
6407
+ required: true,
6408
+ value: { category_id: { _eq: categoryId }, shop: metadatas.value[i].shop },
6409
+ },
6410
+ });
6411
+ }
6114
6412
  return [];
6115
- const category = await this.get({ id: categoryId.toString() });
6116
- await this.categoryFilterRepository.deleteByCategory(categoryId);
6117
- await this.mutation('delete_category_product', ['affected_rows'], {
6118
- where: {
6119
- type: 'category_product_bool_exp',
6120
- required: true,
6121
- value: {
6122
- category_id: { _eq: categoryId },
6123
- product_id: { _in: category.products.filter((productId) => !plainData.products.includes(productId)) },
6124
- },
6125
- },
6126
- });
6127
- await this.mutation('insert_category_product', ['affected_rows'], {
6128
- objects: {
6129
- type: '[category_product_insert_input!]',
6130
- required: true,
6131
- value: plainData.products
6132
- .filter((productId) => !category.products.includes(productId))
6133
- .map((productId) => ({ category_id: categoryId, product_id: productId })),
6134
- },
6135
- });
6136
- return plainData.products;
6413
+ }
6137
6414
  }
6138
- async updateMetadata(categoryId, { metadata }) {
6139
- const plainData = this.paramsToPlain({ metadata });
6140
- if (!plainData.metadata)
6141
- return;
6142
- await this.mutation('update_category_metadata_by_pk', ['category_id'], {
6143
- pk_columns: {
6144
- value: { category_id: categoryId },
6145
- type: 'category_metadata_pk_columns_input',
6146
- required: true,
6147
- },
6148
- _set: {
6149
- value: lodash.omit(metadata, ['category_id']),
6150
- type: 'category_metadata_set_input',
6151
- required: true,
6152
- },
6153
- });
6154
- return plainData.metadata;
6415
+ async addProduct(wishlistId, productId) {
6416
+ return this.categoryProductRepository.addProductToCategory(wishlistId, productId);
6417
+ }
6418
+ async removeProduct(wishlistId, productId) {
6419
+ return this.categoryProductRepository.removeProductFromCategory(wishlistId, productId);
6155
6420
  }
6156
6421
  }
6157
6422
  tslib.__decorate([
@@ -6172,6 +6437,165 @@ tslib.__decorate([
6172
6437
  tslib.__metadata("design:paramtypes", [String]),
6173
6438
  tslib.__metadata("design:returntype", Promise)
6174
6439
  ], WishlistHasuraGraphQLRepository.prototype, "getCategoryByShop", null);
6440
+ tslib.__decorate([
6441
+ Log(),
6442
+ tslib.__metadata("design:type", Function),
6443
+ tslib.__metadata("design:paramtypes", [Object, Array]),
6444
+ tslib.__metadata("design:returntype", Promise)
6445
+ ], WishlistHasuraGraphQLRepository.prototype, "findBfluOrGlamgirlWishlists", null);
6446
+
6447
+ class VertexAxiosAdapter {
6448
+ constructor(config) {
6449
+ this.config = config;
6450
+ this.logger = DebugHelper.from(this);
6451
+ }
6452
+ async query(term, total, gender) {
6453
+ const logger = this.logger.with('query');
6454
+ const req = {
6455
+ url: `${this.config.url}/search`,
6456
+ method: 'POST',
6457
+ responseType: 'json',
6458
+ headers: {
6459
+ Accept: 'application/json',
6460
+ },
6461
+ data: { term, total, gender },
6462
+ };
6463
+ try {
6464
+ const { data } = await axios__default["default"](req);
6465
+ return data;
6466
+ }
6467
+ catch (error) {
6468
+ logger.error({ req, res: error });
6469
+ throw error;
6470
+ }
6471
+ }
6472
+ async get(id) {
6473
+ const logger = this.logger.with('update');
6474
+ const req = {
6475
+ url: `${this.config.url}/${id}`,
6476
+ method: 'GET',
6477
+ responseType: 'json',
6478
+ headers: {
6479
+ Accept: 'application/json',
6480
+ },
6481
+ };
6482
+ try {
6483
+ const { data } = await axios__default["default"](req);
6484
+ return data;
6485
+ }
6486
+ catch (error) {
6487
+ logger.error({ req, res: error });
6488
+ throw error;
6489
+ }
6490
+ }
6491
+ async save(data) {
6492
+ const logger = this.logger.with('save');
6493
+ const req = {
6494
+ url: `${this.config.url}/sync`,
6495
+ method: 'POST',
6496
+ responseType: 'json',
6497
+ headers: {
6498
+ Accept: 'application/json',
6499
+ },
6500
+ data,
6501
+ };
6502
+ try {
6503
+ const { data } = await axios__default["default"](req);
6504
+ return data;
6505
+ }
6506
+ catch (error) {
6507
+ logger.error({ req, res: error });
6508
+ throw error;
6509
+ }
6510
+ }
6511
+ async update(id, data) {
6512
+ const logger = this.logger.with('update');
6513
+ const req = {
6514
+ url: `${this.config.url}/${id}`,
6515
+ method: 'PUT',
6516
+ responseType: 'json',
6517
+ headers: {
6518
+ Accept: 'application/json',
6519
+ },
6520
+ data,
6521
+ };
6522
+ try {
6523
+ const { data } = await axios__default["default"](req);
6524
+ return data;
6525
+ }
6526
+ catch (error) {
6527
+ logger.error({ req, res: error });
6528
+ throw error;
6529
+ }
6530
+ }
6531
+ async delete(id) {
6532
+ const logger = this.logger.with('delete');
6533
+ const req = {
6534
+ url: `${this.config.url}/${id}`,
6535
+ method: 'DELETE',
6536
+ responseType: 'json',
6537
+ headers: {
6538
+ Accept: 'application/json',
6539
+ },
6540
+ };
6541
+ try {
6542
+ const { data } = await axios__default["default"](req);
6543
+ return data;
6544
+ }
6545
+ catch (error) {
6546
+ logger.error({ req, res: error });
6547
+ throw error;
6548
+ }
6549
+ }
6550
+ bulkProducts(products) {
6551
+ return;
6552
+ }
6553
+ }
6554
+
6555
+ class ProductsVertexSearch {
6556
+ constructor(adapter) {
6557
+ this.adapter = adapter;
6558
+ }
6559
+ async getById(id) {
6560
+ const data = await this.adapter.get(id);
6561
+ return data;
6562
+ }
6563
+ async search(searchTerm, total, gender) {
6564
+ try {
6565
+ const result = await this.adapter.query(searchTerm, total, gender);
6566
+ return result;
6567
+ }
6568
+ catch (error) {
6569
+ console.error(error);
6570
+ }
6571
+ }
6572
+ async save(product) {
6573
+ try {
6574
+ const _a = product.toPlain(), { createdAt, updatedAt, kitProducts } = _a, data = tslib.__rest(_a, ["createdAt", "updatedAt", "kitProducts"]);
6575
+ const newProduct = Product.toInstance(data);
6576
+ await this.adapter.save(newProduct);
6577
+ }
6578
+ catch (error) {
6579
+ console.error(error);
6580
+ }
6581
+ }
6582
+ async update(product) {
6583
+ try {
6584
+ await this.adapter.update(product.id, product);
6585
+ }
6586
+ catch (error) {
6587
+ console.error(error);
6588
+ }
6589
+ }
6590
+ async delete(id) {
6591
+ try {
6592
+ await this.adapter.delete(id);
6593
+ }
6594
+ catch (error) {
6595
+ console.error(error);
6596
+ }
6597
+ }
6598
+ }
6175
6599
 
6176
6600
  Object.defineProperty(exports, 'add', {
6177
6601
  enumerable: true,
@@ -6313,6 +6737,8 @@ exports.CategoryFilterHasuraGraphQLRepository = CategoryFilterHasuraGraphQLRepos
6313
6737
  exports.CategoryFirestoreRepository = CategoryFirestoreRepository;
6314
6738
  exports.CategoryHasuraGraphQL = CategoryHasuraGraphQL;
6315
6739
  exports.CategoryHasuraGraphQLRepository = CategoryHasuraGraphQLRepository;
6740
+ exports.CategoryProduct = CategoryProduct;
6741
+ exports.CategoryProductHasuraGraphQLRepository = CategoryProductHasuraGraphQLRepository;
6316
6742
  exports.Checkout = Checkout;
6317
6743
  exports.CheckoutFirestoreRepository = CheckoutFirestoreRepository;
6318
6744
  exports.CheckoutSubscription = CheckoutSubscription;
@@ -6344,9 +6770,13 @@ exports.LeadFirestoreRepository = LeadFirestoreRepository;
6344
6770
  exports.LegacyOrderFirestoreRepository = LegacyOrderFirestoreRepository;
6345
6771
  exports.LineItem = LineItem;
6346
6772
  exports.Log = Log;
6773
+ exports.LogDocument = LogDocument;
6774
+ exports.LogFirestoreRepository = LogFirestoreRepository;
6347
6775
  exports.Logger = Logger;
6348
6776
  exports.NotFoundError = NotFoundError;
6349
6777
  exports.Order = Order;
6778
+ exports.OrderBlocked = OrderBlocked;
6779
+ exports.OrderBlockedFirestoreRepository = OrderBlockedFirestoreRepository;
6350
6780
  exports.OrderFirestoreRepository = OrderFirestoreRepository;
6351
6781
  exports.Payment = Payment;
6352
6782
  exports.PaymentFirestoreRepository = PaymentFirestoreRepository;
@@ -6360,6 +6790,7 @@ exports.ProductStockNotification = ProductStockNotification;
6360
6790
  exports.ProductStockNotificationHasuraGraphQLRepository = ProductStockNotificationHasuraGraphQLRepository;
6361
6791
  exports.ProductVariantFirestoreRepository = ProductVariantFirestoreRepository;
6362
6792
  exports.ProductsIndex = ProductsIndex;
6793
+ exports.ProductsVertexSearch = ProductsVertexSearch;
6363
6794
  exports.RecoveryPassword = RecoveryPassword;
6364
6795
  exports.ReflectHelper = ReflectHelper;
6365
6796
  exports.Register = Register;
@@ -6398,6 +6829,7 @@ exports.UserPaymentMethodFirestoreRepository = UserPaymentMethodFirestoreReposit
6398
6829
  exports.Variant = Variant;
6399
6830
  exports.VariantHasuraGraphQL = VariantHasuraGraphQL;
6400
6831
  exports.VariantHasuraGraphQLRepository = VariantHasuraGraphQLRepository;
6832
+ exports.VertexAxiosAdapter = VertexAxiosAdapter;
6401
6833
  exports.WeakPasswordError = WeakPasswordError;
6402
6834
  exports.Wishlist = Wishlist;
6403
6835
  exports.WishlistHasuraGraphQLRepository = WishlistHasuraGraphQLRepository;