@infrab4a/connect 4.17.0-beta.0 → 4.17.1

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.cjs.js CHANGED
@@ -2139,6 +2139,9 @@ exports.CouponCategory = void 0;
2139
2139
  CouponCategory["Desculpas"] = "Desculpas";
2140
2140
  CouponCategory["BFlu"] = "BFlu";
2141
2141
  CouponCategory["ROYAL"] = "Royal";
2142
+ CouponCategory["Glamqueen"] = "Glamqueen";
2143
+ CouponCategory["Glampartner"] = "Glampartner";
2144
+ CouponCategory["Glamgirl"] = "Glamgirl";
2142
2145
  CouponCategory["Glamdiva"] = "Glamdiva";
2143
2146
  CouponCategory["Impulsionamento"] = "Impulsionamento";
2144
2147
  CouponCategory["PaidMedia"] = "Paid Media";
@@ -3134,7 +3137,7 @@ class CategoryFirestoreRepository extends withCrudFirestore(withHelpers(withFire
3134
3137
  throw new NotFoundError(`Document with slug ${slug} not found`);
3135
3138
  return categoryDocs.docs[0].data();
3136
3139
  }
3137
- async getCategoriesForHome(categoryIds, limit = 4, gender) {
3140
+ async getCategoriesForHome(categoryIds, shop, limit = 4) {
3138
3141
  const categorySnap = await this.collection(this.collectionName)
3139
3142
  .where('id', 'in', categoryIds.filter(Boolean))
3140
3143
  .where('published', '==', true)
@@ -3144,11 +3147,11 @@ class CategoryFirestoreRepository extends withCrudFirestore(withHelpers(withFire
3144
3147
  const categories = categorySnap.docs.map((doc) => doc.data());
3145
3148
  const homeSections = await Promise.all(categories.map(async (category) => ({
3146
3149
  category,
3147
- products: await this.mountCategory(category, { limit, hasStock: true, gender }),
3150
+ products: await this.mountCategory(category, shop, { limit, hasStock: true }),
3148
3151
  })));
3149
3152
  return homeSections;
3150
3153
  }
3151
- async mountCategory(category, options) {
3154
+ async mountCategory(category, shop, options) {
3152
3155
  if (!category.products)
3153
3156
  throw new RequiredArgumentError(['Category products is empty']);
3154
3157
  const chunks = lodash.chunk(category.products, 10);
@@ -3192,13 +3195,13 @@ tslib.__decorate([
3192
3195
  tslib.__decorate([
3193
3196
  Log(),
3194
3197
  tslib.__metadata("design:type", Function),
3195
- tslib.__metadata("design:paramtypes", [Array, Object, String]),
3198
+ tslib.__metadata("design:paramtypes", [Array, String, Object]),
3196
3199
  tslib.__metadata("design:returntype", Promise)
3197
3200
  ], CategoryFirestoreRepository.prototype, "getCategoriesForHome", null);
3198
3201
  tslib.__decorate([
3199
3202
  Log(),
3200
3203
  tslib.__metadata("design:type", Function),
3201
- tslib.__metadata("design:paramtypes", [Category, Object]),
3204
+ tslib.__metadata("design:paramtypes", [Category, String, Object]),
3202
3205
  tslib.__metadata("design:returntype", Promise)
3203
3206
  ], CategoryFirestoreRepository.prototype, "mountCategory", null);
3204
3207
 
@@ -4946,7 +4949,7 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
4946
4949
  });
4947
4950
  return data;
4948
4951
  }
4949
- async getCategoriesForHome(categoryIds, limit = 4, gender) {
4952
+ async getCategoriesForHome(categoryIds, shop, limit = 4) {
4950
4953
  if (!(categoryIds === null || categoryIds === void 0 ? void 0 : categoryIds.length))
4951
4954
  return [];
4952
4955
  const categoriesFirestore = categoryIds.filter((categoryId) => Number.isNaN(+categoryId));
@@ -4958,22 +4961,32 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
4958
4961
  }).then(({ data }) => data)));
4959
4962
  if (categoriesHasura.length)
4960
4963
  categories.push(...(await this.find({
4961
- filters: { id: { operator: exports.Where.IN, value: categoriesHasura.filter(Boolean) }, published: true },
4964
+ filters: {
4965
+ id: { operator: exports.Where.IN, value: categoriesHasura.filter(Boolean) },
4966
+ published: true,
4967
+ },
4962
4968
  }).then(({ data }) => data)));
4963
4969
  if (!categories.length)
4964
4970
  return [];
4965
4971
  const homeSections = await Promise.all(categories.map(async (category) => ({
4966
4972
  category,
4967
- products: await this.mountCategory(category, { limit, hasStock: true, gender }),
4973
+ products: await this.mountCategory(category, shop, { limit, hasStock: true }),
4968
4974
  })));
4969
4975
  return homeSections;
4970
4976
  }
4971
- async mountCategory(category, options) {
4977
+ async mountCategory(category, shop, options) {
4972
4978
  var _a;
4973
4979
  if (!((_a = category === null || category === void 0 ? void 0 : category.products) === null || _a === void 0 ? void 0 : _a.length))
4974
4980
  return [];
4981
+ const mostRelevants = category.getMostRelevantByShop(shop);
4982
+ const mostRelevantProductsIds = [...new Set(mostRelevants.concat(category.products))];
4975
4983
  const products = [];
4976
- 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: [
4984
+ const { data: productsData } = await this.productRepository.findCatalog({
4985
+ filters: {
4986
+ id: { operator: exports.Where.IN, value: mostRelevantProductsIds },
4987
+ published: true,
4988
+ },
4989
+ fields: [
4977
4990
  'id',
4978
4991
  'name',
4979
4992
  'slug',
@@ -4999,8 +5012,25 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
4999
5012
  'shoppingCount',
5000
5013
  'gender',
5001
5014
  'createdAt',
5002
- ] }, ((options === null || options === void 0 ? void 0 : options.limit) ? { limits: { limit: options === null || options === void 0 ? void 0 : options.limit } } : {})), { options: { enableCount: false } }));
5003
- products.push(...productsData);
5015
+ ],
5016
+ options: { enableCount: false },
5017
+ orderBy: {
5018
+ shoppingCount: 'desc',
5019
+ rate: 'desc',
5020
+ stock: 'desc',
5021
+ name: 'asc',
5022
+ },
5023
+ }, shop === exports.Shops.MENSMARKET ? 'male' : 'female');
5024
+ const mostRelevantWithouyStock = productsData.filter((product) => mostRelevants.includes(product.id) && product.stock.quantity <= 0);
5025
+ const firstProducts = productsData
5026
+ .filter((product) => mostRelevants.includes(product.id) && product.stock.quantity > 0)
5027
+ .sort((a, b) => mostRelevants.indexOf(a.id) - mostRelevants.indexOf(b.id));
5028
+ const lastProducts = productsData
5029
+ .filter((product) => !mostRelevants.includes(product.id) && product.stock.quantity > 0)
5030
+ .concat(mostRelevantWithouyStock);
5031
+ const categoryMostRelevants = firstProducts.concat(lastProducts);
5032
+ const resultFinal = categoryMostRelevants.slice(0, options.limit);
5033
+ products.push(...resultFinal);
5004
5034
  return products;
