@infrab4a/connect 4.9.7-beta.25 → 4.9.7-beta.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.esm.js CHANGED
@@ -51,6 +51,15 @@ var Shops;
51
51
  Shops["ALL"] = "ALL";
52
52
  })(Shops || (Shops = {}));
53
53
 
54
+ var WishlistLogType;
55
+ (function (WishlistLogType) {
56
+ WishlistLogType["CREATE"] = "create";
57
+ WishlistLogType["UPDATE"] = "update";
58
+ WishlistLogType["DELETE"] = "delete";
59
+ WishlistLogType["ADD_PRODUCT"] = "add_product";
60
+ WishlistLogType["REMOVE_PRODUCT"] = "remove_product";
61
+ })(WishlistLogType || (WishlistLogType = {}));
62
+
54
63
  class Filter extends BaseModel {
55
64
  static get identifiersFields() {
56
65
  return ['id'];
@@ -2124,6 +2133,9 @@ var CouponCategory;
2124
2133
  CouponCategory["Desculpas"] = "Desculpas";
2125
2134
  CouponCategory["BFlu"] = "BFlu";
2126
2135
  CouponCategory["ROYAL"] = "Royal";
2136
+ CouponCategory["Glamqueen"] = "Glamqueen";
2137
+ CouponCategory["Glampartner"] = "Glampartner";
2138
+ CouponCategory["Glamgirl"] = "Glamgirl";
2127
2139
  CouponCategory["Glamdiva"] = "Glamdiva";
2128
2140
  CouponCategory["Impulsionamento"] = "Impulsionamento";
2129
2141
  CouponCategory["PaidMedia"] = "Paid Media";
@@ -2225,6 +2237,12 @@ class RoundProductPricesHelper {
2225
2237
  }
2226
2238
  }
2227
2239
 
2240
+ class LogDocument extends BaseModel {
2241
+ static get identifiersFields() {
2242
+ return ['id'];
2243
+ }
2244
+ }
2245
+
2228
2246
  var FilterType;
2229
2247
  (function (FilterType) {
2230
2248
  FilterType["ACCESSORY_IMPORTANCE"] = "accessoryImportance";
@@ -3092,180 +3110,6 @@ const withCrudFirestore = (MixinBase) => {
3092
3110
  };
3093
3111
  };
3094
3112
 
3095
- class LeadFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3096
- constructor({ firestore, interceptors }) {
3097
- super({
3098
- firestore,
3099
- collectionName: 'leads',
3100
- model: Lead,
3101
- interceptors,
3102
- });
3103
- }
3104
- }
3105
-
3106
- class SubscriptionEditionFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
3107
- constructor({ firestore, interceptors }, parentRepository) {
3108
- super({
3109
- firestore,
3110
- collectionName: 'editions',
3111
- parentIdField: 'subscriptionId',
3112
- model: Edition,
3113
- interceptors,
3114
- });
3115
- this.parentRepository = parentRepository;
3116
- }
3117
- }
3118
-
3119
- class SubscriptionFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3120
- constructor({ firestore, interceptors, }) {
3121
- super({
3122
- firestore,
3123
- collectionName: 'subscription',
3124
- model: Subscription,
3125
- interceptors,
3126
- });
3127
- }
3128
- }
3129
-
3130
- class SubscriptionMaterializationFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3131
- constructor({ firestore, interceptors }) {
3132
- super({
3133
- firestore,
3134
- collectionName: 'subscriptionMaterialization',
3135
- model: SubscriptionMaterialization,
3136
- interceptors,
3137
- });
3138
- }
3139
- }
3140
-
3141
- class SubscriptionPaymentFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
3142
- constructor({ firestore, interceptors }, parentRepository) {
3143
- super({
3144
- firestore,
3145
- collectionName: 'payments',
3146
- parentIdField: 'subscriptionId',
3147
- model: SubscriptionPayment,
3148
- interceptors,
3149
- });
3150
- this.parentRepository = parentRepository;
3151
- }
3152
- }
3153
-
3154
- class SubscriptionSummaryFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3155
- constructor({ firestore, interceptors, }) {
3156
- super({
3157
- firestore,
3158
- collectionName: 'subscriptionSummary',
3159
- model: SubscriptionSummary,
3160
- interceptors,
3161
- });
3162
- }
3163
- }
3164
-
3165
- class UserAddressFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
3166
- constructor({ firestore, interceptors }, parentRepository) {
3167
- super({
3168
- firestore,
3169
- collectionName: 'address',
3170
- parentIdField: 'userId',
3171
- model: UserAddress,
3172
- interceptors,
3173
- });
3174
- this.parentRepository = parentRepository;
3175
- }
3176
- }
3177
-
3178
- class UserBeautyProfileFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
3179
- constructor({ firestore, interceptors }, parentRepository) {
3180
- super({
3181
- firestore,
3182
- collectionName: 'CX',
3183
- parentIdField: 'userId',
3184
- model: BeautyProfile,
3185
- interceptors,
3186
- });
3187
- this.parentRepository = parentRepository;
3188
- }
3189
- }
3190
-
3191
- class UserFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3192
- constructor({ firestore, interceptors }) {
3193
- super({
3194
- firestore,
3195
- collectionName: 'users',
3196
- model: User,
3197
- interceptors,
3198
- });
3199
- }
3200
- async get(identifiers) {
3201
- const user = await super.get({ id: identifiers.id });
3202
- user.beautyProfile = await this.getBeautyProfile(user.id);
3203
- user.isSubscriber = await this.checkIfIsSubscriber(user.id);
3204
- return user;
3205
- }
3206
- async checkIfExistsByField(field, value) {
3207
- const result = await this.find({ filters: { [field]: value } });
3208
- return result.count > 0;
3209
- }
3210
- buildModelInstance() {
3211
- const { fromFirestore, toFirestore } = super.buildModelInstance();
3212
- return {
3213
- toFirestore: (data) => {
3214
- const plain = toFirestore(data);
3215
- delete plain.isSubscriber;
3216
- return plain;
3217
- },
3218
- fromFirestore,
3219
- };
3220
- }
3221
- async getBeautyProfile(userId) {
3222
- const beautyProfile = await this.firestore
3223
- .getCollection(`${this.collectionName}/${userId}/CX`)
3224
- .withConverter(this.buildBeautyProfileModelInstance())
3225
- .getDoc('beautyProfile')
3226
- .get();
3227
- return beautyProfile.data();
3228
- }
3229
- async checkIfIsSubscriber(userId) {
3230
- const docs = await this.collection('subscription')
3231
- .where('user.id', '==', userId)
3232
- .where('status', '==', 'active')
3233
- .getDocs();
3234
- return !!docs && !!docs.size;
3235
- }
3236
- buildBeautyProfileModelInstance() {
3237
- return {
3238
- toFirestore: (data) => data.toPlain(),
3239
- fromFirestore: (snap) => BeautyProfile.toInstance(snap.data()),
3240
- };
3241
- }
3242
- }
3243
- __decorate([
3244
- Log(),
3245
- __metadata("design:type", Function),
3246
- __metadata("design:paramtypes", [Object]),
3247
- __metadata("design:returntype", Promise)
3248
- ], UserFirestoreRepository.prototype, "get", null);
3249
- __decorate([
3250
- Log(),
3251
- __metadata("design:type", Function),
3252
- __metadata("design:paramtypes", [String, String]),
3253
- __metadata("design:returntype", Promise)
3254
- ], UserFirestoreRepository.prototype, "checkIfExistsByField", null);
3255
-
3256
- class UserPaymentMethodFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
3257
- constructor({ firestore, interceptors }, parentRepository) {
3258
- super({
3259
- firestore,
3260
- collectionName: 'payment_method',
3261
- parentIdField: 'userId',
3262
- model: UserPaymentMethod,
3263
- interceptors,
3264
- });
3265
- this.parentRepository = parentRepository;
3266
- }
3267
- }
3268
-
3269
3113
  class CategoryFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3270
3114
  constructor({ firestore, interceptors }) {
3271
3115
  super({
@@ -3287,7 +3131,7 @@ class CategoryFirestoreRepository extends withCrudFirestore(withHelpers(withFire
3287
3131
  throw new NotFoundError(`Document with slug ${slug} not found`);
3288
3132
  return categoryDocs.docs[0].data();
3289
3133
  }
3290
- async getCategoriesForHome(categoryIds, limit = 4, gender) {
3134
+ async getCategoriesForHome(categoryIds, shop, limit = 4) {
3291
3135
  const categorySnap = await this.collection(this.collectionName)
3292
3136
  .where('id', 'in', categoryIds.filter(Boolean))
3293
3137
  .where('published', '==', true)
@@ -3297,11 +3141,11 @@ class CategoryFirestoreRepository extends withCrudFirestore(withHelpers(withFire
3297
3141
  const categories = categorySnap.docs.map((doc) => doc.data());
3298
3142
  const homeSections = await Promise.all(categories.map(async (category) => ({
3299
3143
  category,
3300
- products: await this.mountCategory(category, { limit, hasStock: true, gender }),
3144
+ products: await this.mountCategory(category, shop, { limit, hasStock: true }),
3301
3145
  })));
3302
3146
  return homeSections;
3303
3147
  }
3304
- async mountCategory(category, options) {
3148
+ async mountCategory(category, shop, options) {
3305
3149
  if (!category.products)
3306
3150
  throw new RequiredArgumentError(['Category products is empty']);
3307
3151
  const chunks = chunk(category.products, 10);
@@ -3345,13 +3189,13 @@ __decorate([
3345
3189
  __decorate([
3346
3190
  Log(),
3347
3191
  __metadata("design:type", Function),
3348
- __metadata("design:paramtypes", [Array, Object, String]),
3192
+ __metadata("design:paramtypes", [Array, String, Object]),
3349
3193
  __metadata("design:returntype", Promise)
3350
3194
  ], CategoryFirestoreRepository.prototype, "getCategoriesForHome", null);
3351
3195
  __decorate([
3352
3196
  Log(),
3353
3197
  __metadata("design:type", Function),
3354
- __metadata("design:paramtypes", [Category, Object]),
3198
+ __metadata("design:paramtypes", [Category, String, Object]),
3355
3199
  __metadata("design:returntype", Promise)
3356
3200
  ], CategoryFirestoreRepository.prototype, "mountCategory", null);
3357
3201
 
@@ -3450,6 +3294,101 @@ class SubscriptionProductFirestoreRepository extends withCrudFirestore(withHelpe
3450
3294
  }
3451
3295
  }
3452
3296
 
3297
+ class LogFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3298
+ constructor({ firestore, interceptors, }) {
3299
+ super({
3300
+ firestore,
3301
+ collectionName: 'logs',
3302
+ model: LogDocument,
3303
+ interceptors,
3304
+ });
3305
+ }
3306
+ }
3307
+
3308
+ class HomeFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3309
+ constructor({ firestore, interceptors }) {
3310
+ super({
3311
+ firestore,
3312
+ collectionName: 'dms',
3313
+ model: Home,
3314
+ interceptors,
3315
+ });
3316
+ this.homeCategoryGroupToPlain = (homeCategoryGroup) => {
3317
+ var _a, _b, _c;
3318
+ return ({
3319
+ category: ((_a = homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.category) === null || _a === void 0 ? void 0 : _a.toPlain)
3320
+ ? (_b = homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.category) === null || _b === void 0 ? void 0 : _b.toPlain()
3321
+ : homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.category,
3322
+ 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)) || [],
3323
+ });
3324
+ };
3325
+ this.plainToHomeCategoryGroup = (homeCategoryGroup) => {
3326
+ var _a;
3327
+ return ({
3328
+ category: Category.toInstance(homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.category),
3329
+ products: (_a = homeCategoryGroup.products) === null || _a === void 0 ? void 0 : _a.map((product) => Product.toInstance(product)),
3330
+ });
3331
+ };
3332
+ }
3333
+ buildModelInstance() {
3334
+ const { fromFirestore, toFirestore } = super.buildModelInstance();
3335
+ return {
3336
+ toFirestore: (data) => {
3337
+ const modifiedData = this.homeToFirestore(data);
3338
+ return toFirestore(modifiedData);
3339
+ },
3340
+ fromFirestore: (snap) => {
3341
+ const instance = fromFirestore(snap);
3342
+ return this.homeFromFirestore(instance);
3343
+ },
3344
+ };
3345
+ }
3346
+ homeToFirestore(home) {
3347
+ var _a, _b, _c, _d;
3348
+ if ((_a = home.data) === null || _a === void 0 ? void 0 : _a.data) {
3349
+ home.data.data.discoverProducts = ((_b = home.data.data.discoverProducts) === null || _b === void 0 ? void 0 : _b.map(this.homeCategoryGroupToPlain)) || [];
3350
+ home.data.data.featuredProducts = ((_c = home.data.data.featuredProducts) === null || _c === void 0 ? void 0 : _c.map(this.homeCategoryGroupToPlain)) || [];
3351
+ home.data.data.verticalProducts = ((_d = home.data.data.verticalProducts) === null || _d === void 0 ? void 0 : _d.map(this.homeCategoryGroupToPlain)) || [];
3352
+ }
3353
+ return home;
3354
+ }
3355
+ homeFromFirestore(home) {
3356
+ var _a;
3357
+ if ((_a = home.data) === null || _a === void 0 ? void 0 : _a.data) {
3358
+ home.data.data.discoverProducts = home.data.data.discoverProducts.map(this.plainToHomeCategoryGroup);
3359
+ home.data.data.featuredProducts = home.data.data.featuredProducts.map(this.plainToHomeCategoryGroup);
3360
+ home.data.data.verticalProducts = home.data.data.verticalProducts.map(this.plainToHomeCategoryGroup);
3361
+ home.data.createdAt =
3362
+ home.data.createdAt instanceof Timestamp ? home.data.createdAt.toDate() : home.data.createdAt;
3363
+ home.data.expiresAt =
3364
+ home.data.expiresAt instanceof Timestamp ? home.data.expiresAt.toDate() : home.data.expiresAt;
3365
+ }
3366
+ return home;
3367
+ }
3368
+ }
3369
+
3370
+ class ShopMenuFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3371
+ constructor({ firestore, interceptors }) {
3372
+ super({
3373
+ firestore,
3374
+ collectionName: 'shopMenus',
3375
+ model: ShopMenu,
3376
+ interceptors,
3377
+ });
3378
+ }
3379
+ }
3380
+
3381
+ class ShopSettingsFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3382
+ constructor({ firestore, interceptors, }) {
3383
+ super({
3384
+ firestore,
3385
+ collectionName: 'shopSettings',
3386
+ model: ShopSettings,
3387
+ interceptors,
3388
+ });
3389
+ }
3390
+ }
3391
+
3453
3392
  class Buy2WinFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3454
3393
  constructor({ firestore, interceptors }) {
3455
3394
  super({
@@ -3643,90 +3582,180 @@ class SubscriptionPlanFirestoreRepository extends withCrudFirestore(withHelpers(
3643
3582
  }
3644
3583
  }
3645
3584
 
3646
- class HomeFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3585
+ class LeadFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3647
3586
  constructor({ firestore, interceptors }) {
3648
3587
  super({
3649
3588
  firestore,
3650
- collectionName: 'dms',
3651
- model: Home,
3589
+ collectionName: 'leads',
3590
+ model: Lead,
3652
3591
  interceptors,
3653
3592
  });
3654
- this.homeCategoryGroupToPlain = (homeCategoryGroup) => {
3655
- var _a, _b, _c;
3656
- return ({
3657
- category: ((_a = homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.category) === null || _a === void 0 ? void 0 : _a.toPlain)
3658
- ? (_b = homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.category) === null || _b === void 0 ? void 0 : _b.toPlain()
3659
- : homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.category,
3660
- 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)) || [],
3661
- });
3662
- };
3663
- this.plainToHomeCategoryGroup = (homeCategoryGroup) => {
3664
- var _a;
3665
- return ({
3666
- category: Category.toInstance(homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.category),
3667
- products: (_a = homeCategoryGroup.products) === null || _a === void 0 ? void 0 : _a.map((product) => Product.toInstance(product)),
3668
- });
3669
- };
3670
- }
3671
- buildModelInstance() {
3672
- const { fromFirestore, toFirestore } = super.buildModelInstance();
3673
- return {
3674
- toFirestore: (data) => {
3675
- const modifiedData = this.homeToFirestore(data);
3676
- return toFirestore(modifiedData);
3677
- },
3678
- fromFirestore: (snap) => {
3679
- const instance = fromFirestore(snap);
3680
- return this.homeFromFirestore(instance);
3681
- },
3682
- };
3683
3593
  }
3684
- homeToFirestore(home) {
3685
- var _a, _b, _c, _d;
3686
- if ((_a = home.data) === null || _a === void 0 ? void 0 : _a.data) {
3687
- home.data.data.discoverProducts = ((_b = home.data.data.discoverProducts) === null || _b === void 0 ? void 0 : _b.map(this.homeCategoryGroupToPlain)) || [];
3688
- home.data.data.featuredProducts = ((_c = home.data.data.featuredProducts) === null || _c === void 0 ? void 0 : _c.map(this.homeCategoryGroupToPlain)) || [];
3689
- home.data.data.verticalProducts = ((_d = home.data.data.verticalProducts) === null || _d === void 0 ? void 0 : _d.map(this.homeCategoryGroupToPlain)) || [];
3690
- }
3691
- return home;
3594
+ }
3595
+
3596
+ class SubscriptionEditionFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
3597
+ constructor({ firestore, interceptors }, parentRepository) {
3598
+ super({
3599
+ firestore,
3600
+ collectionName: 'editions',
3601
+ parentIdField: 'subscriptionId',
3602
+ model: Edition,
3603
+ interceptors,
3604
+ });
3605
+ this.parentRepository = parentRepository;
3692
3606
  }
3693
- homeFromFirestore(home) {
3694
- var _a;
3695
- if ((_a = home.data) === null || _a === void 0 ? void 0 : _a.data) {
3696
- home.data.data.discoverProducts = home.data.data.discoverProducts.map(this.plainToHomeCategoryGroup);
3697
- home.data.data.featuredProducts = home.data.data.featuredProducts.map(this.plainToHomeCategoryGroup);
3698
- home.data.data.verticalProducts = home.data.data.verticalProducts.map(this.plainToHomeCategoryGroup);
3699
- home.data.createdAt =
3700
- home.data.createdAt instanceof Timestamp ? home.data.createdAt.toDate() : home.data.createdAt;
3701
- home.data.expiresAt =
3702
- home.data.expiresAt instanceof Timestamp ? home.data.expiresAt.toDate() : home.data.expiresAt;
3703
- }
3704
- return home;
3607
+ }
3608
+
3609
+ class SubscriptionFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3610
+ constructor({ firestore, interceptors, }) {
3611
+ super({
3612
+ firestore,
3613
+ collectionName: 'subscription',
3614
+ model: Subscription,
3615
+ interceptors,
3616
+ });
3705
3617
  }
3706
3618
  }
3707
3619
 
3708
- class ShopMenuFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3620
+ class SubscriptionMaterializationFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3709
3621
  constructor({ firestore, interceptors }) {
3710
3622
  super({
3711
3623
  firestore,
3712
- collectionName: 'shopMenus',
3713
- model: ShopMenu,
3624
+ collectionName: 'subscriptionMaterialization',
3625
+ model: SubscriptionMaterialization,
3714
3626
  interceptors,
3715
3627
  });
3716
3628
  }
3717
3629
  }
3718
3630
 
3719
- class ShopSettingsFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3631
+ class SubscriptionPaymentFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
3632
+ constructor({ firestore, interceptors }, parentRepository) {
3633
+ super({
3634
+ firestore,
3635
+ collectionName: 'payments',
3636
+ parentIdField: 'subscriptionId',
3637
+ model: SubscriptionPayment,
3638
+ interceptors,
3639
+ });
3640
+ this.parentRepository = parentRepository;
3641
+ }
3642
+ }
3643
+
3644
+ class SubscriptionSummaryFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3720
3645
  constructor({ firestore, interceptors, }) {
3721
3646
  super({
3722
3647
  firestore,
3723
- collectionName: 'shopSettings',
3724
- model: ShopSettings,
3648
+ collectionName: 'subscriptionSummary',
3649
+ model: SubscriptionSummary,
3725
3650
  interceptors,
3726
3651
  });
3727
3652
  }
3728
3653
  }
3729
3654
 
3655
+ class UserAddressFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
3656
+ constructor({ firestore, interceptors }, parentRepository) {
3657
+ super({
3658
+ firestore,
3659
+ collectionName: 'address',
3660
+ parentIdField: 'userId',
3661
+ model: UserAddress,
3662
+ interceptors,
3663
+ });
3664
+ this.parentRepository = parentRepository;
3665
+ }
3666
+ }
3667
+
3668
+ class UserBeautyProfileFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
3669
+ constructor({ firestore, interceptors }, parentRepository) {
3670
+ super({
3671
+ firestore,
3672
+ collectionName: 'CX',
3673
+ parentIdField: 'userId',
3674
+ model: BeautyProfile,
3675
+ interceptors,
3676
+ });
3677
+ this.parentRepository = parentRepository;
3678
+ }
3679
+ }
3680
+
3681
+ class UserFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3682
+ constructor({ firestore, interceptors }) {
3683
+ super({
3684
+ firestore,
3685
+ collectionName: 'users',
3686
+ model: User,
3687
+ interceptors,
3688
+ });
3689
+ }
3690
+ async get(identifiers) {
3691
+ const user = await super.get({ id: identifiers.id });
3692
+ user.beautyProfile = await this.getBeautyProfile(user.id);
3693
+ user.isSubscriber = await this.checkIfIsSubscriber(user.id);
3694
+ return user;
3695
+ }
3696
+ async checkIfExistsByField(field, value) {
3697
+ const result = await this.find({ filters: { [field]: value } });
3698
+ return result.count > 0;
3699
+ }
3700
+ buildModelInstance() {
3701
+ const { fromFirestore, toFirestore } = super.buildModelInstance();
3702
+ return {
3703
+ toFirestore: (data) => {
3704
+ const plain = toFirestore(data);
3705
+ delete plain.isSubscriber;
3706
+ return plain;
3707
+ },
3708
+ fromFirestore,
3709
+ };
3710
+ }
3711
+ async getBeautyProfile(userId) {
3712
+ const beautyProfile = await this.firestore
3713
+ .getCollection(`${this.collectionName}/${userId}/CX`)
3714
+ .withConverter(this.buildBeautyProfileModelInstance())
3715
+ .getDoc('beautyProfile')
3716
+ .get();
3717
+ return beautyProfile.data();
3718
+ }
3719
+ async checkIfIsSubscriber(userId) {
3720
+ const docs = await this.collection('subscription')
3721
+ .where('user.id', '==', userId)
3722
+ .where('status', '==', 'active')
3723
+ .getDocs();
3724
+ return !!docs && !!docs.size;
3725
+ }
3726
+ buildBeautyProfileModelInstance() {
3727
+ return {
3728
+ toFirestore: (data) => data.toPlain(),
3729
+ fromFirestore: (snap) => BeautyProfile.toInstance(snap.data()),
3730
+ };
3731
+ }
3732
+ }
3733
+ __decorate([
3734
+ Log(),
3735
+ __metadata("design:type", Function),
3736
+ __metadata("design:paramtypes", [Object]),
3737
+ __metadata("design:returntype", Promise)
3738
+ ], UserFirestoreRepository.prototype, "get", null);
3739
+ __decorate([
3740
+ Log(),
3741
+ __metadata("design:type", Function),
3742
+ __metadata("design:paramtypes", [String, String]),
3743
+ __metadata("design:returntype", Promise)
3744
+ ], UserFirestoreRepository.prototype, "checkIfExistsByField", null);
3745
+
3746
+ class UserPaymentMethodFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
3747
+ constructor({ firestore, interceptors }, parentRepository) {
3748
+ super({
3749
+ firestore,
3750
+ collectionName: 'payment_method',
3751
+ parentIdField: 'userId',
3752
+ model: UserPaymentMethod,
3753
+ interceptors,
3754
+ });
3755
+ this.parentRepository = parentRepository;
3756
+ }
3757
+ }
3758
+
3730
3759
  class ConnectBaseDocumentSnapshot {
3731
3760
  constructor(connectDocumentSnapshot) {
3732
3761
  this.connectDocumentSnapshot = connectDocumentSnapshot;
@@ -4914,7 +4943,7 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
4914
4943
  });
4915
4944
  return data;
4916
4945
  }
4917
- async getCategoriesForHome(categoryIds, limit = 4, gender) {
4946
+ async getCategoriesForHome(categoryIds, shop, limit = 4) {
4918
4947
  if (!(categoryIds === null || categoryIds === void 0 ? void 0 : categoryIds.length))
4919
4948
  return [];
4920
4949
  const categoriesFirestore = categoryIds.filter((categoryId) => Number.isNaN(+categoryId));
@@ -4926,22 +4955,32 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
4926
4955
  }).then(({ data }) => data)));
4927
4956
  if (categoriesHasura.length)
4928
4957
  categories.push(...(await this.find({
4929
- filters: { id: { operator: Where.IN, value: categoriesHasura.filter(Boolean) }, published: true },
4958
+ filters: {
4959
+ id: { operator: Where.IN, value: categoriesHasura.filter(Boolean) },
4960
+ published: true,
4961
+ },
4930
4962
  }).then(({ data }) => data)));
4931
4963
  if (!categories.length)
4932
4964
  return [];
4933
4965
  const homeSections = await Promise.all(categories.map(async (category) => ({
4934
4966
  category,
4935
- products: await this.mountCategory(category, { limit, hasStock: true, gender }),
4967
+ products: await this.mountCategory(category, shop, { limit, hasStock: true }),
4936
4968
  })));
4937
4969
  return homeSections;
4938
4970
  }
4939
- async mountCategory(category, options) {
4971
+ async mountCategory(category, shop, options) {
4940
4972
  var _a;
4941
4973
  if (!((_a = category === null || category === void 0 ? void 0 : category.products) === null || _a === void 0 ? void 0 : _a.length))
4942
4974
  return [];
4975
+ const mostRelevants = category.getMostRelevantByShop(shop);
4976
+ const mostRelevantProductsIds = [...new Set(mostRelevants.concat(category.products))];
4943
4977
  const products = [];
4944
- const { data: productsData } = await this.productRepository.find(Object.assign(Object.assign({ filters: Object.assign(Object.assign({ id: { operator: Where.IN, value: category.products }, published: true }, ((options === null || options === void 0 ? void 0 : options.hasStock) ? { stock: { quantity: { operator: Where.GT, value: 0 } } } : {})), ((options === null || options === void 0 ? void 0 : options.gender) ? { tags: { operator: Where.IN, value: [options === null || options === void 0 ? void 0 : options.gender] } } : {})), fields: [
4978
+ const { data: productsData } = await this.productRepository.find({
4979
+ filters: {
4980
+ id: { operator: Where.IN, value: mostRelevantProductsIds },
4981
+ published: true,
4982
+ },
4983
+ fields: [
4945
4984
  'id',
4946
4985
  'name',
4947
4986
  'slug',
@@ -4967,8 +5006,25 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
4967
5006
  'shoppingCount',
4968
5007
  'gender',
4969
5008
  'createdAt',
4970
- ] }, ((options === null || options === void 0 ? void 0 : options.limit) ? { limits: { limit: options === null || options === void 0 ? void 0 : options.limit } } : {})), { options: { enableCount: false } }));
4971
- products.push(...productsData);
5009
+ ],
5010
+ options: { enableCount: false },
5011
+ orderBy: {
5012
+ shoppingCount: 'desc',
5013
+ rate: 'desc',
5014
+ stock: 'desc',
5015
+ name: 'asc',
5016
+ },
5017
+ });
5018
+ const mostRelevantWithouyStock = productsData.filter((product) => mostRelevants.includes(product.id) && product.stock.quantity <= 0);
5019
+ const firstProducts = productsData
5020
+ .filter((product) => mostRelevants.includes(product.id) && product.stock.quantity > 0)
5021
+ .sort((a, b) => mostRelevants.indexOf(a.id) - mostRelevants.indexOf(b.id));
5022
+ const lastProducts = productsData
5023
+ .filter((product) => !mostRelevants.includes(product.id))
5024
+ .concat(mostRelevantWithouyStock);
5025
+ const categoryMostRelevants = firstProducts.concat(lastProducts);
5026
+ const resultFinal = categoryMostRelevants.slice(0, options.limit);
5027
+ products.push(...resultFinal);
4972
5028
  return products;
4973
5029
  }
4974
5030
  async getChildren(parentId) {
@@ -5143,13 +5199,13 @@ __decorate([
5143
5199
  __decorate([
5144
5200
  Log(),
5145
5201
  __metadata("design:type", Function),
5146
- __metadata("design:paramtypes", [Array, Object, String]),
5202
+ __metadata("design:paramtypes", [Array, String, Object]),
5147
5203
  __metadata("design:returntype", Promise)
5148
5204
  ], CategoryHasuraGraphQLRepository.prototype, "getCategoriesForHome", null);
5149
5205
  __decorate([
5150
5206
  Log(),
5151
5207
  __metadata("design:type", Function),
5152
- __metadata("design:paramtypes", [Category, Object]),
5208
+ __metadata("design:paramtypes", [Category, String, Object]),
5153
5209
  __metadata("design:returntype", Promise)
5154
5210
  ], CategoryHasuraGraphQLRepository.prototype, "mountCategory", null);
5155
5211
  __decorate([
@@ -6280,10 +6336,10 @@ class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
6280
6336
  value: [PersonTypes.BFLU, PersonTypes.GLAMGIRL],
6281
6337
  } }), orderBy: Object.assign({ personHasPhoto: 'desc' }, omit(params.orderBy, ['personHasPhoto'])) }));
