30 lines
1.1 KiB
JavaScript
30 lines
1.1 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.emailHandler = void 0;
|
|
exports.tryMakeEmailNotification = tryMakeEmailNotification;
|
|
const uuid_1 = require("oak-domain/lib/utils/uuid");
|
|
const index_1 = require("./index");
|
|
const emailHandler = async ({ message, applications, system, context }) => {
|
|
const notificationDatas = [];
|
|
const emailNotification = await tryMakeEmailNotification(message, context);
|
|
if (emailNotification) {
|
|
notificationDatas.push(emailNotification);
|
|
}
|
|
return notificationDatas;
|
|
};
|
|
exports.emailHandler = emailHandler;
|
|
async function tryMakeEmailNotification(message, context) {
|
|
const { userId, type, entity, entityId, router } = message;
|
|
const converter = index_1.ConverterDict[type] && index_1.ConverterDict[type].email;
|
|
if (converter) {
|
|
const dispersedData = await converter(message, context);
|
|
if (dispersedData) {
|
|
return {
|
|
id: await (0, uuid_1.generateNewIdAsync)(),
|
|
data: dispersedData,
|
|
channel: 'email',
|
|
};
|
|
}
|
|
}
|
|
}
|