@infrab4a/connect 4.9.7-beta.16 → 4.9.7-beta.18

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
@@ -42,6 +42,21 @@ class BaseModel {
42
42
  }
43
43
  }
44
44
 
45
+ exports.GenderDestination = void 0;
46
+ (function (GenderDestination) {
47
+ GenderDestination["FEMALE"] = "female";
48
+ GenderDestination["MALE"] = "male";
49
+ GenderDestination["UNISEX"] = "unisex";
50
+ })(exports.GenderDestination || (exports.GenderDestination = {}));
51
+
52
+ exports.Shops = void 0;
53
+ (function (Shops) {
54
+ Shops["MENSMARKET"] = "mensmarket";
55
+ Shops["GLAMSHOP"] = "Glamshop";
56
+ Shops["GLAMPOINTS"] = "Glampoints";
57
+ Shops["ALL"] = "ALL";
58
+ })(exports.Shops || (exports.Shops = {}));
59
+
45
60
  class Filter extends BaseModel {
46
61
  static get identifiersFields() {
47
62
  return ['id'];
@@ -56,6 +71,33 @@ class CategoryBase extends BaseModel {
56
71
  static get identifiersFields() {
57
72
  return ['id'];
58
73
  }
74
+ get glamImages() {
75
+ return this.images && this.images[exports.Shops.GLAMSHOP]
76
+ ? this.images[exports.Shops.GLAMSHOP]
77
+ : {
78
+ brandBanner: null,
79
+ brandBannerMobile: null,
80
+ image: null,
81
+ };
82
+ }
83
+ get mensImages() {
84
+ return this.images && this.images[exports.Shops.MENSMARKET]
85
+ ? this.images[exports.Shops.MENSMARKET]
86
+ : {
87
+ brandBanner: null,
88
+ brandBannerMobile: null,
89
+ image: null,
90
+ };
91
+ }
92
+ get glamMetadata() {
93
+ return this.metadatas.find((metadata) => metadata.shop === exports.Shops.GLAMSHOP);
94
+ }
95
+ get mensMetadata() {
96
+ return this.metadatas.find((metadata) => metadata.shop === exports.Shops.MENSMARKET);
97
+ }
98
+ getMostRelevantByShop(shop) {
99
+ return this.mostRelevants && this.mostRelevants[shop] ? this.mostRelevants[shop] : [];
100
+ }
59
101
  }
60
102
  tslib.__decorate([
61
103
  classTransformer.Type(() => CategoryBase),
@@ -164,21 +206,6 @@ tslib.__decorate([
164
206
  tslib.__metadata("design:type", Category)
165
207
  ], CategoryFilter.prototype, "category", void 0);
166
208
 
167
- exports.GenderDestination = void 0;
168
- (function (GenderDestination) {
169
- GenderDestination["FEMALE"] = "female";
170
- GenderDestination["MALE"] = "male";
171
- GenderDestination["UNISEX"] = "unisex";
172
- })(exports.GenderDestination || (exports.GenderDestination = {}));
173
-
174
- exports.Shops = void 0;
175
- (function (Shops) {
176
- Shops["MENSMARKET"] = "mensmarket";
177
- Shops["GLAMSHOP"] = "Glamshop";
178
- Shops["GLAMPOINTS"] = "Glampoints";
179
- Shops["ALL"] = "ALL";
180
- })(exports.Shops || (exports.Shops = {}));
181
-
182
209
  class FilterOption extends BaseModel {
183
210
  static get identifiersFields() {
184
211
  return ['id'];
@@ -4634,6 +4661,7 @@ class CategoryFilterHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHa
4634
4661
  fields: [
4635
4662
  'id',
4636
4663
  'description',
4664
+ 'title',
4637
4665
  'slug',
4638
4666
  'enabled',
4639
4667
  { createdAt: { columnName: 'created_at' } },
@@ -4745,6 +4773,7 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
4745
4773
  'name',
4746
4774
  'description',
4747
4775
  'image',
4776
+ { images: { columnName: 'images', type: HasuraGraphQLColumnType.Jsonb } },
4748
4777
  'published',
4749
4778
  'shop',
4750
4779
  { shops: { columnName: 'shops', type: HasuraGraphQLColumnType.Jsonb } },
@@ -4777,7 +4806,7 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
4777
4806
  filters: {
4778
4807
  columnName: 'filters',
4779
4808
  foreignKeyColumn: { filter_id: 'id' },
4780
- fields: [{ filter: ['id', 'description', 'slug', 'enabled'] }],
4809
+ fields: [{ filter: ['id', 'title', 'description', 'slug', 'enabled'] }],
4781
4810
  bindPersistData: (value) => ({
4782
4811
  filters: { data: value.map((filter) => ({ filter_id: filter.id })) },
4783
4812
  }),
@@ -4800,12 +4829,21 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
4800
4829
  {
4801
4830
  metadata: {
4802
4831
  columnName: 'metadata',
4803
- fields: ['title', 'description'],
4832
+ fields: ['shop', 'title', 'description'],
4804
4833
  bindPersistData: (value) => ({
4805
4834
  metadata: { data: value },
4806
4835
  }),
4807
4836
  },
4808
4837
  },
4838
+ {
4839
+ metadatas: {
4840
+ columnName: 'metadatas',
4841
+ fields: ['shop', 'title', 'description'],
4842
+ bindPersistData: (value) => ({
4843
+ metadatas: { data: value },
4844
+ }),
4845
+ },
4846
+ },
4809
4847
  { isCollection: { columnName: 'is_collection' } },
4810
4848
  { isWishlist: { columnName: 'is_wishlist' } },
4811
4849
  'reference',
@@ -4820,14 +4858,29 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
4820
4858
  'theme',
4821
4859
  { bannerUrl: { columnName: 'banner_url' } },
4822
4860
  { mostRelevant: { columnName: 'most_relevant', type: HasuraGraphQLColumnType.Jsonb } },
4861
+ { mostRelevants: { columnName: 'most_relevants', type: HasuraGraphQLColumnType.Jsonb } },
4823
4862
  ],
4824
4863
  });
4825
4864
  this.productRepository = productRepository;
4826
4865
  this.categoryFilterRepository = categoryFilterRepository;
4827
4866
  }
4828
4867
  async create(params) {
4829
- const { metadata } = params, data = tslib.__rest(params, ["metadata"]);
4830
- return super.create(Object.assign(Object.assign({}, data), { isWishlist: false, metadata: metadata || { description: null, title: null } }));
4868
+ const { images, mostRelevants, metadatas } = params, data = tslib.__rest(params, ["images", "mostRelevants", "metadatas"]);
4869
+ return super.create(Object.assign(Object.assign({}, data), { isWishlist: false, metadatas: metadatas || [{ shop: null, description: null, title: null }], mostRelevants: mostRelevants || {
4870
+ [exports.Shops.GLAMSHOP]: null,
4871
+ [exports.Shops.MENSMARKET]: null,
4872
+ }, images: images || {
4873
+ [exports.Shops.GLAMSHOP]: {
4874
+ brandBanner: null,
4875
+ brandBannerMobile: null,
4876
+ image: null,
4877
+ },
4878
+ [exports.Shops.MENSMARKET]: {
4879
+ brandBanner: null,
4880
+ brandBannerMobile: null,
4881
+ image: null,
4882
+ },
4883
+ } }));
4831
4884
  }
4832
4885
  async get(identifiers) {
4833
4886
  var _a;
@@ -4836,12 +4889,12 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
4836
4889
  : super.get(identifiers);
4837
4890
  }
4838
4891
  async update(params) {
4839
- const { products, id: checkId, metadata, filters } = params, data = tslib.__rest(params, ["products", "id", "metadata", "filters"]);
4892
+ const { products, id: checkId, metadatas, filters } = params, data = tslib.__rest(params, ["products", "id", "metadatas", "filters"]);
4840
4893
  const plainData = this.paramsToPlain({ id: checkId });
4841
4894
  const id = await this.getId(plainData.id);
4842
4895
  const category = await super.update(Object.assign(Object.assign({ id }, data), { isWishlist: false }));
4843
4896
  category.products = products && (await this.updateProducts(+id, { products }));
4844
- category.metadata = metadata && (await this.updateMetadata(+id, { metadata }));
4897
+ category.metadatas = metadatas && (await this.updateMetadata(+id, { metadatas }));
4845
4898
  category.filters = filters && (await this.updateFilters(+id, { filters }));
4846
4899
  return category;
4847
4900
  }
@@ -5017,23 +5070,36 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
5017
5070
  });
5018
5071
  return plainData.products;
5019
5072
  }
5020
- async updateMetadata(categoryId, { metadata }) {
5021
- const plainData = this.paramsToPlain({ metadata });
5022
- if (!plainData.metadata)
5023
- return null;
5024
- await this.mutation('update_category_metadata_by_pk', ['category_id'], {
5025
- pk_columns: {
5026
- value: { category_id: categoryId },
5027
- type: 'category_metadata_pk_columns_input',
5028
- required: true,
5029
- },
5030
- _set: {
5031
- value: lodash.omit(metadata, ['category_id']),
5032
- type: 'category_metadata_set_input',
5033
- required: true,
5034
- },
5035
- });
5036
- return plainData.metadata;
5073
+ async updateMetadata(categoryId, { metadatas }) {
5074
+ if (Array.isArray(metadatas) && !metadatas.length)
5075
+ return [];
5076
+ if (Array.isArray(metadatas) && metadatas.length) {
5077
+ await this.mutation('delete_category_metadata', ['affected_rows'], {
5078
+ where: {
5079
+ type: 'category_metadata_bool_exp',
5080
+ required: true,
5081
+ value: { category_id: { _eq: categoryId } },
5082
+ },
5083
+ });
5084
+ await this.mutation('insert_category_metadata', ['affected_rows'], {
5085
+ objects: {
5086
+ type: '[category_metadata_insert_input!]',
5087
+ required: true,
5088
+ value: metadatas.map((m) => (Object.assign({ category_id: categoryId }, m))),
5089
+ },
5090
+ });
5091
+ return metadatas;
5092
+ }
5093
+ if ('action' in metadatas && metadatas.action === 'remove' && metadatas.value.length) {
5094
+ await this.mutation('delete_category_metadata', ['affected_rows'], {
5095
+ where: {
5096
+ type: 'category_metadata_bool_exp',
5097
+ required: true,
5098
+ value: { category_id: { _eq: categoryId } },
5099
+ },
5100
+ });
5101
+ return [];
5102
+ }
5037
5103
  }
5038
5104
  async updateFilters(categoryId, { filters }) {
5039
5105
  if ('action' in filters && filters.action === 'remove' && filters.value.length) {
@@ -5127,6 +5193,7 @@ class FilterHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGrap
5127
5193
  interceptors,
5128
5194
  fields: [
5129
5195
  'id',
5196
+ 'title',
5130
5197
  'description',
5131
5198
  'slug',
5132
5199
  'enabled',
@@ -5514,6 +5581,8 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
5514
5581
  enableCount: false,
5515
5582
  },
5516
5583
  });
5584
+ if (!result.data.length)
5585
+ return null;
5517
5586
  const product = (_a = result === null || result === void 0 ? void 0 : result.data) === null || _a === void 0 ? void 0 : _a.shift();
5518
5587
  RoundProductPricesHelper.roundProductPrices(product);
5519
5588
  return product;
@@ -6068,7 +6137,7 @@ class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
6068
6137
  {
6069
6138
  metadata: {
6070
6139
  columnName: 'metadata',
6071
- fields: ['title', 'description'],
6140
+ fields: ['shop', 'title', 'description'],
6072
6141
  bindPersistData: (value) => ({
6073
6142
  metadata: { data: value },
6074
6143
  }),
@@ -6098,8 +6167,23 @@ class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
6098
6167
  this.categoryFilterRepository = categoryFilterRepository;
6099
6168
  }
6100
6169
  async create(params) {
6101
- const { metadata } = params, data = tslib.__rest(params, ["metadata"]);
6102
- return super.create(Object.assign(Object.assign({}, data), { isWishlist: true, isCollection: true, brandCategory: false, metadata: metadata || { description: data.description, title: data.name } }));
6170
+ var _a;
6171
+ const { images, mostRelevants, metadatas } = params, data = tslib.__rest(params, ["images", "mostRelevants", "metadatas"]);
6172
+ return super.create(Object.assign(Object.assign({}, data), { isWishlist: true, isCollection: true, brandCategory: false, metadatas: metadatas || [{ shop: (_a = data.shop) !== null && _a !== void 0 ? _a : null, description: data.description, title: data.name }], mostRelevants: mostRelevants || {
6173
+ [exports.Shops.GLAMSHOP]: null,
6174
+ [exports.Shops.MENSMARKET]: null,
6175
+ }, images: images || {
6176
+ [exports.Shops.GLAMSHOP]: {
6177
+ brandBanner: null,
6178
+ brandBannerMobile: null,
6179
+ image: null,
6180
+ },
6181
+ [exports.Shops.MENSMARKET]: {
6182
+ brandBanner: null,
6183
+ brandBannerMobile: null,
6184
+ image: null,
6185
+ },
6186
+ } }));
6103
6187
  }
6104
6188
  async get(identifiers) {
6105
6189
  const data = await super.get(identifiers);
@@ -6112,12 +6196,12 @@ class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
6112
6196
  return await super.find(Object.assign(Object.assign({}, rest), { filters: Object.assign(Object.assign({}, filters), { isWishlist: { operator: exports.Where.EQUALS, value: true } }) }));
6113
6197
  }
6114
6198
  async update(params) {
6115
- const { products, id: checkId, metadata, filters } = params, data = tslib.__rest(params, ["products", "id", "metadata", "filters"]);
6199
+ const { products, id: checkId, metadatas, filters } = params, data = tslib.__rest(params, ["products", "id", "metadatas", "filters"]);
6116
6200
  const plainData = this.paramsToPlain({ id: checkId });
6117
6201
  const id = plainData.id;
6118
6202
  const category = await super.update(Object.assign(Object.assign({ id }, data), { isWishlist: true, isCollection: true, brandCategory: false }));
6119
6203
  category.products = products && (await this.updateProducts(+id, { products }));
6120
- category.metadata = metadata && (await this.updateMetadata(+id, { metadata }));
6204
+ category.metadatas = metadatas && (await this.updateMetadata(+id, { metadatas }));
6121
6205
  return category;
6122
6206
  }
6123
6207
  async getWishlistBySlug(slug) {
@@ -6229,23 +6313,40 @@ class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
6229
6313
  });
6230
6314
  return plainData.products;
6231
6315
  }
6232
- async updateMetadata(categoryId, { metadata }) {
6233
- const plainData = this.paramsToPlain({ metadata });
6234
- if (!plainData.metadata)
6235
- return;
6236
- await this.mutation('update_category_metadata_by_pk', ['category_id'], {
6237
- pk_columns: {
6238
- value: { category_id: categoryId },
6239
- type: 'category_metadata_pk_columns_input',
6240
- required: true,
6241
- },
6242
- _set: {
6243
- value: lodash.omit(metadata, ['category_id']),
6244
- type: 'category_metadata_set_input',
6245
- required: true,
6246
- },
6247
- });
6248
- return plainData.metadata;
6316
+ async updateMetadata(categoryId, { metadatas }) {
6317
+ if (Array.isArray(metadatas) && !metadatas.length)
6318
+ return [];
6319
+ if (Array.isArray(metadatas) && metadatas.length) {
6320
+ const metadataUpdated = [];
6321
+ for (const data of metadatas) {
6322
+ const update = await this.mutation('update_category_metadata_by_pk', ['category_id', 'shop'], {
6323
+ pk_columns: {
6324
+ value: { category_id: categoryId, shop: data.shop },
6325
+ type: 'category_metadata_pk_columns_input',
6326
+ required: true,
6327
+ },
6328
+ _set: {
6329
+ value: lodash.omit(data, ['category_id', 'shop']),
6330
+ type: 'category_metadata_set_input',
6331
+ required: true,
6332
+ },
6333
+ });
6334
+ metadataUpdated.push(update);
6335
+ }
6336
+ return metadataUpdated;
6337
+ }
6338
+ if ('action' in metadatas && metadatas.action === 'remove' && metadatas.value.length) {
6339
+ for (let i = 0; i < metadatas.value.length; i++) {
6340
+ await this.mutation('delete_category_metadata', ['affected_rows'], {
6341
+ where: {
6342
+ type: 'category_metadata_bool_exp',
6343
+ required: true,
6344
+ value: { category_id: { _eq: categoryId }, shop: metadatas.value[i].shop },
6345
+ },
6346
+ });
6347
+ }
6348
+ return [];
6349
+ }
6249
6350
  }
6250
6351
  }
6251
6352
  tslib.__decorate([
package/index.esm.js CHANGED
@@ -36,6 +36,21 @@ class BaseModel {
36
36
  }
37
37
  }
38
38
 
39
+ var GenderDestination;
40
+ (function (GenderDestination) {
41
+ GenderDestination["FEMALE"] = "female";
42
+ GenderDestination["MALE"] = "male";
43
+ GenderDestination["UNISEX"] = "unisex";
44
+ })(GenderDestination || (GenderDestination = {}));
45
+
46
+ var Shops;
47
+ (function (Shops) {
48
+ Shops["MENSMARKET"] = "mensmarket";
49
+ Shops["GLAMSHOP"] = "Glamshop";
50
+ Shops["GLAMPOINTS"] = "Glampoints";
51
+ Shops["ALL"] = "ALL";
52
+ })(Shops || (Shops = {}));
53
+
39
54
  class Filter extends BaseModel {
40
55
  static get identifiersFields() {
41
56
  return ['id'];
@@ -50,6 +65,33 @@ class CategoryBase extends BaseModel {
50
65
  static get identifiersFields() {
51
66
  return ['id'];
52
67
  }
68
+ get glamImages() {
69
+ return this.images && this.images[Shops.GLAMSHOP]
70
+ ? this.images[Shops.GLAMSHOP]
71
+ : {
72
+ brandBanner: null,
73
+ brandBannerMobile: null,
74
+ image: null,
75
+ };
76
+ }
77
+ get mensImages() {
78
+ return this.images && this.images[Shops.MENSMARKET]
79
+ ? this.images[Shops.MENSMARKET]
80
+ : {
81
+ brandBanner: null,
82
+ brandBannerMobile: null,
83
+ image: null,
84
+ };
85
+ }
86
+ get glamMetadata() {
87
+ return this.metadatas.find((metadata) => metadata.shop === Shops.GLAMSHOP);
88
+ }
89
+ get mensMetadata() {
90
+ return this.metadatas.find((metadata) => metadata.shop === Shops.MENSMARKET);
91
+ }
92
+ getMostRelevantByShop(shop) {
93
+ return this.mostRelevants && this.mostRelevants[shop] ? this.mostRelevants[shop] : [];
94
+ }
53
95
  }
54
96
  __decorate([
55
97
  Type(() => CategoryBase),
@@ -158,21 +200,6 @@ __decorate([
158
200
  __metadata("design:type", Category)
159
201
  ], CategoryFilter.prototype, "category", void 0);
160
202
 
161
- var GenderDestination;
162
- (function (GenderDestination) {
163
- GenderDestination["FEMALE"] = "female";
164
- GenderDestination["MALE"] = "male";
165
- GenderDestination["UNISEX"] = "unisex";
166
- })(GenderDestination || (GenderDestination = {}));
167
-
168
- var Shops;
169
- (function (Shops) {
170
- Shops["MENSMARKET"] = "mensmarket";
171
- Shops["GLAMSHOP"] = "Glamshop";
172
- Shops["GLAMPOINTS"] = "Glampoints";
173
- Shops["ALL"] = "ALL";
174
- })(Shops || (Shops = {}));
175
-
176
203
  class FilterOption extends BaseModel {
177
204
  static get identifiersFields() {
178
205
  return ['id'];
@@ -4628,6 +4655,7 @@ class CategoryFilterHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHa
4628
4655
  fields: [
4629
4656
  'id',
4630
4657
  'description',
4658
+ 'title',
4631
4659
  'slug',
4632
4660
  'enabled',
4633
4661
  { createdAt: { columnName: 'created_at' } },
@@ -4739,6 +4767,7 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
4739
4767
  'name',
4740
4768
  'description',
4741
4769
  'image',
4770
+ { images: { columnName: 'images', type: HasuraGraphQLColumnType.Jsonb } },
4742
4771
  'published',
4743
4772
  'shop',
4744
4773
  { shops: { columnName: 'shops', type: HasuraGraphQLColumnType.Jsonb } },
@@ -4771,7 +4800,7 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
4771
4800
  filters: {
4772
4801
  columnName: 'filters',
4773
4802
  foreignKeyColumn: { filter_id: 'id' },
4774
- fields: [{ filter: ['id', 'description', 'slug', 'enabled'] }],
4803
+ fields: [{ filter: ['id', 'title', 'description', 'slug', 'enabled'] }],
4775
4804
  bindPersistData: (value) => ({
4776
4805
  filters: { data: value.map((filter) => ({ filter_id: filter.id })) },
4777
4806
  }),
@@ -4794,12 +4823,21 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
4794
4823
  {
4795
4824
  metadata: {
4796
4825
  columnName: 'metadata',
4797
- fields: ['title', 'description'],
4826
+ fields: ['shop', 'title', 'description'],
4798
4827
  bindPersistData: (value) => ({
4799
4828
  metadata: { data: value },
4800
4829
  }),
4801
4830
  },
4802
4831
  },
4832
+ {
4833
+ metadatas: {
4834
+ columnName: 'metadatas',
4835
+ fields: ['shop', 'title', 'description'],
4836
+ bindPersistData: (value) => ({
4837
+ metadatas: { data: value },
4838
+ }),
4839
+ },
4840
+ },
4803
4841
  { isCollection: { columnName: 'is_collection' } },
4804
4842
  { isWishlist: { columnName: 'is_wishlist' } },
4805
4843
  'reference',
@@ -4814,14 +4852,29 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
4814
4852
  'theme',
4815
4853
  { bannerUrl: { columnName: 'banner_url' } },
4816
4854
  { mostRelevant: { columnName: 'most_relevant', type: HasuraGraphQLColumnType.Jsonb } },
4855
+ { mostRelevants: { columnName: 'most_relevants', type: HasuraGraphQLColumnType.Jsonb } },
4817
4856
  ],
4818
4857
  });
4819
4858
  this.productRepository = productRepository;
4820
4859
  this.categoryFilterRepository = categoryFilterRepository;
4821
4860
  }
4822
4861
  async create(params) {
4823
- const { metadata } = params, data = __rest(params, ["metadata"]);
4824
- return super.create(Object.assign(Object.assign({}, data), { isWishlist: false, metadata: metadata || { description: null, title: null } }));
4862
+ const { images, mostRelevants, metadatas } = params, data = __rest(params, ["images", "mostRelevants", "metadatas"]);
4863
+ return super.create(Object.assign(Object.assign({}, data), { isWishlist: false, metadatas: metadatas || [{ shop: null, description: null, title: null }], mostRelevants: mostRelevants || {
4864
+ [Shops.GLAMSHOP]: null,
4865
+ [Shops.MENSMARKET]: null,
4866
+ }, images: images || {
4867
+ [Shops.GLAMSHOP]: {
4868
+ brandBanner: null,
4869
+ brandBannerMobile: null,
4870
+ image: null,
4871
+ },
4872
+ [Shops.MENSMARKET]: {
4873
+ brandBanner: null,
4874
+ brandBannerMobile: null,
4875
+ image: null,
4876
+ },
4877
+ } }));
4825
4878
  }
4826
4879
  async get(identifiers) {
4827
4880
  var _a;
@@ -4830,12 +4883,12 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
4830
4883
  : super.get(identifiers);
4831
4884
  }
4832
4885
  async update(params) {
4833
- const { products, id: checkId, metadata, filters } = params, data = __rest(params, ["products", "id", "metadata", "filters"]);
4886
+ const { products, id: checkId, metadatas, filters } = params, data = __rest(params, ["products", "id", "metadatas", "filters"]);
4834
4887
  const plainData = this.paramsToPlain({ id: checkId });
4835
4888
  const id = await this.getId(plainData.id);
4836
4889
  const category = await super.update(Object.assign(Object.assign({ id }, data), { isWishlist: false }));
4837
4890
  category.products = products && (await this.updateProducts(+id, { products }));
4838
- category.metadata = metadata && (await this.updateMetadata(+id, { metadata }));
4891
+ category.metadatas = metadatas && (await this.updateMetadata(+id, { metadatas }));
4839
4892
  category.filters = filters && (await this.updateFilters(+id, { filters }));
4840
4893
  return category;
4841
4894
  }
@@ -5011,23 +5064,36 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
5011
5064
  });
5012
5065
  return plainData.products;
5013
5066
  }
5014
- async updateMetadata(categoryId, { metadata }) {
5015
- const plainData = this.paramsToPlain({ metadata });
5016
- if (!plainData.metadata)
5017
- return null;
5018
- await this.mutation('update_category_metadata_by_pk', ['category_id'], {
5019
- pk_columns: {
5020
- value: { category_id: categoryId },
5021
- type: 'category_metadata_pk_columns_input',
5022
- required: true,
5023
- },
5024
- _set: {
5025
- value: omit(metadata, ['category_id']),
5026
- type: 'category_metadata_set_input',
5027
- required: true,
5028
- },
5029
- });
5030
- return plainData.metadata;
5067
+ async updateMetadata(categoryId, { metadatas }) {
5068
+ if (Array.isArray(metadatas) && !metadatas.length)
5069
+ return [];
5070
+ if (Array.isArray(metadatas) && metadatas.length) {
5071
+ await this.mutation('delete_category_metadata', ['affected_rows'], {
5072
+ where: {
5073
+ type: 'category_metadata_bool_exp',
5074
+ required: true,
5075
+ value: { category_id: { _eq: categoryId } },
5076
+ },
5077
+ });
5078
+ await this.mutation('insert_category_metadata', ['affected_rows'], {
5079
+ objects: {
5080
+ type: '[category_metadata_insert_input!]',
5081
+ required: true,
5082
+ value: metadatas.map((m) => (Object.assign({ category_id: categoryId }, m))),
5083
+ },
5084
+ });
5085
+ return metadatas;
5086
+ }
5087
+ if ('action' in metadatas && metadatas.action === 'remove' && metadatas.value.length) {
5088
+ await this.mutation('delete_category_metadata', ['affected_rows'], {
5089
+ where: {
5090
+ type: 'category_metadata_bool_exp',
5091
+ required: true,
5092
+ value: { category_id: { _eq: categoryId } },
5093
+ },
5094
+ });
5095
+ return [];
5096
+ }
5031
5097
  }
5032
5098
  async updateFilters(categoryId, { filters }) {
5033
5099
  if ('action' in filters && filters.action === 'remove' && filters.value.length) {
@@ -5121,6 +5187,7 @@ class FilterHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGrap
5121
5187
  interceptors,
5122
5188
  fields: [
5123
5189
  'id',
5190
+ 'title',
5124
5191
  'description',
5125
5192
  'slug',
5126
5193
  'enabled',
@@ -5508,6 +5575,8 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
5508
5575
  enableCount: false,
5509
5576
  },
5510
5577
  });
5578
+ if (!result.data.length)
5579
+ return null;
5511
5580
  const product = (_a = result === null || result === void 0 ? void 0 : result.data) === null || _a === void 0 ? void 0 : _a.shift();
5512
5581
  RoundProductPricesHelper.roundProductPrices(product);
5513
5582
  return product;
@@ -6062,7 +6131,7 @@ class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
6062
6131
  {
6063
6132
  metadata: {
6064
6133
  columnName: 'metadata',
6065
- fields: ['title', 'description'],
6134
+ fields: ['shop', 'title', 'description'],
6066
6135
  bindPersistData: (value) => ({
6067
6136
  metadata: { data: value },
6068
6137
  }),
@@ -6092,8 +6161,23 @@ class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
6092
6161
  this.categoryFilterRepository = categoryFilterRepository;
6093
6162
  }
6094
6163
  async create(params) {
6095
- const { metadata } = params, data = __rest(params, ["metadata"]);
6096
- return super.create(Object.assign(Object.assign({}, data), { isWishlist: true, isCollection: true, brandCategory: false, metadata: metadata || { description: data.description, title: data.name } }));
6164
+ var _a;
6165
+ const { images, mostRelevants, metadatas } = params, data = __rest(params, ["images", "mostRelevants", "metadatas"]);
6166
+ return super.create(Object.assign(Object.assign({}, data), { isWishlist: true, isCollection: true, brandCategory: false, metadatas: metadatas || [{ shop: (_a = data.shop) !== null && _a !== void 0 ? _a : null, description: data.description, title: data.name }], mostRelevants: mostRelevants || {
6167
+ [Shops.GLAMSHOP]: null,
6168
+ [Shops.MENSMARKET]: null,
6169
+ }, images: images || {
6170
+ [Shops.GLAMSHOP]: {
6171
+ brandBanner: null,
6172
+ brandBannerMobile: null,
6173
+ image: null,
6174
+ },
6175
+ [Shops.MENSMARKET]: {
6176
+ brandBanner: null,
6177
+ brandBannerMobile: null,
6178
+ image: null,
6179
+ },
6180
+ } }));
6097
6181
  }
6098
6182
  async get(identifiers) {
6099
6183
  const data = await super.get(identifiers);
@@ -6106,12 +6190,12 @@ class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
6106
6190
  return await super.find(Object.assign(Object.assign({}, rest), { filters: Object.assign(Object.assign({}, filters), { isWishlist: { operator: Where.EQUALS, value: true } }) }));
6107
6191
  }
6108
6192
  async update(params) {
6109
- const { products, id: checkId, metadata, filters } = params, data = __rest(params, ["products", "id", "metadata", "filters"]);
6193
+ const { products, id: checkId, metadatas, filters } = params, data = __rest(params, ["products", "id", "metadatas", "filters"]);
6110
6194
  const plainData = this.paramsToPlain({ id: checkId });
6111
6195
  const id = plainData.id;
6112
6196
  const category = await super.update(Object.assign(Object.assign({ id }, data), { isWishlist: true, isCollection: true, brandCategory: false }));
6113
6197
  category.products = products && (await this.updateProducts(+id, { products }));
6114
- category.metadata = metadata && (await this.updateMetadata(+id, { metadata }));
6198
+ category.metadatas = metadatas && (await this.updateMetadata(+id, { metadatas }));
6115
6199
  return category;
6116
6200
  }
6117
6201
  async getWishlistBySlug(slug) {
@@ -6223,23 +6307,40 @@ class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
6223
6307
  });
6224
6308
  return plainData.products;
6225
6309
  }
6226
- async updateMetadata(categoryId, { metadata }) {
6227
- const plainData = this.paramsToPlain({ metadata });
6228
- if (!plainData.metadata)
6229
- return;
6230
- await this.mutation('update_category_metadata_by_pk', ['category_id'], {
6231
- pk_columns: {
6232
- value: { category_id: categoryId },
6233
- type: 'category_metadata_pk_columns_input',
6234
- required: true,
6235
- },
6236
- _set: {
6237
- value: omit(metadata, ['category_id']),
6238
- type: 'category_metadata_set_input',
6239
- required: true,
6240
- },
6241
- });
6242
- return plainData.metadata;
6310
+ async updateMetadata(categoryId, { metadatas }) {
6311
+ if (Array.isArray(metadatas) && !metadatas.length)
6312
+ return [];
6313
+ if (Array.isArray(metadatas) && metadatas.length) {
6314
+ const metadataUpdated = [];
6315
+ for (const data of metadatas) {
6316
+ const update = await this.mutation('update_category_metadata_by_pk', ['category_id', 'shop'], {
6317
+ pk_columns: {
6318
+ value: { category_id: categoryId, shop: data.shop },
6319
+ type: 'category_metadata_pk_columns_input',
6320
+ required: true,
6321
+ },
6322
+ _set: {
6323
+ value: omit(data, ['category_id', 'shop']),
6324
+ type: 'category_metadata_set_input',
6325
+ required: true,
6326
+ },
6327
+ });
6328
+ metadataUpdated.push(update);
6329
+ }
6330
+ return metadataUpdated;
6331
+ }
6332
+ if ('action' in metadatas && metadatas.action === 'remove' && metadatas.value.length) {
6333
+ for (let i = 0; i < metadatas.value.length; i++) {
6334
+ await this.mutation('delete_category_metadata', ['affected_rows'], {
6335
+ where: {
6336
+ type: 'category_metadata_bool_exp',
6337
+ required: true,
6338
+ value: { category_id: { _eq: categoryId }, shop: metadatas.value[i].shop },
6339
+ },
6340
+ });
6341
+ }
6342
+ return [];
6343
+ }
6243
6344
  }
6244
6345
  }
6245
6346
  __decorate([
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@infrab4a/connect",
3
- "version": "4.9.7-beta.16",
3
+ "version": "4.9.7-beta.18",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org"
6
6
  },
@@ -1,7 +1,7 @@
1
1
  import { BaseModel, GenericIdentifier, ModelBaseStructure } from '../../generic/model';
2
2
  import { Shops } from './enums';
3
3
  import { Filter } from './filter';
4
- import { CategoryCondition, CategoryMetadata } from './types';
4
+ import { CategoryCondition, CategoryImages, CategoryMetadata, CategoryMostRelevant } from './types';
5
5
  export declare class CategoryBase<ChildCategory extends ModelBaseStructure<ChildCategory, Identifiers> = ModelBaseStructure<any, any>, Identifiers = ChildCategory['identifiersFields']> extends BaseModel<ChildCategory, Identifiers> {
6
6
  id: string;
7
7
  brandCategory: boolean;
@@ -9,6 +9,7 @@ export declare class CategoryBase<ChildCategory extends ModelBaseStructure<Child
9
9
  name: string;
10
10
  slug: string;
11
11
  image?: string;
12
+ images?: CategoryImages;
12
13
  brandCategoryBanner?: string;
13
14
  brandCategoryBannerMobile?: string;
14
15
  description: string;
@@ -20,6 +21,7 @@ export declare class CategoryBase<ChildCategory extends ModelBaseStructure<Child
20
21
  shops?: string[];
21
22
  published: boolean;
22
23
  metadata: CategoryMetadata;
24
+ metadatas: CategoryMetadata[];
23
25
  isCollection?: boolean;
24
26
  isWishlist?: boolean;
25
27
  reference?: string;
@@ -27,7 +29,21 @@ export declare class CategoryBase<ChildCategory extends ModelBaseStructure<Child
27
29
  theme?: string;
28
30
  bannerUrl?: string;
29
31
  mostRelevant?: string[];
32
+ mostRelevants?: CategoryMostRelevant;
30
33
  parent?: CategoryBase;
31
34
  filters?: Filter[];
32
35
  static get identifiersFields(): GenericIdentifier[];
36
+ get glamImages(): {
37
+ image: string;
38
+ brandBanner: string;
39
+ brandBannerMobile: string;
40
+ };
41
+ get mensImages(): {
42
+ image: string;
43
+ brandBanner: string;
44
+ brandBannerMobile: string;
45
+ };
46
+ get glamMetadata(): CategoryMetadata;
47
+ get mensMetadata(): CategoryMetadata;
48
+ getMostRelevantByShop(shop: Shops): string[];
33
49
  }
@@ -4,6 +4,7 @@ import { FilterOption } from './filter-option';
4
4
  export declare class Filter extends BaseModel<Filter> {
5
5
  id: number;
6
6
  description: string;
7
+ title?: string;
7
8
  slug: string;
8
9
  enabled: boolean;
9
10
  options?: FilterOption[];
@@ -0,0 +1,8 @@
1
+ import { Shops } from '../enums';
2
+ export type CategoryImages = {
3
+ [shop in Shops]?: {
4
+ image: string;
5
+ brandBanner: string;
6
+ brandBannerMobile: string;
7
+ };
8
+ };
@@ -1,4 +1,6 @@
1
+ import { Shops } from '../enums';
1
2
  export type CategoryMetadata = {
3
+ shop: Shops;
2
4
  title?: string;
3
5
  description?: string;
4
6
  };
@@ -0,0 +1,4 @@
1
+ import { Shops } from '../enums';
2
+ export type CategoryMostRelevant = {
3
+ [shop in Shops]?: string[];
4
+ };
@@ -1,5 +1,7 @@
1
1
  export * from './category-condition.type';
2
+ export * from './category-images.type';
2
3
  export * from './category-metadata.type';
4
+ export * from './category-most-relevant.type';
3
5
  export * from './category-product';
4
6
  export * from './product-evaluation.type';
5
7
  export * from './product-gender.type';