UNPKG

kod-temp

Version:

Workano Communications SDK

57 lines (56 loc) 2.72 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); // addUser.ts const index_1 = __importDefault(require("../../lib/index")); class default_1 { static listCallLogs(offset, limit) { return __awaiter(this, void 0, void 0, function* () { const callLogs = yield index_1.default.callLogd.listCallLogs(offset, limit); // Process the call logs to create a more readable data structure const groupedLogs = {}; callLogs.forEach((cl) => { const isOutgoing = cl.callDirection === "outbound"; const contactNumber = isOutgoing ? cl.destination.extension : cl.source.extension; const contactName = isOutgoing ? cl.destination.name : cl.source.name; const simplifiedLog = { id: cl.id, time: cl.start.toISOString().split("T")[1].substr(0, 8), // HH:MM:SS duration: cl.duration, isOutgoing, contactName: contactName || "", contactNumber, answered: cl.answered, recordings: cl.recordings, }; const date = cl.start.toISOString().split("T")[0]; // YYYY-MM-DD if (!groupedLogs[date]) { groupedLogs[date] = []; } groupedLogs[date].push(simplifiedLog); }); // Convert the grouped logs into an array const result = Object.keys(groupedLogs) .sort((a, b) => new Date(b).getTime() - new Date(a).getTime()) // Sort dates descending .map((date) => ({ date, calls: groupedLogs[date], })); return result; }); } } exports.default = default_1;