collabSupport/services/callReport/storeContext.js
jmcqueen a25fc08fe2 Rename /voicereport to /callreport with scoped user and phone targets.
Add store/email/phone filtering, richer call-line formatting, CDR feed pagination and queueing, and split Jira poller enrichment into testable modules.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-27 10:10:03 -04:00

37 lines
1.3 KiB
JavaScript

// services/callReport/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 = 'callreport:store';
/**
* @param {string} storeNum
* @returns {Promise<{ storeNum, personId, locationId, locationName, dialNumber, timeZone, email }>}
*/
export async function resolveStoreForCallReport(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`,
};
}