@infrab4a/connect 4.9.7-beta.17 → 4.9.7-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.
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'];
@@ -4746,6 +4773,7 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
4746
4773
  'name',
4747
4774
  'description',
4748
4775
  'image',
4776
+ { images: { columnName: 'images', type: HasuraGraphQLColumnType.Jsonb } },
4749
4777
  'published',
4750
4778
  'shop',
4751
4779
  { shops: { columnName: 'shops', type: HasuraGraphQLColumnType.Jsonb } },
@@ -4801,12 +4829,21 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
4801
4829
  {
4802
4830
  metadata: {
4803
4831
  columnName: 'metadata',
4804
- fields: ['title', 'description'],
4832
+ fields: ['shop', 'title', 'description'],
4805
4833
  bindPersistData: (value) => ({
4806
4834
  metadata: { data: value },
4807
4835
  }),
4808
4836
  },
4809
4837
  },
4838
+ {
4839
+ metadatas: {
4840
+ columnName: 'metadatas',
4841
+ fields: ['shop', 'title', 'description'],
4842
+ bindPersistData: (value) => ({
4843
+ metadatas: { data: value },
4844
+ }),
4845
+ },
4846
+ },
4810
4847
  { isCollection: { columnName: 'is_collection' } },
4811
4848
  { isWishlist: { columnName: 'is_wishlist' } },
4812
4849
  'reference',
@@ -4821,14 +4858,29 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
4821
4858
  'theme',
4822
4859
  { bannerUrl: { columnName: 'banner_url' } },
4823
4860
  { mostRelevant: { columnName: 'most_relevant', type: HasuraGraphQLColumnType.Jsonb } },
4861
+ { mostRelevants: { columnName: 'most_relevants', type: HasuraGraphQLColumnType.Jsonb } },
4824
4862
  ],
4825
4863
  });
4826
4864
  this.productRepository = productRepository;
4827
4865
  this.categoryFilterRepository = categoryFilterRepository;
4828
4866
  }
4829
4867
  async create(params) {
4830
- const { metadata } = params, data = tslib.__rest(params, ["metadata"]);
4831
- 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
+ } }));
4832
4884
  }
4833
4885
  async get(identifiers) {
4834
4886
  var _a;
@@ -4837,12 +4889,12 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
4837
4889
  : super.get(identifiers);
4838
4890
  }
4839
4891
  async update(params) {
4840
- 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"]);
4841
4893
  const plainData = this.paramsToPlain({ id: checkId });
4842
4894
  const id = await this.getId(plainData.id);
4843
4895
  const category = await super.update(Object.assign(Object.assign({ id }, data), { isWishlist: false }));
4844
4896
  category.products = products && (await this.updateProducts(+id, { products }));
4845
- category.metadata = metadata && (await this.updateMetadata(+id, { metadata }));
4897
+ category.metadatas = metadatas && (await this.updateMetadata(+id, { metadatas }));
4846
4898
  category.filters = filters && (await this.updateFilters(+id, { filters }));
4847
4899
  return category;
4848
4900
  }
@@ -5018,23 +5070,36 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
5018
5070
  });
5019
5071
  return plainData.products;
5020
5072
  }
5021
- async updateMetadata(categoryId, { metadata }) {
5022
- const plainData = this.paramsToPlain({ metadata });
5023
- if (!plainData.metadata)
5024
- return null;
5025
- await this.mutation('update_category_metadata_by_pk', ['category_id'], {
5026
- pk_columns: {
5027
- value: { category_id: categoryId },
5028
- type: 'category_metadata_pk_columns_input',
5029
- required: true,
5030
- },
5031
- _set: {
5032
- value: lodash.omit(metadata, ['category_id']),
5033
- type: 'category_metadata_set_input',
5034
- required: true,
5035
- },
5036
- });
5037
- 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
+ }
5038
5103
  }
5039
5104
  async updateFilters(categoryId, { filters }) {
5040
5105
  if ('action' in filters && filters.action === 'remove' && filters.value.length) {
@@ -5516,6 +5581,8 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
5516
5581
  enableCount: false,
5517
5582
  },
5518
5583
  });
5584
+ if (!result.data.length)
5585
+ return null;
5519
5586
  const product = (_a = result === null || result === void 0 ? void 0 : result.data) === null || _a === void 0 ? void 0 : _a.shift();
5520
5587
  RoundProductPricesHelper.roundProductPrices(product);
5521
5588
  return product;
@@ -6070,7 +6137,7 @@ class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
6070
6137
  {
6071
6138
  metadata: {
6072
6139
  columnName: 'metadata',
6073
- fields: ['title', 'description'],
6140
+ fields: ['shop', 'title', 'description'],
6074
6141
  bindPersistData: (value) => ({
6075
6142
  metadata: { data: value },
6076
6143
  }),
@@ -6100,8 +6167,23 @@ class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
6100
6167
  this.categoryFilterRepository = categoryFilterRepository;
6101
6168
  }
6102
6169
  async create(params) {
6103
- const { metadata } = params, data = tslib.__rest(params, ["metadata"]);
6104
- 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
+ } }));
6105
6187
  }
