|
@@ -41,9 +41,9 @@ export interface DefaultSearchReindexResponse extends SearchReindexResponse {
|
|
|
*
|
|
*
|
|
|
* @example
|
|
* @example
|
|
|
* ```ts
|
|
* ```ts
|
|
|
- * import { DefaultSearchPlugin } from '\@vendure/core';
|
|
|
|
|
|
|
+ * import { DefaultSearchPlugin, VendureConfig } from '\@vendure/core';
|
|
|
*
|
|
*
|
|
|
- * const config: VendureConfig = {
|
|
|
|
|
|
|
+ * export const config: VendureConfig = {
|
|
|
* // Add an instance of the plugin to the plugins array
|
|
* // Add an instance of the plugin to the plugins array
|
|
|
* plugins: [
|
|
* plugins: [
|
|
|
* DefaultSearchPlugin,
|
|
* DefaultSearchPlugin,
|
|
@@ -69,21 +69,21 @@ export class DefaultSearchPlugin implements OnVendureBootstrap {
|
|
|
async onVendureBootstrap() {
|
|
async onVendureBootstrap() {
|
|
|
this.searchIndexService.initJobQueue();
|
|
this.searchIndexService.initJobQueue();
|
|
|
|
|
|
|
|
- this.eventBus.ofType(ProductEvent).subscribe((event) => {
|
|
|
|
|
|
|
+ this.eventBus.ofType(ProductEvent).subscribe(event => {
|
|
|
if (event.type === 'deleted') {
|
|
if (event.type === 'deleted') {
|
|
|
return this.searchIndexService.deleteProduct(event.ctx, event.product);
|
|
return this.searchIndexService.deleteProduct(event.ctx, event.product);
|
|
|
} else {
|
|
} else {
|
|
|
return this.searchIndexService.updateProduct(event.ctx, event.product);
|
|
return this.searchIndexService.updateProduct(event.ctx, event.product);
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
- this.eventBus.ofType(ProductVariantEvent).subscribe((event) => {
|
|
|
|
|
|
|
+ this.eventBus.ofType(ProductVariantEvent).subscribe(event => {
|
|
|
if (event.type === 'deleted') {
|
|
if (event.type === 'deleted') {
|
|
|
return this.searchIndexService.deleteVariant(event.ctx, event.variants);
|
|
return this.searchIndexService.deleteVariant(event.ctx, event.variants);
|
|
|
} else {
|
|
} else {
|
|
|
return this.searchIndexService.updateVariants(event.ctx, event.variants);
|
|
return this.searchIndexService.updateVariants(event.ctx, event.variants);
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
- this.eventBus.ofType(AssetEvent).subscribe((event) => {
|
|
|
|
|
|
|
+ this.eventBus.ofType(AssetEvent).subscribe(event => {
|
|
|
if (event.type === 'updated') {
|
|
if (event.type === 'updated') {
|
|
|
return this.searchIndexService.updateAsset(event.ctx, event.asset);
|
|
return this.searchIndexService.updateAsset(event.ctx, event.asset);
|
|
|
}
|
|
}
|
|
@@ -91,7 +91,7 @@ export class DefaultSearchPlugin implements OnVendureBootstrap {
|
|
|
return this.searchIndexService.deleteAsset(event.ctx, event.asset);
|
|
return this.searchIndexService.deleteAsset(event.ctx, event.asset);
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
- this.eventBus.ofType(ProductChannelEvent).subscribe((event) => {
|
|
|
|
|
|
|
+ this.eventBus.ofType(ProductChannelEvent).subscribe(event => {
|
|
|
if (event.type === 'assigned') {
|
|
if (event.type === 'assigned') {
|
|
|
return this.searchIndexService.assignProductToChannel(
|
|
return this.searchIndexService.assignProductToChannel(
|
|
|
event.ctx,
|
|
event.ctx,
|
|
@@ -112,18 +112,18 @@ export class DefaultSearchPlugin implements OnVendureBootstrap {
|
|
|
collectionModification$
|
|
collectionModification$
|
|
|
.pipe(
|
|
.pipe(
|
|
|
buffer(closingNotifier$),
|
|
buffer(closingNotifier$),
|
|
|
- filter((events) => 0 < events.length),
|
|
|
|
|
- map((events) => ({
|
|
|
|
|
|
|
+ filter(events => 0 < events.length),
|
|
|
|
|
+ map(events => ({
|
|
|
ctx: events[0].ctx,
|
|
ctx: events[0].ctx,
|
|
|
ids: events.reduce((ids, e) => [...ids, ...e.productVariantIds], [] as ID[]),
|
|
ids: events.reduce((ids, e) => [...ids, ...e.productVariantIds], [] as ID[]),
|
|
|
})),
|
|
})),
|
|
|
- filter((e) => 0 < e.ids.length),
|
|
|
|
|
|
|
+ filter(e => 0 < e.ids.length),
|
|
|
)
|
|
)
|
|
|
- .subscribe((events) => {
|
|
|
|
|
|
|
+ .subscribe(events => {
|
|
|
return this.searchIndexService.updateVariantsById(events.ctx, events.ids);
|
|
return this.searchIndexService.updateVariantsById(events.ctx, events.ids);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- this.eventBus.ofType(TaxRateModificationEvent).subscribe((event) => {
|
|
|
|
|
|
|
+ this.eventBus.ofType(TaxRateModificationEvent).subscribe(event => {
|
|
|
const defaultTaxZone = event.ctx.channel.defaultTaxZone;
|
|
const defaultTaxZone = event.ctx.channel.defaultTaxZone;
|
|
|
if (defaultTaxZone && idsAreEqual(defaultTaxZone.id, event.taxRate.zone.id)) {
|
|
if (defaultTaxZone && idsAreEqual(defaultTaxZone.id, event.taxRate.zone.id)) {
|
|
|
return this.searchIndexService.reindex(event.ctx);
|
|
return this.searchIndexService.reindex(event.ctx);
|