Skip to content
This repository has been archived by the owner on Oct 9, 2024. It is now read-only.

Commit

Permalink
Fix bug where orders.receipt.resend was not being scaffolded on ins…
Browse files Browse the repository at this point in the history
…tallation
  • Loading branch information
robbieaverill committed Nov 29, 2021
1 parent 0bc1df7 commit 1783942
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

13 changes: 11 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,15 @@ module.exports = async function handler(request, context) {

// Loop each event type
const promises = [];
[
const templateConfig = [
{
event: 'customers.login.token',
name: 'Customers: login token',
subject: 'Log in to your account',
},
{
event: 'orders.create',
eventAliases: ['orders.receipt.resend'],
name: 'Orders: receipt',
subject: 'Your order: {{ payload.customer_reference }}',
},
Expand All @@ -118,14 +119,22 @@ module.exports = async function handler(request, context) {
name: 'Orders: item shipped',
subject: 'Your order has shipped!',
},
].forEach(({ event, name, subject }) => {
];
templateConfig.forEach(({ event, name, subject }) => {
promises.push(createTemplate(event, name, subject));
});

// Wait for all of the templates to be built, then collect their IDs
const templateIds = await Promise.all(promises);
// Converts from [{event: 'foo', id: 'a-b-c'},...] to {foo: 'a-b-c', ...}
const templates = templateIds.reduce((acc, value) => (acc[value.event] = value.id, acc), {});
// Add any template event aliases
templateConfig.forEach(({ event, eventAliases = [] }) => {
eventAliases.forEach((alias) => {
templates[alias] = templates[event];
});
});

context.store.set('templates', templates);
result = {
installed: true,
Expand Down

0 comments on commit 1783942

Please sign in to comment.