Files
medusa-store/packages/medusa-plugin-restock-notification/src/subscribers/index.js
2021-06-24 17:56:02 +02:00

28 lines
688 B
JavaScript

class VariantSubscriber {
constructor({ manager, eventBusService, restockNotificationService }) {
this.manager_ = manager
this.restockNotificationService_ = restockNotificationService
eventBusService.subscribe(
"product-variant.updated",
this.handleVariantUpdate
)
}
handleVariantUpdate = async (data) => {
const { id, fields } = data
if (fields.includes("inventory_quantity")) {
return await this.manager_.transaction(
async (m) =>
await this.restockNotificationService_
.withTransaction(m)
.triggerRestock(id)
)
}
return Promise.resolve()
}
}
export default VariantSubscriber