@infrab4a/connect 3.14.4 → 3.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1687,7 +1687,7 @@ class ProductsIndex {
1687
1687
  }
1688
1688
  search(searchTerm, total, shop) {
1689
1689
  return __awaiter(this, void 0, void 0, function* () {
1690
- const size = total >= 10 ? 500 : 9;
1690
+ const size = total || 9;
1691
1691
  const fields = [
1692
1692
  'EAN',
1693
1693
  'brand',
@@ -3171,17 +3171,27 @@ const withFindHasuraGraphQL = (MixinBase) => {
3171
3171
  : []),
3172
3172
  ];
3173
3173
  };
3174
+ this.bindDistinctAttributes = (distinct, fields) => this.bindAttributesToColumns(distinct, fields);
3174
3175
  this.bindAttributesToColumns = (attributes, fields) => attributes.map((attr) => {
3175
3176
  var _a;
3176
3177
  return ((_a = AttributeOptionHelper.FindByAttribute(attr.toString().split('.').pop(), fields)) === null || _a === void 0 ? void 0 : _a.columnName) || attr;
3177
3178
  });
3178
3179
  }
3179
3180
  find(params) {
3180
- var _a, _b, _c;
3181
+ var _a, _b, _c, _d, _e, _f, _g, _h;
3181
3182
  return __awaiter(this, void 0, void 0, function* () {
3182
3183
  this.logger = DebugHelper.from(this, 'find');
3183
3184
  const { filters, limits, orderBy, options } = params || {};
3184
3185
  const enableCount = (_a = options === null || options === void 0 ? void 0 : options.enableCount) !== null && _a !== void 0 ? _a : true;
3186
+ const variablesFilters = isNil(filters)
3187
+ ? {}
3188
+ : {
3189
+ where: {
3190
+ value: BindFilterQueryHelper.MakeGraphQLWhere(filters, this.fields),
3191
+ type: `${this.tableName}_bool_exp`,
3192
+ required: true,
3193
+ },
3194
+ };
3185
3195
  const variablesCount = Object.assign(Object.assign({}, (isNil(orderBy)
3186
3196
  ? {}
3187
3197
  : {
@@ -3190,15 +3200,7 @@ const withFindHasuraGraphQL = (MixinBase) => {
3190
3200
  list: true,
3191
3201
  value: this.bindOrderByAttributes(orderBy, this.fields),
3192
3202
  },
3193
- })), (isNil(filters)
3194
- ? {}
3195
- : {
3196
- where: {
3197
- value: BindFilterQueryHelper.MakeGraphQLWhere(filters, this.fields),
3198
- type: `${this.tableName}_bool_exp`,
3199
- required: true,
3200
- },
3201
- }));
3203
+ })), variablesFilters);
3202
3204
  const variables = Object.assign(Object.assign({}, (isNil(limits) ? {} : limits)), variablesCount);
3203
3205
  const aggregateFields = [
3204
3206
  ...(enableCount ? ['count'] : []),
@@ -3230,23 +3232,51 @@ const withFindHasuraGraphQL = (MixinBase) => {
3230
3232
  },
3231
3233
  ]
3232
3234
  : []),
3235
+ ...((!((_b = params.limits) === null || _b === void 0 ? void 0 : _b.offset) &&
3236
+ ((_d = (_c = params.options) === null || _c === void 0 ? void 0 : _c.distinct) === null || _d === void 0 ? void 0 : _d.map((distinct) => {
3237
+ var _a, _b;
3238
+ const distinctOption = (_a = this.fields.find((fieldOption) => fieldOption === distinct)) !== null && _a !== void 0 ? _a : this.fields.find((fieldOption) => Object.keys(fieldOption).shift() === distinct);
3239
+ const fieldName = ((_b = Object.values(distinctOption).shift()) === null || _b === void 0 ? void 0 : _b.columnName) || distinct;
3240
+ return {
3241
+ operation: {
3242
+ name: `${this.tableName}`,
3243
+ alias: `${this.tableName}_${distinct}_distinct`,
3244
+ },
3245
+ fields: [distinctOption],
3246
+ variables: Object.assign(Object.assign({}, variablesFilters), { [`${this.tableName}_${fieldName}_distinct`]: {
3247
+ type: `${this.tableName}_select_column!`,
3248
+ list: true,
3249
+ value: fieldName,
3250
+ name: 'distinct_on',
3251
+ } }),
3252
+ };
3253
+ }))) ||
3254
+ []),
3233
3255
  ]);