5005
5035
  }
5006
5036
  async getChildren(parentId) {
@@ -5175,13 +5205,13 @@ tslib.__decorate([
5175
5205
  tslib.__decorate([
5176
5206
  Log(),
5177
5207
  tslib.__metadata("design:type", Function),
5178
- tslib.__metadata("design:paramtypes", [Array, Object, String]),
5208
+ tslib.__metadata("design:paramtypes", [Array, String, Object]),
5179
5209
  tslib.__metadata("design:returntype", Promise)
5180
5210
  ], CategoryHasuraGraphQLRepository.prototype, "getCategoriesForHome", null);
5181
5211
  tslib.__decorate([
5182
5212
  Log(),
5183
5213
  tslib.__metadata("design:type", Function),
5184
- tslib.__metadata("design:paramtypes", [Category, Object]),
5214
+ tslib.__metadata("design:paramtypes", [Category, String, Object]),
5185
5215
  tslib.__metadata("design:returntype", Promise)
5186
5216
  ], CategoryHasuraGraphQLRepository.prototype, "mountCategory", null);
5187
5217
  tslib.__decorate([
@@ -6312,10 +6342,10 @@ class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
6312
6342
  value: [exports.PersonTypes.BFLU, exports.PersonTypes.GLAMGIRL],
6313
6343
  } }), orderBy: Object.assign({ personHasPhoto: 'desc' }, lodash.omit(params.orderBy, ['personHasPhoto'])) }));
