Skip to content
Snippets Groups Projects
Commit 7f95231d authored by Aaron Dötsch's avatar Aaron Dötsch
Browse files

Simplify notification handler

parent a9ebc6d6
No related branches found
No related tags found
No related merge requests found
...@@ -15,19 +15,15 @@ export async function sendNotification<T extends PossibleNotificationType>(user: ...@@ -15,19 +15,15 @@ export async function sendNotification<T extends PossibleNotificationType>(user:
notificationChannels = await getNotificationChannels(userId, type.key); notificationChannels = await getNotificationChannels(userId, type.key);
} }
return Promise.all(notificationChannels.map(channel => { return Promise.all(notificationChannels.map(channel => {
switch(channel.channelType){ const channelType = Object.values(ChannelType).find(type => type.key === channel.channelType);
case ChannelType.EMAIL.key: { if(!channelType){
return ChannelType.EMAIL.handler(channel.recipient, type, data) console.error(`Unknown channel type`, channel.channelType);
.catch(err => {
return { return {
status: "error", status: "ignored",
channel, channel
error: err } as HandlerReturnIgnored;
} as HandlerReturnError;
});
} }
case ChannelType.WEBHOOK.key: { return channelType.handler(channel.recipient, type, data)
return ChannelType.WEBHOOK.handler(channel.recipient, type, data)
.catch(err => { .catch(err => {
return { return {
status: "error", status: "error",
...@@ -35,15 +31,6 @@ export async function sendNotification<T extends PossibleNotificationType>(user: ...@@ -35,15 +31,6 @@ export async function sendNotification<T extends PossibleNotificationType>(user:
error: err error: err
} as HandlerReturnError; } as HandlerReturnError;
}); });
}
default: {
console.error(`Unknown channel type`, channel.channelType);
return {
status: "ignored",
channel
} as HandlerReturnIgnored;
}
};
})); }));
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment