// services/voiceReport/storeContext.js // Resolve Webex location + timezone for a store number. import webex from '../../integrations/webex/WebexClient.js'; import { logger } from '../../utils/logger.js'; import { DISPLAY_TIMEZONE } from '../../utils/time.js'; import { resolveStoreMainNumber } from '../callTest/storeResolver.js'; const LOG_SCOPE = 'voicereport:store'; /** * @param {string} storeNum * @returns {Promise<{ storeNum, personId, locationId, locationName, dialNumber, timeZone, email }>} */ export async function resolveStoreForVoiceReport(storeNum) { const base = await resolveStoreMainNumber(storeNum); let timeZone = DISPLAY_TIMEZONE; try { const [profile, location] = await Promise.all([ webex.request('GET', `telephony/config/people/${base.personId}`).catch(() => null), base.locationId ? webex.request('GET', `telephony/config/locations/${base.locationId}`).catch(() => null) : null, ]); timeZone = profile?.timeZone || location?.timeZone || location?.timezone || timeZone; } catch (err) { logger(LOG_SCOPE, `Timezone lookup failed for store ${storeNum}: ${err.message}`, 'debug'); } const padded = String(storeNum).trim().padStart(5, '0'); return { ...base, timeZone, email: `ae${padded}@ae.com`, }; }