6282
6338
  }
6283
- getCategoriesForHome(categoryIds, limit, gender) {
6339
+ getCategoriesForHome(categoryIds, gender, limit) {
6284
6340
  return;
6285
6341
  }
6286
- mountCategory(category, options) {
6342
+ mountCategory(category, shop, options) {
6287
6343
  return;
6288
6344
  }
6289
6345
  getChildren(parentId) {
@@ -6544,4 +6600,4 @@ class ProductsVertexSearch {
6544
6600
  }
6545
6601
  }
6546
6602
 
6547
- export { AccessoryImportances, Address, Area, Authentication, AuthenticationFirebaseAuthService, AxiosAdapter, Base, BaseModel, BeardProblems, BeardSizes, BeautyProductImportances, BeautyProfile, BeautyQuestionsHelper, BillingStatus, BodyProblems, BodyShapes, BodyTattoos, Buy2Win, Buy2WinFirestoreRepository, Campaign, CampaignBanner, CampaignDashboard, CampaignDashboardFirestoreRepository, CampaignHashtag, CampaignHashtagFirestoreRepository, Category, CategoryCollectionChildren, CategoryCollectionChildrenHasuraGraphQLRepository, CategoryFilter, CategoryFilterHasuraGraphQLRepository, CategoryFirestoreRepository, CategoryHasuraGraphQL, CategoryHasuraGraphQLRepository, Checkout, CheckoutFirestoreRepository, CheckoutSubscription, CheckoutSubscriptionFirestoreRepository, CheckoutTypes, ClassNameHelper, ConnectBaseDocumentSnapshot, ConnectCollectionService, ConnectDocumentService, ConnectFirestoreService, Coupon, CouponCategory, CouponFirestoreRepository, CouponSubtypes, CouponTypes, Debug, DebugDecoratorHelper, DebugHelper, DebugNamespaces, DuplicatedResultsError, Edition, EditionStatus, Exclusivities, FaceSkinOilinesses, FaceSkinProblems, FaceSkinTones, FamilyIncomes, Filter, FilterHasuraGraphQLRepository, FilterOption, FilterOptionHasuraGraphQLRepository, FilterType, FirebaseFileUploaderService, FragranceImportances, GenderDestination, HairColors, HairProblems, HairStrands, HairTypes, Home, HomeFirestoreRepository, InvalidArgumentError, KitProduct, KitProductHasuraGraphQL, Lead, LeadFirestoreRepository, LegacyOrderFirestoreRepository, LineItem, Log, Logger, NotFoundError, OfficePosition, Order, OrderBlocked, OrderBlockedFirestoreRepository, OrderFirestoreRepository, OrderStatus, Payment, PaymentFirestoreRepository, PaymentType, PersonTypes, Plans, Product, ProductFirestoreRepository, ProductHasuraGraphQL, ProductHasuraGraphQLRepository, ProductReviews, ProductReviewsHasuraGraphQLRepository, ProductSpents, ProductStockNotification, ProductStockNotificationHasuraGraphQLRepository, ProductVariantFirestoreRepository, ProductsIndex, ProductsVertexSearch, QuestionsFilters, RecoveryPassword, ReflectHelper, Register, RegisterFirebaseAuthService, RequiredArgumentError, RoundProductPricesHelper, ShippingMethod, ShopMenu, ShopMenuFirestoreRepository, ShopPageName, ShopSettings, ShopSettingsFirestoreRepository, Shops, SignInMethods, SignOut, Status, Subscription, SubscriptionEditionFirestoreRepository, SubscriptionFirestoreRepository, SubscriptionMaterialization, SubscriptionMaterializationFirestoreRepository, SubscriptionPayment, SubscriptionPaymentFirestoreRepository, SubscriptionPlan, SubscriptionPlanFirestoreRepository, SubscriptionProductFirestoreRepository, SubscriptionSummary, SubscriptionSummaryFirestoreRepository, Trace, UnauthorizedError, UpdateOptionActions, UpdateUserImage, User, UserAddress, UserAddressFirestoreRepository, UserAlreadyRegisteredError, UserBeautyProfileFirestoreRepository, UserFirestoreRepository, UserPaymentMethod, UserPaymentMethodFirestoreRepository, UserType, Variant, VariantHasuraGraphQL, VariantHasuraGraphQLRepository, VertexAxiosAdapter, WeakPasswordError, Where, Wishlist, WishlistHasuraGraphQLRepository, is, isDebuggable, isUUID, parseDateTime, withCreateFirestore, withCreateHasuraGraphQL, withCrudFirestore, withCrudHasuraGraphQL, withDeleteFirestore, withDeleteHasuraGraphQL, withFindFirestore, withFindHasuraGraphQL, withFirestore, withGetFirestore, withGetHasuraGraphQL, withHasuraGraphQL, withHelpers, withSubCollection, withUpdateFirestore, withUpdateHasuraGraphQL };
6603
+ export { AccessoryImportances, Address, Area, Authentication, AuthenticationFirebaseAuthService, AxiosAdapter, Base, BaseModel, BeardProblems, BeardSizes, BeautyProductImportances, BeautyProfile, BeautyQuestionsHelper, BillingStatus, BodyProblems, BodyShapes, BodyTattoos, Buy2Win, Buy2WinFirestoreRepository, Campaign, CampaignBanner, CampaignDashboard, CampaignDashboardFirestoreRepository, CampaignHashtag, CampaignHashtagFirestoreRepository, Category, CategoryCollectionChildren, CategoryCollectionChildrenHasuraGraphQLRepository, CategoryFilter, CategoryFilterHasuraGraphQLRepository, CategoryFirestoreRepository, CategoryHasuraGraphQL, CategoryHasuraGraphQLRepository, Checkout, CheckoutFirestoreRepository, CheckoutSubscription, CheckoutSubscriptionFirestoreRepository, CheckoutTypes, ClassNameHelper, ConnectBaseDocumentSnapshot, ConnectCollectionService, ConnectDocumentService, ConnectFirestoreService, Coupon, CouponCategory, CouponFirestoreRepository, CouponSubtypes, CouponTypes, Debug, DebugDecoratorHelper, DebugHelper, DebugNamespaces, DuplicatedResultsError, Edition, EditionStatus, Exclusivities, FaceSkinOilinesses, FaceSkinProblems, FaceSkinTones, FamilyIncomes, Filter, FilterHasuraGraphQLRepository, FilterOption, FilterOptionHasuraGraphQLRepository, FilterType, FirebaseFileUploaderService, FragranceImportances, GenderDestination, HairColors, HairProblems, HairStrands, HairTypes, Home, HomeFirestoreRepository, InvalidArgumentError, KitProduct, KitProductHasuraGraphQL, Lead, LeadFirestoreRepository, LegacyOrderFirestoreRepository, LineItem, Log, LogDocument, LogFirestoreRepository, Logger, NotFoundError, OfficePosition, Order, OrderBlocked, OrderBlockedFirestoreRepository, OrderFirestoreRepository, OrderStatus, Payment, PaymentFirestoreRepository, PaymentType, PersonTypes, Plans, Product, ProductFirestoreRepository, ProductHasuraGraphQL, ProductHasuraGraphQLRepository, ProductReviews, ProductReviewsHasuraGraphQLRepository, ProductSpents, ProductStockNotification, ProductStockNotificationHasuraGraphQLRepository, ProductVariantFirestoreRepository, ProductsIndex, ProductsVertexSearch, QuestionsFilters, RecoveryPassword, ReflectHelper, Register, RegisterFirebaseAuthService, RequiredArgumentError, RoundProductPricesHelper, ShippingMethod, ShopMenu, ShopMenuFirestoreRepository, ShopPageName, ShopSettings, ShopSettingsFirestoreRepository, Shops, SignInMethods, SignOut, Status, Subscription, SubscriptionEditionFirestoreRepository, SubscriptionFirestoreRepository, SubscriptionMaterialization, SubscriptionMaterializationFirestoreRepository, SubscriptionPayment, SubscriptionPaymentFirestoreRepository, SubscriptionPlan, SubscriptionPlanFirestoreRepository, SubscriptionProductFirestoreRepository, SubscriptionSummary, SubscriptionSummaryFirestoreRepository, Trace, UnauthorizedError, UpdateOptionActions, UpdateUserImage, User, UserAddress, UserAddressFirestoreRepository, UserAlreadyRegisteredError, UserBeautyProfileFirestoreRepository, UserFirestoreRepository, UserPaymentMethod, UserPaymentMethodFirestoreRepository, UserType, Variant, VariantHasuraGraphQL, VariantHasuraGraphQLRepository, VertexAxiosAdapter, WeakPasswordError, Where, Wishlist, WishlistHasuraGraphQLRepository, WishlistLogType, is, isDebuggable, isUUID, parseDateTime, withCreateFirestore, withCreateHasuraGraphQL, withCrudFirestore, withCrudHasuraGraphQL, withDeleteFirestore, withDeleteHasuraGraphQL, withFindFirestore, withFindHasuraGraphQL, withFirestore, withGetFirestore, withGetHasuraGraphQL, withHasuraGraphQL, withHelpers, withSubCollection, withUpdateFirestore, withUpdateHasuraGraphQL };