"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.smsHandler = void 0; exports.tryMakeSmsNotification = tryMakeSmsNotification; const tslib_1 = require("tslib"); const assert_1 = tslib_1.__importDefault(require("assert")); const index_1 = require("./index"); const uuid_1 = require("oak-domain/lib/utils/uuid"); const smsHandler = async ({ message, applications, system, context }) => { const notificationDatas = []; const smsNotification = await tryMakeSmsNotification(message, context); if (smsNotification) { notificationDatas.push(smsNotification); } return notificationDatas; }; exports.smsHandler = smsHandler; async function tryMakeSmsNotification(message, context) { const { userId, type, entity, entityId, router } = message; (0, assert_1.default)(userId); const [mobile] = await context.select('mobile', { data: { id: 1, mobile: 1, }, filter: { userId, }, indexFrom: 0, count: 1, }, { dontCollect: true }); if (mobile) { const converter = index_1.ConverterDict[type] && index_1.ConverterDict[type].sms; if (converter) { const dispersedData = await converter(message, context); if (dispersedData) { return { id: await (0, uuid_1.generateNewIdAsync)(), data: dispersedData, channel: 'sms', data1: mobile, }; } } } }