This commit is contained in:
parent
d7cebcb7f5
commit
4b2be3144b
@ -139,52 +139,68 @@ router.get("/", (req, res) => {
|
|||||||
.then((result) => {
|
.then((result) => {
|
||||||
var contacts = result.data.data.findContactsCompletedBetween.edges;
|
var contacts = result.data.data.findContactsCompletedBetween.edges;
|
||||||
var filteredContacts = [];
|
var filteredContacts = [];
|
||||||
for (const contact of contacts) {
|
contacts.forEach(function (contact, i) {
|
||||||
if (
|
if (contact.node.interaction.__typename === "Email") {
|
||||||
contact.node.interaction.__typename === "Email" &&
|
// threadId if Reference in Subject line will do
|
||||||
contact.node.interaction.threadId === threadId
|
if (
|
||||||
) {
|
(contact.node.interaction.threadId === threadId) |
|
||||||
filteredContacts.push(contact);
|
contact.node.interaction.subject.includes(`<< Ref:${threadId} >>`)
|
||||||
|
) {
|
||||||
|
filteredContacts.push(contact);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
result.data.data.findContactsCompletedBetween.edges = filteredContacts;
|
result.data.data.findContactsCompletedBetween.edges = filteredContacts;
|
||||||
result.data.data.findContactsCompletedBetween.totalCount =
|
result.data.data.findContactsCompletedBetween.totalCount =
|
||||||
filteredContacts.length;
|
filteredContacts.length;
|
||||||
|
|
||||||
// calculate elapsed
|
// Summary Values
|
||||||
var contactReceived = new Date(
|
var summary = {};
|
||||||
|
|
||||||
|
summary.totalCount = filteredContacts.length;
|
||||||
|
summary.totalInboundCount = 0;
|
||||||
|
summary.totalInboundActiveSeconds = 0;
|
||||||
|
|
||||||
|
summary.firstContactReceivedDate = new Date(
|
||||||
filteredContacts[0].node.interaction.receivedDate
|
filteredContacts[0].node.interaction.receivedDate
|
||||||
);
|
);
|
||||||
var lastContactEndTime = new Date(
|
|
||||||
|
filteredContacts.forEach(function (contact, i) {
|
||||||
|
if (contact.node.direction === "INBOUND") {
|
||||||
|
summary.totalInboundCount++;
|
||||||
|
if (!summary.firstInboundContactStartDate) {
|
||||||
|
summary.firstInboundContactStartDate = new Date(
|
||||||
|
contact.node.startTime
|
||||||
|
);
|
||||||
|
|
||||||
|
summary.firstContactReceivedDate = new Date(
|
||||||
|
contact.node.interaction.receivedDate
|
||||||
|
);
|
||||||
|
}
|
||||||
|
summary.totalInboundActiveSeconds += contact.node.activeDuration;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// TODO: Because of overlapping contacts, we may need to calculate max instead of last.
|
||||||
|
summary.lastContactEndTime = new Date(
|
||||||
filteredContacts[filteredContacts.length - 1].node.endTime
|
filteredContacts[filteredContacts.length - 1].node.endTime
|
||||||
);
|
);
|
||||||
var firstContactStartTime = new Date(
|
|
||||||
filteredContacts[0].node.startTime
|
|
||||||
);
|
|
||||||
|
|
||||||
var totalHTDays =
|
summary.totalHTDays =
|
||||||
(lastContactEndTime.getTime() - contactReceived.getTime()) /
|
(summary.lastContactEndTime.getTime() -
|
||||||
(1000 * 3600 * 24);
|
summary.firstContactReceivedDate.getTime()) /
|
||||||
var activeHTDays =
|
(1000 * 3600);
|
||||||
(lastContactEndTime.getTime() - firstContactStartTime.getTime()) /
|
summary.activeHTMinutes =
|
||||||
(1000 * 3600 * 24);
|
(summary.lastContactEndTime.getTime() -
|
||||||
// var totalATHours = (lastContactEndTime.getTime() - firstContactStartTime.getTime()) / (1000 * 3600);
|
summary.firstInboundContactStartDate.getTime()) /
|
||||||
var totalATSeconds = 0;
|
(1000 * 60);
|
||||||
for (const contact of filteredContacts) {
|
|
||||||
totalATSeconds += contact.node.activeDuration;
|
|
||||||
}
|
|
||||||
var totalATHours = totalATSeconds / (60 * 60);
|
|
||||||
|
|
||||||
result.data.data.findContactsCompletedBetween.totalHTDays =
|
result.data.data.summary = summary;
|
||||||
totalHTDays.toPrecision(5);
|
|
||||||
result.data.data.findContactsCompletedBetween.activeHTDays =
|
|
||||||
activeHTDays.toPrecision(5);
|
|
||||||
result.data.data.findContactsCompletedBetween.totalATHours =
|
|
||||||
totalATHours.toPrecision(5);
|
|
||||||
|
|
||||||
if (result.data) {
|
if (result.data) {
|
||||||
console.log(
|
console.log(
|
||||||
util.inspect(result.data, {
|
util.inspect(summary, {
|
||||||
showHidden: false,
|
showHidden: false,
|
||||||
depth: null,
|
depth: null,
|
||||||
colors: true,
|
colors: true,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user