// /utils/notifyFlags.js 'use strict'; const NOTIFY_FIELD_KEYS = [ 'notify', 'notifySms', 'notifyEmail', 'notifyBot', 'sendSms', 'sendEmail', 'sendBot' ]; const toFlag = (value, fallback = true) => { if (value === undefined || value === null || value === '') return fallback; if (typeof value === 'boolean') return value; if (typeof value === 'number') return value !== 0; if (typeof value === 'string') { const normalized = value.trim().toLowerCase(); if (['false', '0', 'no', 'off'].includes(normalized)) return false; if (['true', '1', 'yes', 'on'].includes(normalized)) return true; } return fallback; }; const pickNotifyFlags = (source = {}) => { const nested = source && typeof source.notify === 'object' && source.notify !== null ? source.notify : {}; return { sms: toFlag(nested.sms ?? source.notifySms ?? source.sendSms, true), email: toFlag(nested.email ?? source.notifyEmail ?? source.sendEmail, true), bot: toFlag(nested.bot ?? source.notifyBot ?? source.sendBot, true) }; }; const omitNotifyFields = (source = {}) => { const next = { ...source }; NOTIFY_FIELD_KEYS.forEach((key) => { delete next[key]; }); return next; }; module.exports = { pickNotifyFlags, omitNotifyFields };