docs: describes usage of plugin

This commit is contained in:
Sebastian Rindom
2021-04-07 11:00:24 +02:00
parent 69442a1735
commit fdbf11ac7a
8 changed files with 188 additions and 26 deletions
@@ -13,10 +13,6 @@ class OrderSubscriber {
this.notificationService_.subscribe("swap.created", "sendgrid")
this.notificationService_.subscribe("order.items_returned", "sendgrid")
this.notificationService_.subscribe("order.return_requested", "sendgrid")
this.notificationService_.subscribe(
"restock_notification.restocked",
"sendgrid"
)
}
}
@@ -0,0 +1,41 @@
class RestockNotification {
constructor({ eventBusService, sendgridService }) {
eventBusService.subscribe(
"restock-notification.restocked",
async (eventData) => {
const templateId = await sendgridService.getTemplateId(
"restock-notification.restocked"
)
if (!templateId) {
return
}
const data = await sendgridService.fetchData(
"restock-notification.restocked",
eventData,
null
)
if (!data.emails) {
return
}
return await Promise.all(
data.emails.map(async (e) => {
const sendOptions = {
template_id: templateId,
from: sendgridService.options_.from,
to: e,
dynamic_template_data: data,
}
return await sendgridService.sendEmail(sendOptions)
})
)
}
)
}
}
export default RestockNotification