25 lines
937 B
JavaScript
25 lines
937 B
JavaScript
import { generateNewIdAsync } from 'oak-domain/lib/utils/uuid';
|
|
import { ConverterDict } from './index';
|
|
export const emailHandler = async ({ message, applications, system, messageTypeTemplates, context }) => {
|
|
const notificationDatas = [];
|
|
const emailNotification = await tryMakeEmailNotification(message, context);
|
|
if (emailNotification) {
|
|
notificationDatas.push(emailNotification);
|
|
}
|
|
return notificationDatas;
|
|
};
|
|
export async function tryMakeEmailNotification(message, context) {
|
|
const { userId, type, entity, entityId, router } = message;
|
|
const converter = ConverterDict[type] && ConverterDict[type].toEmail;
|
|
if (converter) {
|
|
const dispersedData = await converter(message, context);
|
|
if (dispersedData) {
|
|
return {
|
|
id: await generateNewIdAsync(),
|
|
data: dispersedData,
|
|
channel: 'email',
|
|
};
|
|
}
|
|
}
|
|
}
|