6314
6344
  }
6315
- getCategoriesForHome(categoryIds, limit, gender) {
6345
+ getCategoriesForHome(categoryIds, gender, limit) {
6316
6346
  return;
6317
6347
  }
6318
- mountCategory(category, options) {
6348
+ mountCategory(category, shop, options) {
6319
6349
  return;
6320
6350
  }
6321
6351
  getChildren(parentId) {
package/index.esm.js CHANGED
@@ -2133,6 +2133,9 @@ var CouponCategory;
2133
2133
  CouponCategory["Desculpas"] = "Desculpas";
2134
2134
  CouponCategory["BFlu"] = "BFlu";
2135
2135
  CouponCategory["ROYAL"] = "Royal";
2136
+ CouponCategory["Glamqueen"] = "Glamqueen";
2137
+ CouponCategory["Glampartner"] = "Glampartner";
2138
+ CouponCategory["Glamgirl"] = "Glamgirl";
2136
2139
  CouponCategory["Glamdiva"] = "Glamdiva";
2137
2140
  CouponCategory["Impulsionamento"] = "Impulsionamento";
2138
2141
  CouponCategory["PaidMedia"] = "Paid Media";
@@ -3128,7 +3131,7 @@ class CategoryFirestoreRepository extends withCrudFirestore(withHelpers(withFire
3128
3131
  throw new NotFoundError(`Document with slug ${slug} not found`);
3129
3132
  return categoryDocs.docs[0].data();
3130
3133
  }
3131
- async getCategoriesForHome(categoryIds, limit = 4, gender) {
3134
+ async getCategoriesForHome(categoryIds, shop, limit = 4) {
3132
3135
  const categorySnap = await this.collection(this.collectionName)
3133
3136
  .where('id', 'in', categoryIds.filter(Boolean))
3134
3137
  .where('published', '==', true)
@@ -3138,11 +3141,11 @@ class CategoryFirestoreRepository extends withCrudFirestore(withHelpers(withFire
3138
3141
  const categories = categorySnap.docs.map((doc) => doc.data());
3139
3142
  const homeSections = await Promise.all(categories.map(async (category) => ({
3140
3143
  category,
3141
- products: await this.mountCategory(category, { limit, hasStock: true, gender }),
3144
+ products: await this.mountCategory(category, shop, { limit, hasStock: true }),
3142
3145
  })));
3143
3146
  return homeSections;
3144
3147
  }
3145
- async mountCategory(category, options) {
3148
+ async mountCategory(category, shop, options) {
3146
3149
  if (!category.products)
3147
3150
  throw new RequiredArgumentError(['Category products is empty']);
3148
3151
  const chunks = chunk(category.products, 10);
@@ -3186,13 +3189,13 @@ __decorate([
3186
3189
  __decorate([
3187
3190
  Log(),
3188
3191
  __metadata("design:type", Function),
3189
- __metadata("design:paramtypes", [Array, Object, String]),
3192
+ __metadata("design:paramtypes", [Array, String, Object]),
3190
3193
  __metadata("design:returntype", Promise)
3191
3194
  ], CategoryFirestoreRepository.prototype, "getCategoriesForHome", null);
3192
3195
  __decorate([
3193
3196
  Log(),
3194
3197
  __metadata("design:type", Function),
3195
- __metadata("design:paramtypes", [Category, Object]),
3198
+ __metadata("design:paramtypes", [Category, String, Object]),
3196
3199
  __metadata("design:returntype", Promise)
3197
3200
  ], CategoryFirestoreRepository.prototype, "mountCategory", null);
3198
3201
 
@@ -4940,7 +4943,7 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
4940
4943
  });
4941
4944
  return data;
4942
4945
  }
4943
- async getCategoriesForHome(categoryIds, limit = 4, gender) {
4946
+ async getCategoriesForHome(categoryIds, shop, limit = 4) {
4944
4947
  if (!(categoryIds === null || categoryIds === void 0 ? void 0 : categoryIds.length))
4945
4948
  return [];
4946
4949
  const categoriesFirestore = categoryIds.filter((categoryId) => Number.isNaN(+categoryId));
@@ -4952,22 +4955,32 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
4952
4955
  }).then(({ data }) => data)));
4953
4956
  if (categoriesHasura.length)
4954
4957
  categories.push(...(await this.find({
4955
- 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
+ },
4956
4962
  }).then(({ data }) => data)));
4957
4963
  if (!categories.length)
4958
4964
  return [];
4959
4965
  const homeSections = await Promise.all(categories.map(async (category) => ({
4960
4966
  category,
4961
- products: await this.mountCategory(category, { limit, hasStock: true, gender }),
4967
+ products: await this.mountCategory(category, shop, { limit, hasStock: true }),
4962
4968
  })));
4963
4969
  return homeSections;
4964
4970
  }
4965
- async mountCategory(category, options) {
4971
+ async mountCategory(category, shop, options) {
4966
4972
  var _a;
4967
4973
  if (!((_a = category === null || category === void 0 ? void 0 : category.products) === null || _a === void 0 ? void 0 : _a.length))
4968
4974
  return [];
4975
+ const mostRelevants = category.getMostRelevantByShop(shop);
4976
+ const mostRelevantProductsIds = [...new Set(mostRelevants.concat(category.products))];
4969
4977
  const products = [];
4970
- 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.findCatalog({
4979
+ filters: {
4980
+ id: { operator: Where.IN, value: mostRelevantProductsIds },
4981
+ published: true,
4982
+ },
4983
+ fields: [
4971
4984
  'id',
4972
4985
  'name',
4973
4986
  'slug',
@@ -4993,8 +5006,25 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
4993
5006
  'shoppingCount',
4994
5007
  'gender',
4995
5008
  'createdAt',
4996
- ] }, ((options === null || options === void 0 ? void 0 : options.limit) ? { limits: { limit: options === null || options === void 0 ? void 0 : options.limit } } : {})), { options: { enableCount: false } }));
4997
- products.push(...productsData);
5009
+ ],
5010
+ options: { enableCount: false },
5011
+ orderBy: {
5012
+ shoppingCount: 'desc',
5013
+ rate: 'desc',
5014
+ stock: 'desc',
5015
+ name: 'asc',
5016
+ },
5017
+ }, shop === Shops.MENSMARKET ? 'male' : 'female');
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) && product.stock.quantity > 0)
5024
+ .concat(mostRelevantWithouyStock);
5025
+ const categoryMostRelevants = firstProducts.concat(lastProducts);
5026
+ const resultFinal = categoryMostRelevants.slice(0, options.limit);
5027
+ products.push(...resultFinal);
4998
5028
  return products;
