Error logging, go back 2 years and 0 contact
handling
This commit is contained in:
parent
51f68d5021
commit
4650a4d5a3
@ -116,7 +116,7 @@ router.get("/", (req, res) => {
|
||||
}
|
||||
}`;
|
||||
var startTime = new Date(
|
||||
new Date().setFullYear(new Date().getFullYear() - 1)
|
||||
new Date().setFullYear(new Date().getFullYear() - 2)
|
||||
);
|
||||
var endTime = new Date(new Date().setHours(new Date().getHours() - 1));
|
||||
|
||||
@ -136,6 +136,17 @@ router.get("/", (req, res) => {
|
||||
)
|
||||
.then((result) => {
|
||||
var contacts = result.data.data.findContactsCompletedBetween.edges;
|
||||
|
||||
// Log error to console
|
||||
if (result.data.errors && result.data.errors.length > 0) {
|
||||
result.data.errors.forEach(function (error, i) {
|
||||
console.log("ERROR: Errors in results - " + error.message);
|
||||
});
|
||||
|
||||
// TODO: Should keep errors for filteredContacts
|
||||
result.data.errors = [];
|
||||
}
|
||||
|
||||
var filteredContacts = [];
|
||||
contacts.forEach(function (contact, i) {
|
||||
if (contact.node.interaction.__typename === "Email") {
|
||||
@ -162,40 +173,41 @@ router.get("/", (req, res) => {
|
||||
summary.totalInboundCount = 0;
|
||||
summary.totalInboundActiveSeconds = 0;
|
||||
|
||||
summary.firstContactReceivedDate = new Date(
|
||||
filteredContacts[0].node.interaction.receivedDate
|
||||
);
|
||||
if (summary.totalCount > 0) {
|
||||
summary.firstContactReceivedDate = new Date(
|
||||
filteredContacts[0].node.interaction.receivedDate
|
||||
);
|
||||
|
||||
filteredContacts.forEach(function (contact, i) {
|
||||
if (contact.node.direction === "INBOUND") {
|
||||
summary.totalInboundCount++;
|
||||
if (!summary.firstInboundContactStartDate) {
|
||||
summary.firstInboundContactStartDate = new Date(
|
||||
contact.node.startTime
|
||||
);
|
||||
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.firstContactReceivedDate = new Date(
|
||||
contact.node.interaction.receivedDate
|
||||
);
|
||||
}
|
||||
summary.totalInboundActiveSeconds += contact.node.activeDuration;
|
||||
}
|
||||
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
|
||||
);
|
||||
|
||||
summary.totalHTHours =
|
||||
(summary.lastContactEndTime.getTime() -
|
||||
summary.firstContactReceivedDate.getTime()) /
|
||||
(1000 * 3600);
|
||||
summary.activeHTMinutes =
|
||||
(summary.lastContactEndTime.getTime() -
|
||||
summary.firstInboundContactStartDate.getTime()) /
|
||||
(1000 * 60);
|
||||
// TODO: Because of overlapping contacts, we may need to calculate max instead of last.
|
||||
summary.lastContactEndTime = new Date(
|
||||
filteredContacts[filteredContacts.length - 1].node.endTime
|
||||
);
|
||||
|
||||
summary.totalHTHours =
|
||||
(summary.lastContactEndTime.getTime() -
|
||||
summary.firstContactReceivedDate.getTime()) /
|
||||
(1000 * 3600);
|
||||
summary.activeHTMinutes =
|
||||
(summary.lastContactEndTime.getTime() -
|
||||
summary.firstInboundContactStartDate.getTime()) /
|
||||
(1000 * 60);
|
||||
}
|
||||
result.data.data.summary = summary;
|
||||
|
||||
if (result.data) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user