6106
6188
  async get(identifiers) {
6107
6189
  const data = await super.get(identifiers);
@@ -6114,12 +6196,12 @@ class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
6114
6196
  return await super.find(Object.assign(Object.assign({}, rest), { filters: Object.assign(Object.assign({}, filters), { isWishlist: { operator: exports.Where.EQUALS, value: true } }) }));
6115
6197
  }
6116
6198
  async update(params) {
6117
- 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"]);
6118
6200
  const plainData = this.paramsToPlain({ id: checkId });
6119
6201
  const id = plainData.id;
6120
6202
  const category = await super.update(Object.assign(Object.assign({ id }, data), { isWishlist: true, isCollection: true, brandCategory: false }));
6121
6203
  category.products = products && (await this.updateProducts(+id, { products }));
6122
- category.metadata = metadata && (await this.updateMetadata(+id, { metadata }));
6204
+ category.metadatas = metadatas && (await this.updateMetadata(+id, { metadatas }));
6123
6205
  return category;
6124
6206
  }
6125
6207
  async getWishlistBySlug(slug) {
@@ -6231,23 +6313,40 @@ class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
6231
6313
  });
6232
6314
  return plainData.products;
6233
6315
  }
6234
- async updateMetadata(categoryId, { metadata }) {
6235
- const plainData = this.paramsToPlain({ metadata });
6236
- if (!plainData.metadata)
6237
- return;
6238
- await this.mutation('update_category_metadata_by_pk', ['category_id'], {
6239
- pk_columns: {
6240
- value: { category_id: categoryId },
6241
- type: 'category_metadata_pk_columns_input',
6242
- required: true,
6243
- },
6244
- _set: {
6245
- value: lodash.omit(metadata, ['category_id']),
6246
- type: 'category_metadata_set_input',
6247
- required: true,
6248
- },
6249
- });
6250
- 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
+ }
6251
6350
  }
6252
6351
  }
6253
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'];
@@ -4740,6 +4767,7 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
4740
4767
  'name',
4741
4768
  'description',
4742
4769
  'image',
4770
+ { images: { columnName: 'images', type: HasuraGraphQLColumnType.Jsonb } },
4743
4771
  'published',
4744
4772
  'shop',
4745
4773
  { shops: { columnName: 'shops', type: HasuraGraphQLColumnType.Jsonb } },
@@ -4795,12 +4823,21 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
4795
4823
  {
4796
4824
  metadata: {
4797
4825
  columnName: 'metadata',
4798
- fields: ['title', 'description'],
4826
+ fields: ['shop', 'title', 'description'],
4799
4827
  bindPersistData: (value) => ({
4800
4828
  metadata: { data: value },
4801
4829
  }),
4802
4830
  },
4803
4831
  },
4832
+ {
4833
+ metadatas: {
4834
+ columnName: 'metadatas',
4835
+ fields: ['shop', 'title', 'description'],
4836
+ bindPersistData: (value) => ({
4837
+ metadatas: { data: value },
4838
+ }),
4839
+ },
4840
+ },
4804
4841
  { isCollection: { columnName: 'is_collection' } },
4805
4842
  { isWishlist: { columnName: 'is_wishlist' } },
4806
4843
  'reference',
@@ -4815,14 +4852,29 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
4815
4852
  'theme',
4816
4853
  { bannerUrl: { columnName: 'banner_url' } },
4817
4854
  { mostRelevant: { columnName: 'most_relevant', type: HasuraGraphQLColumnType.Jsonb } },
4855
+ { mostRelevants: { columnName: 'most_relevants', type: HasuraGraphQLColumnType.Jsonb } },
4818
4856
  ],
4819
4857
  });
4820
4858
  this.productRepository = productRepository;
4821
4859
  this.categoryFilterRepository = categoryFilterRepository;
4822
4860
  }
4823
4861
  async create(params) {
4824
- const { metadata } = params, data = __rest(params, ["metadata"]);
4825
- 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
+ } }));
4826
4878
  }
4827
4879
  async get(identifiers) {
4828
4880
  var _a;
@@ -4831,12 +4883,12 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
4831
4883
  : super.get(identifiers);
4832
4884
  }
4833
4885
  async update(params) {
4834
- 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"]);
4835
4887
  const plainData = this.paramsToPlain({ id: checkId });
4836
4888
  const id = await this.getId(plainData.id);
4837
4889
  const category = await super.update(Object.assign(Object.assign({ id }, data), { isWishlist: false }));
4838
4890
  category.products = products && (await this.updateProducts(+id, { products }));
4839
- category.metadata = metadata && (await this.updateMetadata(+id, { metadata }));
4891
+ category.metadatas = metadatas && (await this.updateMetadata(+id, { metadatas }));
4840
4892
  category.filters = filters && (await this.updateFilters(+id, { filters }));
4841
4893
  return category;
4842
4894
  }
@@ -5012,23 +5064,36 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
5012
5064
  });
5013
5065
  return plainData.products;
5014
5066
  }
5015
- async updateMetadata(categoryId, { metadata }) {
5016
- const plainData = this.paramsToPlain({ metadata });
5017
- if (!plainData.metadata)
5018
- return null;
5019
- await this.mutation('update_category_metadata_by_pk', ['category_id'], {
5020
- pk_columns: {
5021
- value: { category_id: categoryId },
5022
- type: 'category_metadata_pk_columns_input',
5023
- required: true,
5024
- },
5025
- _set: {
5026
- value: omit(metadata, ['category_id']),
5027
- type: 'category_metadata_set_input',
5028
- required: true,
5029
- },
5030
- });
5031
- 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
+ }
5032
5097
  }
5033
5098
  async updateFilters(categoryId, { filters }) {
5034
5099
  if ('action' in filters && filters.action === 'remove' && filters.value.length) {
@@ -5510,6 +5575,8 @@ class ProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
5510
5575
  enableCount: false,
5511
5576
  },
5512
5577
  });
5578
+ if (!result.data.length)
5579
+ return null;
5513
5580
  const product = (_a = result === null || result === void 0 ? void 0 : result.data) === null || _a === void 0 ? void 0 : _a.shift();
5514
5581
  RoundProductPricesHelper.roundProductPrices(product);
5515
5582
  return product;
@@ -6064,7 +6131,7 @@ class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
6064
6131
  {
6065
6132
  metadata: {
6066
6133
  columnName: 'metadata',
6067
- fields: ['title', 'description'],
6134
+ fields: ['shop', 'title', 'description'],
6068
6135
  bindPersistData: (value) => ({
6069
6136
  metadata: { data: value },
6070
6137
  }),
@@ -6094,8 +6161,23 @@ class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
6094
6161
  this.categoryFilterRepository = categoryFilterRepository;
6095
6162
  }
6096
6163
  async create(params) {
6097
- const { metadata } = params, data = __rest(params, ["metadata"]);
6098
- 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
+ } }));
6099
6181
  }
6100
6182
  async get(identifiers) {
6101
6183
  const data = await super.get(identifiers);
@@ -6108,12 +6190,12 @@ class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
6108
6190
  return await super.find(Object.assign(Object.assign({}, rest), { filters: Object.assign(Object.assign({}, filters), { isWishlist: { operator: Where.EQUALS, value: true } }) }));
6109
6191
  }
6110
6192
  async update(params) {
6111
- 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"]);
6112
6194
  const plainData = this.paramsToPlain({ id: checkId });
6113
6195
  const id = plainData.id;
6114
6196
  const category = await super.update(Object.assign(Object.assign({ id }, data), { isWishlist: true, isCollection: true, brandCategory: false }));
6115
6197
  category.products = products && (await this.updateProducts(+id, { products }));
6116
- category.metadata = metadata && (await this.updateMetadata(+id, { metadata }));
6198
+ category.metadatas = metadatas && (await this.updateMetadata(+id, { metadatas }));
6117
6199
  return category;
6118
6200
  }
6119
6201
  async getWishlistBySlug(slug) {
@@ -6225,23 +6307,40 @@ class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
6225
6307
  });
6226
6308
  return plainData.products;
6227
6309
  }
6228
- async updateMetadata(categoryId, { metadata }) {
6229
- const plainData = this.paramsToPlain({ metadata });
6230
- if (!plainData.metadata)
6231
- return;
6232
- await this.mutation('update_category_metadata_by_pk', ['category_id'], {
6233
- pk_columns: {
6234
- value: { category_id: categoryId },
6235
- type: 'category_metadata_pk_columns_input',
6236
- required: true,
6237
- },
6238
- _set: {
6239
- value: omit(metadata, ['category_id']),
6240
- type: 'category_metadata_set_input',
6241
- required: true,
6242
- },
6243
- });
6244
- 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
+ }
6245
6344
  }
6246
6345
  }
6247
6346
  __decorate([
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@infrab4a/connect",
3
- "version": "4.9.7-beta.17",
3
+ "version": "4.9.7-beta.19",
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;
@@ -19,7 +20,8 @@ export declare class CategoryBase<ChildCategory extends ModelBaseStructure<Child
19
20
  shop?: Shops;
20
21
  shops?: string[];
21
22
  published: boolean;
22
- metadata: CategoryMetadata;
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
  }
@@ -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';