clean code

pr/2623
CarinaWolli 2022-04-26 00:28:14 +02:00
parent 69ae2dcb46
commit cd96e22990
1 changed files with 27 additions and 23 deletions

View File

@ -149,35 +149,39 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
}, },
}); });
const subscribers = await getSubscribers({ const subscriberPromises = [
...subscriberOptions, getSubscribers({
subscriptionType: SubscriptionType.WEBHOOK, ...subscriberOptions,
}); subscriptionType: SubscriptionType.WEBHOOK,
//const allSubscribersPromises = [getSubscribers(subscriberOptions)] }),
];
if (zapierAppInstalled) { if (zapierAppInstalled) {
const zapierSubscribers = await getSubscribers({ subscriberPromises.push(
...subscriberOptions, getSubscribers({
subscriptionType: SubscriptionType.ZAPIER, ...subscriberOptions,
}); subscriptionType: SubscriptionType.ZAPIER,
subscribers.push(...zapierSubscribers); })
//allSubscribersPromises.push(getZapierSubscribers(subscriberOptions)); );
} }
//await Promise.all(allSubscribersPromises) const allSubscribers = await Promise.all(subscriberPromises);
const promises = subscribers.map((sub) => const promises = allSubscribers.map((subArray) =>
sendPayload( subArray.map((sub) =>
eventTrigger, sendPayload(
new Date().toISOString(), eventTrigger,
sub.subscriberUrl, new Date().toISOString(),
evt, sub.subscriberUrl,
sub.subscriptionType, evt,
sub.payloadTemplate sub.subscriptionType,
).catch((e) => { sub.payloadTemplate
console.error(`Error executing webhook for event: ${eventTrigger}, URL: ${sub.subscriberUrl}`, e); ).catch((e) => {
}) console.error(`Error executing webhook for event: ${eventTrigger}, URL: ${sub.subscriberUrl}`, e);
})
)
); );
await Promise.all(promises); await Promise.all(promises);
// by cancelling first, and blocking whilst doing so; we can ensure a cancel // by cancelling first, and blocking whilst doing so; we can ensure a cancel