4999
5029
  }
5000
5030
  async getChildren(parentId) {
@@ -5169,13 +5199,13 @@ __decorate([
5169
5199
  __decorate([
5170
5200
  Log(),
5171
5201
  __metadata("design:type", Function),
5172
- __metadata("design:paramtypes", [Array, Object, String]),
5202
+ __metadata("design:paramtypes", [Array, String, Object]),
5173
5203
  __metadata("design:returntype", Promise)
5174
5204
  ], CategoryHasuraGraphQLRepository.prototype, "getCategoriesForHome", null);
5175
5205
  __decorate([
5176
5206
  Log(),
5177
5207
  __metadata("design:type", Function),
5178
- __metadata("design:paramtypes", [Category, Object]),
5208
+ __metadata("design:paramtypes", [Category, String, Object]),
5179
5209
  __metadata("design:returntype", Promise)
5180
5210
  ], CategoryHasuraGraphQLRepository.prototype, "mountCategory", null);
5181
5211
  __decorate([
@@ -6306,10 +6336,10 @@ class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
6306
6336
  value: [PersonTypes.BFLU, PersonTypes.GLAMGIRL],
6307
6337
  } }), orderBy: Object.assign({ personHasPhoto: 'desc' }, omit(params.orderBy, ['personHasPhoto'])) }));
6308
6338
  }
