Add support for sending stats to Matrix, split out some code into more generic classes. #1

Open
rory.gay wants to merge 35 commits from rory.gay/freepbx-stats:main into main
Showing only changes of commit 6136dace7c - Show all commits

View file

@ -86,14 +86,15 @@ function getSystemUptime() {
*/ */
function updateRecords(callStats, records) { function updateRecords(callStats, records) {
const yesterday = getYesterday().startDate; const yesterday = getYesterday().startDate;
const yesterdayDateString = yesterday.toISOString().split('T')[0];
let isNewRecord = false; let isNewRecord = false;
// Update all-time record // Update all-time record
const allTimeRecord = records.callRecord || new CallRecord({ date: yesterday, count: 0 }); const allTimeRecord = records.callRecord || new CallRecord({ date: yesterdayDateString, count: 0 });
if (!records.callRecord) { if (!records.callRecord) {
records.callRecord = { date: currentDate, count: callStats.totalCallsMade }; records.callRecord = { date: yesterdayDateString, count: callStats.totalCallsMade };
isNewRecord = true; isNewRecord = true;
} else if (parseInt(allTimeRecord.count) < callStats.totalCallsThisMonth) { } else if (allTimeRecord.count < callStats.totalCallsThisMonth) {
allTimeRecord.count = callStats.totalCallsThisMonth; allTimeRecord.count = callStats.totalCallsThisMonth;
isNewRecord = true; isNewRecord = true;
} }