@coko/server
Version:
Reusable server for use by Coko's projects
38 lines • 1.32 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const sendEmail_1 = require("./sendEmail");
const logger_1 = __importDefault(require("../logger"));
const constants_1 = require("./constants");
const { NOTIFY_SERVICE } = constants_1.labels;
const { EMAIL } = constants_1.notificationTypes;
const sendEmail = async (data) => {
const { subject, to, content, text } = data;
const emailData = {
html: `<div>${content}</div>`,
subject: `${subject}`,
text: text || content,
to,
};
logger_1.default.info(`${NOTIFY_SERVICE} sendEmail: email will be sent with subject ${subject}`);
return (0, sendEmail_1.sendEmail)(emailData);
};
const notify = (type, data) => {
logger_1.default.info(`${NOTIFY_SERVICE} notify: notification of type ${type} will be sent`);
switch (type) {
case EMAIL:
try {
sendEmail(data);
}
catch (e) {
logger_1.default.error(e);
}
break;
default:
throw Error('Notification type is required');
}
};
exports.default = notify;
//# sourceMappingURL=notify.js.map