@infrab4a/connect 4.9.13 → 4.9.14-beta.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.
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,21 @@ class CategoryBase extends BaseModel {
56
71
  static get identifiersFields() {
57
72
  return ['id'];
58
73
  }
74
+ get glamImages() {
75
+ return this.images[exports.Shops.GLAMSHOP];
76
+ }
77
+ get mensImages() {
78
+ return this.images[exports.Shops.MENSMARKET];
79
+ }
80
+ get glamMetadata() {
81
+ return this.metadata.find((metadata) => metadata.shop === exports.Shops.GLAMSHOP);
82
+ }
83
+ get mensMetadata() {
84
+ return this.metadata.find((metadata) => metadata.shop === exports.Shops.MENSMARKET);
85
+ }
86
+ getMostRelevantByShop(shop) {
87
+ return this.mostRelevant[shop];
88
+ }
59
89
  }
60
90
  tslib.__decorate([
61
91
  classTransformer.Type(() => CategoryBase),
@@ -164,21 +194,6 @@ tslib.__decorate([
164
194
  tslib.__metadata("design:type", Category)
165
195
  ], CategoryFilter.prototype, "category", void 0);
166
196
 
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
197
  class FilterOption extends BaseModel {
183
198
  static get identifiersFields() {
184
199
  return ['id'];
@@ -4691,6 +4706,7 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
4691
4706
  'name',
4692
4707
  'description',
4693
4708
  'image',
4709
+ { images: { columnName: 'images', type: HasuraGraphQLColumnType.Jsonb } },
4694
4710
  'published',
4695
4711
  'shop',
4696
4712
  { shops: { columnName: 'shops', type: HasuraGraphQLColumnType.Jsonb } },
@@ -4746,7 +4762,7 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
4746
4762
  {
4747
4763
  metadata: {
4748
4764
  columnName: 'metadata',
4749
- fields: ['title', 'description'],
4765
+ fields: ['shop', 'title', 'description'],
4750
4766
  bindPersistData: (value) => ({
4751
4767
  metadata: { data: value },
4752
4768
  }),
@@ -4773,7 +4789,7 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
4773
4789
  }
4774
4790
  async create(params) {
4775
4791
  const { metadata } = params, data = tslib.__rest(params, ["metadata"]);
4776
- return super.create(Object.assign(Object.assign({}, data), { isWishlist: false, metadata: metadata || { description: null, title: null } }));
4792
+ return super.create(Object.assign(Object.assign({}, data), { isWishlist: false, metadata: metadata || [{ shop: null, description: null, title: null }] }));
4777
4793
  }
4778
4794
  async get(identifiers) {
4779
4795
  var _a;
@@ -4964,22 +4980,35 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
4964
4980
  return plainData.products;
4965
4981
  }
4966
4982
  async updateMetadata(categoryId, { metadata }) {
4967
- const plainData = this.paramsToPlain({ metadata });
4968
- if (!plainData.metadata)
4969
- return null;
4970
- await this.mutation('update_category_metadata_by_pk', ['category_id'], {
4971
- pk_columns: {
4972
- value: { category_id: categoryId },
4973
- type: 'category_metadata_pk_columns_input',
4974
- required: true,
4975
- },
4976
- _set: {
4977
- value: lodash.omit(metadata, ['category_id']),
4978
- type: 'category_metadata_set_input',
4979
- required: true,
4980
- },
4981
- });
4982
- return plainData.metadata;
4983
+ if (Array.isArray(metadata) && !metadata.length)
4984
+ return [];
4985
+ if (Array.isArray(metadata) && metadata.length) {
4986
+ await this.mutation('delete_category_metadata', ['affected_rows'], {
4987
+ where: {
4988
+ type: 'category_metadata_bool_exp',
4989
+ required: true,
4990
+ value: { category_id: { _eq: categoryId } },
4991
+ },
4992
+ });
4993
+ await this.mutation('insert_category_metadata', ['affected_rows'], {
4994
+ objects: {
4995
+ type: '[category_metadata_insert_input!]',
4996
+ required: true,
4997
+ value: metadata.map((m) => (Object.assign({ category_id: categoryId }, m))),
4998
+ },
4999
+ });
5000
+ return metadata;
5001
+ }
5002
+ if ('action' in metadata && metadata.action === 'remove' && metadata.value.length) {
5003
+ await this.mutation('delete_category_metadata', ['affected_rows'], {
5004
+ where: {
5005
+ type: 'category_metadata_bool_exp',
5006
+ required: true,
5007
+ value: { category_id: { _eq: categoryId } },
5008
+ },
5009
+ });
5010
+ return [];
5011
+ }
4983
5012
  }
4984
5013
  async updateFilters(categoryId, { filters }) {
4985
5014
  if ('action' in filters && filters.action === 'remove' && filters.value.length) {
@@ -5986,7 +6015,7 @@ class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
5986
6015
  {
5987
6016
  metadata: {
5988
6017
  columnName: 'metadata',
5989
- fields: ['title', 'description'],
6018
+ fields: ['shop', 'title', 'description'],
5990
6019
  bindPersistData: (value) => ({
5991
6020
  metadata: { data: value },
5992
6021
  }),
@@ -6013,8 +6042,9 @@ class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
6013
6042
  this.categoryFilterRepository = categoryFilterRepository;
6014
6043
  }
6015
6044
  async create(params) {
6045
+ var _a;
6016
6046
  const { metadata } = params, data = tslib.__rest(params, ["metadata"]);
6017
- return super.create(Object.assign(Object.assign({}, data), { isWishlist: true, isCollection: true, brandCategory: false, metadata: metadata || { description: data.description, title: data.name } }));
6047
+ return super.create(Object.assign(Object.assign({}, data), { isWishlist: true, isCollection: true, brandCategory: false, metadata: metadata || [{ shop: (_a = data.shop) !== null && _a !== void 0 ? _a : null, description: data.description, title: data.name }] }));
6018
6048
  }
6019
6049
  async get(identifiers) {
6020
6050
  const data = await super.get(identifiers);
@@ -6138,22 +6168,39 @@ class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
6138
6168
  return plainData.products;
6139
6169
  }
6140
6170
  async updateMetadata(categoryId, { metadata }) {
6141
- const plainData = this.paramsToPlain({ metadata });
6142
- if (!plainData.metadata)
6143
- return;
6144
- await this.mutation('update_category_metadata_by_pk', ['category_id'], {
6145
- pk_columns: {
6146
- value: { category_id: categoryId },
6147
- type: 'category_metadata_pk_columns_input',
6148
- required: true,
6149
- },
6150
- _set: {
6151
- value: lodash.omit(metadata, ['category_id']),
6152
- type: 'category_metadata_set_input',
6153
- required: true,
6154
- },
6155
- });
6156
- return plainData.metadata;
6171
+ if (Array.isArray(metadata) && !metadata.length)
6172
+ return [];
6173
+ if (Array.isArray(metadata) && metadata.length) {
6174
+ const metadataUpdated = [];
6175
+ for (const data of metadata) {
6176
+ const update = await this.mutation('update_category_metadata_by_pk', ['category_id', 'shop'], {
6177
+ pk_columns: {
6178
+ value: { category_id: categoryId, shop: data.shop },
6179
+ type: 'category_metadata_pk_columns_input',
6180
+ required: true,
6181
+ },
6182
+ _set: {
6183
+ value: lodash.omit(data, ['category_id', 'shop']),
6184
+ type: 'category_metadata_set_input',
6185
+ required: true,
6186
+ },
6187
+ });
6188
+ metadataUpdated.push(update);
6189
+ }
6190
+ return metadataUpdated;
6191
+ }
6192
+ if ('action' in metadata && metadata.action === 'remove' && metadata.value.length) {
6193
+ for (let i = 0; i < metadata.value.length; i++) {
6194
+ await this.mutation('delete_category_metadata', ['affected_rows'], {
6195
+ where: {
6196
+ type: 'category_metadata_bool_exp',
6197
+ required: true,
6198
+ value: { category_id: { _eq: categoryId }, shop: metadata.value[i].shop },
6199
+ },
6200
+ });
6201
+ }
6202
+ return [];
6203
+ }
6157
6204
  }
6158
6205
  }
6159
6206
  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,21 @@ class CategoryBase extends BaseModel {
50
65
  static get identifiersFields() {
51
66
  return ['id'];
52
67
  }
68
+ get glamImages() {
69
+ return this.images[Shops.GLAMSHOP];
70
+ }
71
+ get mensImages() {
72
+ return this.images[Shops.MENSMARKET];
73
+ }
74
+ get glamMetadata() {
75
+ return this.metadata.find((metadata) => metadata.shop === Shops.GLAMSHOP);
76
+ }
77
+ get mensMetadata() {
78
+ return this.metadata.find((metadata) => metadata.shop === Shops.MENSMARKET);
79
+ }
80
+ getMostRelevantByShop(shop) {
81
+ return this.mostRelevant[shop];
82
+ }
53
83
  }
54
84
  __decorate([
55
85
  Type(() => CategoryBase),
@@ -158,21 +188,6 @@ __decorate([
158
188
  __metadata("design:type", Category)
159
189
  ], CategoryFilter.prototype, "category", void 0);
160
190
 
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
191
  class FilterOption extends BaseModel {
177
192
  static get identifiersFields() {
178
193
  return ['id'];
@@ -4685,6 +4700,7 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
4685
4700
  'name',
4686
4701
  'description',
4687
4702
  'image',
4703
+ { images: { columnName: 'images', type: HasuraGraphQLColumnType.Jsonb } },
4688
4704
  'published',
4689
4705
  'shop',
4690
4706
  { shops: { columnName: 'shops', type: HasuraGraphQLColumnType.Jsonb } },
@@ -4740,7 +4756,7 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
4740
4756
  {
4741
4757
  metadata: {
4742
4758
  columnName: 'metadata',
4743
- fields: ['title', 'description'],
4759
+ fields: ['shop', 'title', 'description'],
4744
4760
  bindPersistData: (value) => ({
4745
4761
  metadata: { data: value },
4746
4762
  }),
@@ -4767,7 +4783,7 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
4767
4783
  }
4768
4784
  async create(params) {
4769
4785
  const { metadata } = params, data = __rest(params, ["metadata"]);
4770
- return super.create(Object.assign(Object.assign({}, data), { isWishlist: false, metadata: metadata || { description: null, title: null } }));
4786
+ return super.create(Object.assign(Object.assign({}, data), { isWishlist: false, metadata: metadata || [{ shop: null, description: null, title: null }] }));
4771
4787
  }
4772
4788
  async get(identifiers) {
4773
4789
  var _a;
@@ -4958,22 +4974,35 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
4958
4974
  return plainData.products;
4959
4975
  }
4960
4976
  async updateMetadata(categoryId, { metadata }) {
4961
- const plainData = this.paramsToPlain({ metadata });
4962
- if (!plainData.metadata)
4963
- return null;
4964
- await this.mutation('update_category_metadata_by_pk', ['category_id'], {
4965
- pk_columns: {
4966
- value: { category_id: categoryId },
4967
- type: 'category_metadata_pk_columns_input',
4968
- required: true,
4969
- },
4970
- _set: {
4971
- value: omit(metadata, ['category_id']),
4972
- type: 'category_metadata_set_input',
4973
- required: true,
4974
- },
4975
- });
4976
- return plainData.metadata;
4977
+ if (Array.isArray(metadata) && !metadata.length)
4978
+ return [];
4979
+ if (Array.isArray(metadata) && metadata.length) {
4980
+ await this.mutation('delete_category_metadata', ['affected_rows'], {
4981
+ where: {
4982
+ type: 'category_metadata_bool_exp',
4983
+ required: true,
4984
+ value: { category_id: { _eq: categoryId } },
4985
+ },
4986
+ });
4987
+ await this.mutation('insert_category_metadata', ['affected_rows'], {
4988
+ objects: {
4989
+ type: '[category_metadata_insert_input!]',
4990
+ required: true,
4991
+ value: metadata.map((m) => (Object.assign({ category_id: categoryId }, m))),
4992
+ },
4993
+ });
4994
+ return metadata;
4995
+ }
4996
+ if ('action' in metadata && metadata.action === 'remove' && metadata.value.length) {
4997
+ await this.mutation('delete_category_metadata', ['affected_rows'], {
4998
+ where: {
4999
+ type: 'category_metadata_bool_exp',
5000
+ required: true,
5001
+ value: { category_id: { _eq: categoryId } },
5002
+ },
5003
+ });
5004
+ return [];
5005
+ }
4977
5006
  }
4978
5007
  async updateFilters(categoryId, { filters }) {
4979
5008
  if ('action' in filters && filters.action === 'remove' && filters.value.length) {
@@ -5980,7 +6009,7 @@ class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
5980
6009
  {
5981
6010
  metadata: {
5982
6011
  columnName: 'metadata',
5983
- fields: ['title', 'description'],
6012
+ fields: ['shop', 'title', 'description'],
5984
6013
  bindPersistData: (value) => ({
5985
6014
  metadata: { data: value },
5986
6015
  }),
@@ -6007,8 +6036,9 @@ class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
6007
6036
  this.categoryFilterRepository = categoryFilterRepository;
6008
6037
  }
6009
6038
  async create(params) {
6039
+ var _a;
6010
6040
  const { metadata } = params, data = __rest(params, ["metadata"]);
6011
- return super.create(Object.assign(Object.assign({}, data), { isWishlist: true, isCollection: true, brandCategory: false, metadata: metadata || { description: data.description, title: data.name } }));
6041
+ return super.create(Object.assign(Object.assign({}, data), { isWishlist: true, isCollection: true, brandCategory: false, metadata: metadata || [{ shop: (_a = data.shop) !== null && _a !== void 0 ? _a : null, description: data.description, title: data.name }] }));
6012
6042
  }
6013
6043
  async get(identifiers) {
6014
6044
  const data = await super.get(identifiers);
@@ -6132,22 +6162,39 @@ class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
6132
6162
  return plainData.products;
6133
6163
  }
6134
6164
  async updateMetadata(categoryId, { metadata }) {
6135
- const plainData = this.paramsToPlain({ metadata });
6136
- if (!plainData.metadata)
6137
- return;
6138
- await this.mutation('update_category_metadata_by_pk', ['category_id'], {
6139
- pk_columns: {
6140
- value: { category_id: categoryId },
6141
- type: 'category_metadata_pk_columns_input',
6142
- required: true,
6143
- },
6144
- _set: {
6145
- value: omit(metadata, ['category_id']),
6146
- type: 'category_metadata_set_input',
6147
- required: true,
6148
- },
6149
- });
6150
- return plainData.metadata;
6165
+ if (Array.isArray(metadata) && !metadata.length)
6166
+ return [];
6167
+ if (Array.isArray(metadata) && metadata.length) {
6168
+ const metadataUpdated = [];
6169
+ for (const data of metadata) {
6170
+ const update = await this.mutation('update_category_metadata_by_pk', ['category_id', 'shop'], {
6171
+ pk_columns: {
6172
+ value: { category_id: categoryId, shop: data.shop },
6173
+ type: 'category_metadata_pk_columns_input',
6174
+ required: true,
6175
+ },
6176
+ _set: {
6177
+ value: omit(data, ['category_id', 'shop']),
6178
+ type: 'category_metadata_set_input',
6179
+ required: true,
6180
+ },
6181
+ });
6182
+ metadataUpdated.push(update);
6183
+ }
6184
+ return metadataUpdated;
6185
+ }
6186
+ if ('action' in metadata && metadata.action === 'remove' && metadata.value.length) {
6187
+ for (let i = 0; i < metadata.value.length; i++) {
6188
+ await this.mutation('delete_category_metadata', ['affected_rows'], {
6189
+ where: {
6190
+ type: 'category_metadata_bool_exp',
6191
+ required: true,
6192
+ value: { category_id: { _eq: categoryId }, shop: metadata.value[i].shop },
6193
+ },
6194
+ });
6195
+ }
6196
+ return [];
6197
+ }
6151
6198
  }
6152
6199
  }
6153
6200
  __decorate([
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@infrab4a/connect",
3
- "version": "4.9.13",
3
+ "version": "4.9.14-beta.0",
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,15 +20,28 @@ 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[];
23
24
  isCollection?: boolean;
24
25
  isWishlist?: boolean;
25
26
  reference?: string;
26
27
  parentId?: number;
27
28
  theme?: string;
28
29
  bannerUrl?: string;
29
- mostRelevant?: string[];
30
+ mostRelevant?: CategoryMostRelevant;
30
31
  parent?: CategoryBase;
31
32
  filters?: Filter[];
32
33
  static get identifiersFields(): GenericIdentifier[];
34
+ get glamImages(): {
35
+ image: string;
36
+ brandBanner: string;
37
+ brandBannerMobile: string;
38
+ };
39
+ get mensImages(): {
40
+ image: string;
41
+ brandBanner: string;
42
+ brandBannerMobile: string;
43
+ };
44
+ get glamMetadata(): CategoryMetadata;
45
+ get mensMetadata(): CategoryMetadata;
46
+ getMostRelevantByShop(shop: Shops): string[];
33
47
  }
@@ -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';