@haus-tech/badge-plugin 3.0.0 → 4.0.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.
@@ -1,7 +1,8 @@
1
1
  import { DeepPartial } from '@vendure/common/lib/shared-types';
2
- import { VendureEntity, Collection, ID, Asset } from '@vendure/core';
3
- export declare class Badge extends VendureEntity {
2
+ import { VendureEntity, Collection, ID, Asset, ChannelAware, Channel } from '@vendure/core';
3
+ export declare class Badge extends VendureEntity implements ChannelAware {
4
4
  constructor(input?: DeepPartial<Badge>);
5
+ channels: Channel[];
5
6
  position: string;
6
7
  order: number;
7
8
  text: string;
@@ -20,6 +20,7 @@ let Badge = class Badge extends core_1.VendureEntity {
20
20
  Object.assign(this, input);
21
21
  }
22
22
  }
23
+ channels;
23
24
  position;
24
25
  order;
25
26
  text;
@@ -28,6 +29,11 @@ let Badge = class Badge extends core_1.VendureEntity {
28
29
  collection;
29
30
  collectionId;
30
31
  };
32
+ __decorate([
33
+ (0, typeorm_1.ManyToMany)((type) => core_1.Channel),
34
+ (0, typeorm_1.JoinTable)(),
35
+ __metadata("design:type", Array)
36
+ ], Badge.prototype, "channels", void 0);
31
37
  __decorate([
32
38
  (0, typeorm_1.Column)({ default: 'top-left' }),
33
39
  __metadata("design:type", String)
@@ -33,7 +33,9 @@ let BadgeService = class BadgeService {
33
33
  }
34
34
  async findAll(ctx, options) {
35
35
  return this.listQueryBuilder
36
- .build(badge_entity_1.Badge, options, { relations: ['collection', 'asset'], ctx })
36
+ .build(badge_entity_1.Badge, options, { relations: ['collection', 'asset', 'channels'], ctx })
37
+ .leftJoin('badge.channels', 'channel')
38
+ .andWhere('channel.id = :channelId', { channelId: ctx.channel.id })
37
39
  .getManyAndCount()
38
40
  .then(([items, totalItems]) => ({ items, totalItems }));
39
41
  }
@@ -41,6 +43,7 @@ let BadgeService = class BadgeService {
41
43
  const badge = new badge_entity_1.Badge({
42
44
  position: 'top-left',
43
45
  ...input,
46
+ channels: [ctx.channel],
44
47
  });
45
48
  return this.connection.getRepository(ctx, badge_entity_1.Badge).save(badge);
46
49
  }
@@ -80,12 +83,19 @@ let BadgeService = class BadgeService {
80
83
  return badge || new core_1.ErrorResult();
81
84
  }
82
85
  async findOneByCollectionId(ctx, collectionId) {
83
- return this.connection.getRepository(ctx, badge_entity_1.Badge).findOne({ where: { collectionId } });
86
+ const badge = await this.connection
87
+ .getRepository(ctx, badge_entity_1.Badge)
88
+ .findOne({ where: { collectionId }, relations: ['channels'] });
89
+ if (badge?.channels.some((channel) => channel.id === ctx.channel.id)) {
90
+ return badge;
91
+ }
92
+ return null;
84
93
  }
85
94
  async findByCollectionIds(ctx, collectionIds) {
86
- return this.connection
95
+ const badges = await this.connection
87
96
  .getRepository(ctx, badge_entity_1.Badge)
88
- .find({ where: { collectionId: (0, typeorm_1.In)(collectionIds) } });
97
+ .find({ where: { collectionId: (0, typeorm_1.In)(collectionIds) }, relations: ['channels'] });
98
+ return badges.filter((badge) => badge.channels.some((channel) => channel.id === ctx.channel.id));
89
99
  }
90
100
  async findBadgesForProduct(ctx, product) {
91
101
  const collections = await this.collectionService.getCollectionsByProductId(ctx, product.id, true);
@@ -27,7 +27,7 @@
27
27
  [disabled]="true"
28
28
  [hiddenWhenOff]="true"
29
29
  ></vdr-select-toggle>
30
- <img class="asset-thumb" [src]="item.asset | assetPreview : 'thumb'" />
30
+ <img class="asset-thumb" [src]="item.asset | assetPreview : 'medium'" />
31
31
  </div>
32
32
  <div class="detail">
33
33
  <span [title]="item.position">{{ item.position }}</span>
@@ -35,6 +35,7 @@
35
35
 
36
36
  img.asset-thumb {
37
37
  aspect-ratio: 1;
38
+ object-fit: contain;
38
39
  }
39
40
 
40
41
  vdr-select-toggle {
@@ -17,7 +17,7 @@
17
17
  </ng-select>
18
18
  </vdr-labeled-data>
19
19
 
20
- <vdr-labeled-data [label]="'badge-plugin.collections' | translate">
20
+ <vdr-labeled-data [label]="'badge-plugin.collections' | translate" class="select-wrapper">
21
21
  <ng-select
22
22
  [multiple]="false"
23
23
  [clearable]="true"
@@ -14,3 +14,10 @@
14
14
  .label-title {
15
15
  font-size: 32px;
16
16
  }
17
+
18
+ :host ::ng-deep .select-wrapper {
19
+ > div {
20
+ display: block;
21
+ width: 100%;
22
+ }
23
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haus-tech/badge-plugin",
3
- "version": "3.0.0",
3
+ "version": "4.0.0",
4
4
  "description": "Adds a badge to product images",
5
5
  "author": "Haus Tech",
6
6
  "repository": "https://github.com/WeAreHausTech/haus-tech-vendure-plugins",