@infrab4a/connect 4.2.0 → 4.2.1-beta.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.
Files changed (3) hide show
  1. package/index.cjs.js +10 -19
  2. package/index.esm.js +10 -19
  3. package/package.json +1 -1
package/index.cjs.js CHANGED
@@ -4595,18 +4595,14 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
4595
4595
  const plainData = this.paramsToPlain({ products });
4596
4596
  if (!plainData.products || plainData.products.length <= 0)
4597
4597
  return [];
4598
- await this.mutation('delete_category_product', ['affected_rows'], {
4599
- where: {
4600
- type: 'category_product_bool_exp',
4601
- required: true,
4602
- value: { category_id: { _eq: categoryId } },
4603
- },
4604
- });
4598
+ const category = await this.get({ id: categoryId.toString() });
4605
4599
  await this.mutation('insert_category_product', ['affected_rows'], {
4606
4600
  objects: {
4607
4601
  type: '[category_product_insert_input!]',
4608
4602
  required: true,
4609
- value: plainData.products.map((productId) => ({ category_id: categoryId, product_id: productId })),
4603
+ value: plainData.products
4604
+ .filter((productId) => !category.products.includes(productId))
4605
+ .map((productId) => ({ category_id: categoryId, product_id: productId })),
4610
4606
  },
4611
4607
  });
4612
4608
  return plainData.products;
@@ -4644,15 +4640,14 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
4644
4640
  },
4645
4641
  })
4646
4642
  .then((res) => res.data);
4647
- const currentFiltersId = currentFilters.map((f) => f.id);
4643
+ const currentFiltersId = currentFilters.map((f) => f.filterId);
4648
4644
  const filtersUpdatedId = filters.value.map((f) => f.id);
4649
4645
  const filterToBeDeleted = currentFiltersId.filter((c) => !filtersUpdatedId.includes(c));
4650
4646
  const filterToBeInserted = filtersUpdatedId.filter((c) => !currentFiltersId.includes(c));
4651
4647
  for (const filter of filterToBeDeleted) {
4652
4648
  const index = currentFilters.findIndex((f) => f.id == filter);
4653
- if (index != -1) {
4649
+ if (index != -1)
4654
4650
  currentFilters.splice(index, 1);
4655
- }
4656
4651
  await this.categoryFilterRepository.deleteByCategoryAndFilter(categoryId, filter);
4657
4652
  }
4658
4653
  for (const filter of filterToBeInserted) {
@@ -5561,19 +5556,15 @@ class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
5561
5556
  const plainData = this.paramsToPlain({ products });
5562
5557
  if (!plainData.products || plainData.products.length <= 0)
5563
5558
  return [];
5564
- await this.mutation('delete_category_product', ['affected_rows'], {
5565
- where: {
5566
- type: 'category_product_bool_exp',
5567
- required: true,
5568
- value: { category_id: { _eq: categoryId } },
5569
- },
5570
- });
5559
+ const category = await this.get({ id: categoryId.toString() });
5571
5560
  await this.categoryFilterRepository.deleteByCategory(categoryId);
5572
5561
  await this.mutation('insert_category_product', ['affected_rows'], {
5573
5562
  objects: {
5574
5563
  type: '[category_product_insert_input!]',
5575
5564
  required: true,
5576
- value: plainData.products.map((productId) => ({ category_id: categoryId, product_id: productId })),
5565
+ value: plainData.products
5566
+ .filter((productId) => !category.products.includes(productId))
5567
+ .map((productId) => ({ category_id: categoryId, product_id: productId })),
5577
5568
  },
5578
5569
  });
5579
5570
  return plainData.products;
package/index.esm.js CHANGED
@@ -4571,18 +4571,14 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
4571
4571
  const plainData = this.paramsToPlain({ products });
4572
4572
  if (!plainData.products || plainData.products.length <= 0)
4573
4573
  return [];
4574
- await this.mutation('delete_category_product', ['affected_rows'], {
4575
- where: {
4576
- type: 'category_product_bool_exp',
4577
- required: true,
4578
- value: { category_id: { _eq: categoryId } },
4579
- },
4580
- });
4574
+ const category = await this.get({ id: categoryId.toString() });
4581
4575
  await this.mutation('insert_category_product', ['affected_rows'], {
4582
4576
  objects: {
4583
4577
  type: '[category_product_insert_input!]',
4584
4578
  required: true,
4585
- value: plainData.products.map((productId) => ({ category_id: categoryId, product_id: productId })),
4579
+ value: plainData.products
4580
+ .filter((productId) => !category.products.includes(productId))
4581
+ .map((productId) => ({ category_id: categoryId, product_id: productId })),
4586
4582
  },
4587
4583
  });
4588
4584
  return plainData.products;
@@ -4620,15 +4616,14 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
4620
4616
  },
4621
4617
  })
4622
4618
  .then((res) => res.data);
4623
- const currentFiltersId = currentFilters.map((f) => f.id);
4619
+ const currentFiltersId = currentFilters.map((f) => f.filterId);
4624
4620
  const filtersUpdatedId = filters.value.map((f) => f.id);
4625
4621
  const filterToBeDeleted = currentFiltersId.filter((c) => !filtersUpdatedId.includes(c));
4626
4622
  const filterToBeInserted = filtersUpdatedId.filter((c) => !currentFiltersId.includes(c));
4627
4623
  for (const filter of filterToBeDeleted) {
4628
4624
  const index = currentFilters.findIndex((f) => f.id == filter);
4629
- if (index != -1) {
4625
+ if (index != -1)
4630
4626
  currentFilters.splice(index, 1);
4631
- }
4632
4627
  await this.categoryFilterRepository.deleteByCategoryAndFilter(categoryId, filter);
4633
4628
  }
4634
4629
  for (const filter of filterToBeInserted) {
@@ -5537,19 +5532,15 @@ class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
5537
5532
  const plainData = this.paramsToPlain({ products });
5538
5533
  if (!plainData.products || plainData.products.length <= 0)
5539
5534
  return [];
5540
- await this.mutation('delete_category_product', ['affected_rows'], {
5541
- where: {
5542
- type: 'category_product_bool_exp',
5543
- required: true,
5544
- value: { category_id: { _eq: categoryId } },
5545
- },
5546
- });
5535
+ const category = await this.get({ id: categoryId.toString() });
5547
5536
  await this.categoryFilterRepository.deleteByCategory(categoryId);
5548
5537
  await this.mutation('insert_category_product', ['affected_rows'], {
5549
5538
  objects: {
5550
5539
  type: '[category_product_insert_input!]',
5551
5540
  required: true,
5552
- value: plainData.products.map((productId) => ({ category_id: categoryId, product_id: productId })),
5541
+ value: plainData.products
5542
+ .filter((productId) => !category.products.includes(productId))
5543
+ .map((productId) => ({ category_id: categoryId, product_id: productId })),
5553
5544
  },
5554
5545
  });
5555
5546
  return plainData.products;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@infrab4a/connect",
3
- "version": "4.2.0",
3
+ "version": "4.2.1-beta.1",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org"
6
6
  },