@infrab4a/connect 1.0.0-beta.18 → 1.0.0-beta.19

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.
@@ -1897,9 +1897,7 @@ GraphQLFieldHelper.ConvertFieldValueFrom = (data, fields) => Object.keys(data).r
1897
1897
  GraphQLFieldHelper.ConvertFieldValueTo = (instance, fields, update = false) => {
1898
1898
  var _a;
1899
1899
  const data = ((_a = instance.toPlain) === null || _a === void 0 ? void 0 : _a.call(instance)) || instance;
1900
- return Object.keys(data)
1901
- .filter((key) => !isNil(data[key]))
1902
- .reduce((result, attributeName) => {
1900
+ return Object.keys(data).reduce((result, attributeName) => {
1903
1901
  const { columnName, fields: attributeFields, foreignKeyColumn, to, bindPersistData, } = AttributeOptionHelper.FindByAttribute(attributeName, fields);
1904
1902
  if (bindPersistData)
1905
1903
  return Object.assign(Object.assign({}, result), bindPersistData(data[attributeName], instance));
@@ -1907,8 +1905,8 @@ GraphQLFieldHelper.ConvertFieldValueTo = (instance, fields, update = false) => {
1907
1905
  return result;
1908
1906
  if (!!foreignKeyColumn &&
1909
1907
  !isEmpty(foreignKeyColumn) &&
1910
- !Object.keys(foreignKeyColumn).filter((key) => !data[attributeName][key]).length)
1911
- return Object.keys(foreignKeyColumn).reduce((object, current) => (Object.assign(Object.assign({}, object), { [foreignKeyColumn[current]]: data[attributeName][current] })), Object.assign({}, result));
1908
+ !Object.keys(foreignKeyColumn).filter((key) => { var _a; return !((_a = data[attributeName]) === null || _a === void 0 ? void 0 : _a[key]); }).length)
1909
+ return Object.keys(foreignKeyColumn).reduce((object, current) => { var _a; return (Object.assign(Object.assign({}, object), { [foreignKeyColumn[current]]: (_a = data[attributeName]) === null || _a === void 0 ? void 0 : _a[current] })); }, Object.assign({}, result));
1912
1910
  if (update && isObject(data[attributeName]) && !isNil(attributeFields) && !isDate(data[attributeName]))
1913
1911
  return result;
1914
1912
  if (!!columnName && Array.isArray(attributeFields) && isObject(data[attributeName])) {
@@ -1961,7 +1959,21 @@ const withCreateHasuraGraphQL = (MixinBase) => {
1961
1959
  }
1962
1960
  save(data) {
1963
1961
  return __awaiter(this, void 0, void 0, function* () {
1964
- const result = yield this.mutation(this.insertGraphQLOperation, this.model.identifiersFields.map((field) => AttributeOptionHelper.FindByAttribute(field, this.fields).columnName), {
1962
+ const primaryKeyColumns = this.model.identifiersFields.map((field) => AttributeOptionHelper.FindByAttribute(field, this.fields).columnName);
1963
+ const foreignKeyColumns = this.fields
1964
+ .map((field) => {
1965
+ const columnOptions = Object.values(field).shift();
1966
+ return (AttributeOptionHelper.CheckIsColumnOption(columnOptions) &&
1967
+ columnOptions.foreignKeyColumn && [
1968
+ ...Object.values(columnOptions.foreignKeyColumn),
1969
+ {
1970
+ [columnOptions.columnName]: Object.keys(columnOptions.foreignKeyColumn),
1971
+ },
1972
+ ]);
1973
+ })
1974
+ .filter(Boolean)
1975
+ .reduce((keys, current) => [...keys, ...current], []);
1976
+ const result = yield this.mutation(this.insertGraphQLOperation, [...primaryKeyColumns, ...foreignKeyColumns], {
1965
1977
  object: { type: this.insertGraphQLObjectType, required: true, value: this.convertDataToHasura(data) },
1966
1978
  });
1967
1979
  return Object.assign(Object.assign({}, data.toPlain()), this.convertDataFromHasura(result[this.insertGraphQLOperation]).toPlain());
@@ -2091,7 +2103,7 @@ const withUpdateHasuraGraphQL = (MixinBase) => {
2091
2103
  return options.toPlain();
2092
2104
  if (isNil(options.action))
2093
2105
  return options;
2094
- if (options.action === UpdateOptionActions.REMOVE_FIELD)
2106
+ if ([UpdateOptionActions.REMOVE_FIELD.toString(), UpdateOptionActions.NULL.toString()].includes(options.action))
2095
2107
  return null;
2096
2108
  return options.value;
2097
2109
  };
@@ -2121,7 +2133,7 @@ const withUpdateHasuraGraphQL = (MixinBase) => {
2121
2133
  const model = this.model;
2122
2134
  if (model.isModel(params))
2123
2135
  return params.toPlain();
2124
- return Object.keys(params).reduce((data, currentKey) => (Object.assign(Object.assign({}, data), (params[currentKey] && { [currentKey]: getValueByAction(params[currentKey]) }))), {});
2136
+ return Object.keys(params).reduce((data, currentKey) => (Object.assign(Object.assign({}, data), (params[currentKey] !== undefined && { [currentKey]: getValueByAction(params[currentKey]) }))), {});
2125
2137
  }
2126
2138
  getUpdateModelKeys(data) {
2127
2139
  const instance = this.model.toInstance(data);
@@ -2148,10 +2160,11 @@ const withGetHasuraGraphQL = (MixinBase) => {
2148
2160
  return __awaiter(this, void 0, void 0, function* () {
2149
2161
  const instance = this.model.toInstance(identifiers);
2150
2162
  const result = yield this.query(this.getGraphQLOperation, this.fields, this.model.identifiersFields.reduce((ids, identifier) => {
2163
+ var _a;
2151
2164
  if (isNil(instance[identifier]))
2152
2165
  return ids;
2153
2166
  const columnOption = AttributeOptionHelper.FindByAttribute(identifier, this.fields);
2154
- const value = columnOption.to(identifiers[identifier.toString()], instance);
2167
+ const value = ((_a = columnOption === null || columnOption === void 0 ? void 0 : columnOption.to) === null || _a === void 0 ? void 0 : _a.call(columnOption, identifiers[identifier.toString()], instance)) || identifiers[identifier.toString()];
2155
2168
  return Object.assign(Object.assign({}, ids), { [columnOption.columnName]: {
2156
2169
  type: this.getAttributeGraphQLTypeOf(columnOption.type || value),
2157
2170
  value,
@@ -2335,11 +2348,12 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
2335
2348
  conditions: {
2336
2349
  columnName: 'tag_condition',
2337
2350
  type: HasuraGraphQLColumnType.Jsonb,
2338
- from: (tags, row) => ({ brand: row.brand_condition, tags }),
2351
+ from: (tags, row) => ({ brand: row.brand_condition, tags: Array.isArray(tags) ? tags : [] }),
2339
2352
  bindPersistData: (value) => {
2353
+ var _a, _b;
2340
2354
  return {
2341
2355
  brand_condition: value.brand,
2342
- tag_condition: `{"${value.tags.join('","')}"}`,
2356
+ tag_condition: `{"${((_b = (_a = value === null || value === void 0 ? void 0 : value.tags) === null || _a === void 0 ? void 0 : _a.join) === null || _b === void 0 ? void 0 : _b.call(_a, '","')) || ''}"}`,
2343
2357
  };
2344
2358
  },
2345
2359
  bindFindFilter: (sentence) => {
@@ -2434,8 +2448,8 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
2434
2448
  },
2435
2449
  },
2436
2450
  { hasVariants: { columnName: 'has_variants' } },
2437
- { images: { columnName: 'images', to: (value) => `{"${value.join(`","`)}"}` } },
2438
- { miniatures: { columnName: 'miniatures', to: (value) => `{"${value.join(`","`)}"}` } },
2451
+ { images: { columnName: 'images', to: (value) => { var _a; return `{"${((_a = value === null || value === void 0 ? void 0 : value.join) === null || _a === void 0 ? void 0 : _a.call(value, `","`)) || ''}"}`; } } },
2452
+ { miniatures: { columnName: 'miniatures', to: (value) => { var _a; return `{"${((_a = value === null || value === void 0 ? void 0 : value.join) === null || _a === void 0 ? void 0 : _a.call(value, `","`)) || ''}"}`; } } },
2439
2453
  'name',
2440
2454
  {
2441
2455
  price: {
@@ -2448,15 +2462,17 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
2448
2462
  } })), {}),
2449
2463
  bindFindFilter: (sentence) => {
2450
2464
  const filters = Object.values(sentence).shift();
2451
- return Object.assign(Object.assign(Object.assign(Object.assign({}, ((filters === null || filters === void 0 ? void 0 : filters.price) && { price: filters.price })), (filters.fullPrice && { full_price: filters.fullPrice })), (filters.subscriberDiscountPercentage && {
2465
+ return Object.assign(Object.assign(Object.assign(Object.assign({}, (((filters === null || filters === void 0 ? void 0 : filters.price) || (filters === null || filters === void 0 ? void 0 : filters.price) === 0) && { price: filters.price })), ((filters.fullPrice || filters.fullPrice === 0) && { full_price: filters.fullPrice })), ((filters.subscriberDiscountPercentage || filters.subscriberDiscountPercentage === 0) && {
2452
2466
  subscriber_discount_percentage: filters.subscriberDiscountPercentage,
2453
- })), (filters.subscriberPrice && { subscriber_price: filters.subscriberPrice }));
2467
+ })), ((filters.subscriberPrice || filters.subscriberPrice === 0) && {
2468
+ subscriber_price: filters.subscriberPrice,
2469
+ }));
2454
2470
  },
2455
2471
  bindPersistData: (value) => {
2456
2472
  const priceData = Object.values(value).shift();
2457
- return Object.assign(Object.assign(Object.assign(Object.assign({}, ((priceData === null || priceData === void 0 ? void 0 : priceData.price) && { price: priceData.price })), (priceData.fullPrice && { full_price: priceData.fullPrice })), (priceData.subscriberDiscountPercentage && {
2473
+ return Object.assign(Object.assign(Object.assign(Object.assign({}, ((priceData === null || priceData === void 0 ? void 0 : priceData.price) >= 0 && { price: priceData.price })), (priceData.fullPrice >= 0 && { full_price: priceData.fullPrice })), (priceData.subscriberDiscountPercentage >= 0 && {
2458
2474
  subscriber_discount_percentage: priceData.subscriberDiscountPercentage,
2459
- })), (priceData.subscriberPrice && { subscriber_price: priceData.subscriberPrice }));
2475
+ })), (priceData.subscriberPrice >= 0 && { subscriber_price: priceData.subscriberPrice }));
2460
2476
  },
2461
2477
  },
2462
2478
  },
@@ -2595,7 +2611,7 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
2595
2611
  type: '[product_kit_insert_input!]',
2596
2612
  required: true,
2597
2613
  value: plainData.kitProducts.map((kitProduct) => ({
2598
- kit_product_id: kitProduct.kitProductId,
2614
+ kit_product_id: kitProduct.productId || kitProduct.product.id,
2599
2615
  product_id: productId,
2600
2616
  quantity: kitProduct.quantity,
2601
2617
  })),