6309
- getCategoriesForHome(categoryIds, limit, gender) {
6339
+ getCategoriesForHome(categoryIds, gender, limit) {
6310
6340
  return;
6311
6341
  }
6312
- mountCategory(category, options) {
6342
+ mountCategory(category, shop, options) {
6313
6343
  return;
6314
6344
  }
6315
6345
  getChildren(parentId) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@infrab4a/connect",
3
- "version": "4.17.0-beta.0",
3
+ "version": "4.17.1",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org"
6
6
  },
@@ -5,11 +5,11 @@ import { Shops } from '../models/enums/shops.enum';
5
5
  export interface CategoryRepository<T extends Category = Category> extends CrudRepository<T> {
6
6
  getCategoryBySlug(slug: string, shop: Shops): Promise<Category>;
7
7
  getCategoryByShop(shop: string): Promise<Category[]>;
8
- getCategoriesForHome(categoryIds: string[], limit?: number, gender?: string): Promise<{
8
+ getCategoriesForHome(categoryIds: string[], shop: Shops, limit?: number): Promise<{
9
9
  category: Category;
10
10
  products: Product[];
11
11
  }[]>;
12
- mountCategory(category: Category, options?: {
12
+ mountCategory(category: Category, shop: Shops, options?: {
13
13
  limit?: number;
14
14
  hasStock?: boolean;
15
15
  }): Promise<Product[]>;
@@ -3,6 +3,9 @@ export declare enum CouponCategory {
3
3
  Desculpas = "Desculpas",
4
4
  BFlu = "BFlu",
5
5
  ROYAL = "Royal",
6
+ Glamqueen = "Glamqueen",
7
+ Glampartner = "Glampartner",
8
+ Glamgirl = "Glamgirl",
6
9
  Glamdiva = "Glamdiva",
7
10
  Impulsionamento = "Impulsionamento",
8
11
  PaidMedia = "Paid Media",
@@ -4,11 +4,11 @@ declare const CategoryFirestoreRepository_base: import("../../../../../utils").M
4
4
  export declare class CategoryFirestoreRepository extends CategoryFirestoreRepository_base implements CategoryRepository {
5
5
  constructor({ firestore, interceptors }: Pick<FirestoreConstructorParams<Category>, 'firestore' | 'interceptors'>);
6
6
  getCategoryBySlug(slug: string, shop: Shops): Promise<Category>;
7
- getCategoriesForHome(categoryIds: string[], limit?: number, gender?: string): Promise<{
7
+ getCategoriesForHome(categoryIds: string[], shop: Shops, limit?: number): Promise<{
8
8
  category: Category;
9
9
  products: Product[];
10
10
  }[]>;
11
- mountCategory(category: Category, options?: {
11
+ mountCategory(category: Category, shop: Shops, options?: {
12
12
  limit?: number;
13
13
  hasStock?: boolean;
14
14
  gender?: string;
@@ -15,11 +15,11 @@ export declare class CategoryHasuraGraphQLRepository extends CategoryHasuraGraph
15
15
  update(params: UpdateRepositoryParams<CategoryHasuraGraphQL>): Promise<CategoryHasuraGraphQL>;
16
16
  getCategoryBySlug(slug: string, shop: Shops): Promise<Category>;
17
17
  getCategoryByShop(shop: string): Promise<Category[]>;
18
- getCategoriesForHome(categoryIds: string[], limit?: number, gender?: string): Promise<{
18
+ getCategoriesForHome(categoryIds: string[], shop: Shops, limit?: number): Promise<{
19
19
  category: Category;
20
20
  products: Product[];
21
21
  }[]>;
22
- mountCategory(category: Category, options?: {
22
+ mountCategory(category: Category, shop: Shops, options?: {
23
23
  limit?: number;
24
24
  hasStock?: boolean;
25
25
  gender?: string;
@@ -17,8 +17,8 @@ export declare class WishlistHasuraGraphQLRepository extends WishlistHasuraGraph
17
17
  getCategoryBySlug(slug: string, _shop: Shops): Promise<Wishlist>;
18
18
  getCategoryByShop(shop: string): Promise<any>;
19
19
  findBfluOrGlamgirlWishlists(params: FindRepositoryParams<WishlistHasuraGraphQL>, shops: Shops[]): Promise<RepositoryFindResult<WishlistHasuraGraphQL>>;
20
- getCategoriesForHome(categoryIds: string[], limit?: number, gender?: string): any;
21
- mountCategory(category: Category, options?: {
20
+ getCategoriesForHome(categoryIds: string[], gender?: string, limit?: number): any;
21
+ mountCategory(category: Category, shop: Shops, options?: {
22
22
  limit?: number;
23
23
  hasStock?: boolean;
24
24
  }): Promise<Product[]>;