3234
3256
  const data = result[this.tableName].map((row) => this.convertDataFromHasura(row));
3235
- return Object.assign(Object.assign({ data, count: enableCount ? result[`${this.tableName}_aggregate`].aggregate.count : Infinity }, (((_b = options === null || options === void 0 ? void 0 : options.minimal) === null || _b === void 0 ? void 0 : _b.length)
3257
+ 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)
3236
3258
  ? {
3237
3259
  minimal: options.minimal.reduce((minimals, current) => {
3238
3260
  var _a;
3239
3261
  return (Object.assign(Object.assign({}, minimals), 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])));
3240
3262
  }, {}),
3241
3263
  }
3242
- : {})), (((_c = options === null || options === void 0 ? void 0 : options.maximum) === null || _c === void 0 ? void 0 : _c.length)
3264
+ : {})), (((_f = options === null || options === void 0 ? void 0 : options.maximum) === null || _f === void 0 ? void 0 : _f.length)
3243
3265
  ? {
3244
3266
  maximum: options.maximum.reduce((maximums, current) => {
3245
3267
  var _a;
3246
3268
  return (Object.assign(Object.assign({}, maximums), 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])));
3247
3269
  }, {}),
3248
3270
  }
3249
- : {}));
3271
+ : {})), (!((_g = params.limits) === null || _g === void 0 ? void 0 : _g.offset) &&
3272
+ ((_h = options === null || options === void 0 ? void 0 : options.distinct) === null || _h === void 0 ? void 0 : _h.length) && {
3273
+ distinct: options === null || options === void 0 ? void 0 : options.distinct.reduce((distinct, current) => {
3274
+ var _a, _b;
3275
+ const distinctOption = (_a = this.fields.find((fieldOption) => fieldOption === current)) !== null && _a !== void 0 ? _a : this.fields.find((fieldOption) => Object.keys(fieldOption).shift() === current);
3276
+ const fieldName = ((_b = Object.values(distinctOption).shift()) === null || _b === void 0 ? void 0 : _b.columnName) || current;
3277
+ return Object.assign(Object.assign({}, distinct), { [current.toString()]: result[`${this.tableName}_${current.toString()}_distinct`].map((obj) => obj[fieldName]) });
3278
+ }, {}),
3279
+ }));
3250
3280
  });
3251
3281
  }
3252
3282
  };
@@ -4218,7 +4248,7 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
4218
4248
  }
4219
4249
  findCatalog(params, mainGender) {
4220
4250
  return __awaiter(this, void 0, void 0, function* () {
4221
- return this.find(Object.assign(Object.assign({}, params), { filters: Object.assign(Object.assign({}, params.filters), { published: true }), orderBy: Object.assign({ hasStock: 'desc', intGender: mainGender === 'female' ? 'desc' : 'asc' }, omit(params.orderBy, ['hasStock', 'intGender'])) }));
4251
+ return this.find(Object.assign(Object.assign({}, params), { filters: Object.assign(Object.assign({}, params.filters), { published: true }), orderBy: Object.assign(Object.assign({ hasStock: 'desc' }, (!mainGender ? {} : { intGender: mainGender === 'female' ? 'desc' : 'asc' })), omit(params.orderBy, ['hasStock', 'intGender'])) }));
4222
4252
  });
4223
4253
  }
4224
4254
  updateCategories(productId, { categories }) {