Merge pull request #345 from bluewave-labs/feat/details-calculations

Add logic for remaining details calculations
This commit is contained in:
Alexander Holliday authored and GitHub committed 2024-07-16 10:15:02 -07:00
commit dd15d7a27b
1 file changed
+6 -10
+6 -10
View File
@@ -61,33 +61,29 @@ const DetailsPage = () => {
/** /**
* Helper function to get timestamp of the most recent check. * Helper function to get timestamp of the most recent check.
* @param {Array} checks Array of check objects. * @param {Array} checks Array of check objects.
* @returns {string} Timestamp of the most recent check. * @returns {number} Timestamp of the most recent check.
* TODO - NEED TO REVISIT THIS FOR PROPER LOGIC.
*/ */
const getLastCheckedTimestamp = (checks) => { const getLastCheckedTimestamp = (checks) => {
if (!checks || checks.length === 0) { if (!checks || checks.length === 0) {
return "N/A"; // Handle case when no checks are available return 0; // Handle case when no checks are available
} }
const mostRecentCheck = checks[0]; const mostRecentCheck = checks[0];
return new Date(mostRecentCheck.createdAt).toLocaleString(); return mostRecentCheck.createdAt;
}; };
/** /**
* Helper function to count incidents (checks with status === false). * Helper function to count incidents (checks with status === false).
* @param {Array} checks Array of check objects. * @param {Array} checks Array of check objects.
* @returns {number} Number of incidents. * @returns {number} Number of incidents.
* TODO - NEED TO REVISIT THIS FOR PROPER LOGIC.
*/ */
const countIncidents = (checks) => { const countIncidents = (checks) => {
if (!checks || checks.length === 0) { if (!checks || checks.length === 0) {
return 0; // Handle case when no checks are available return 0; // Handle case when no checks are available
} }
return checks.reduce((acc, check) => {
// Count checks with status === false check.status === false ? (acc += 1) : acc;
// TODO - NEED TO REVISIT THIS FOR PROPER LOGIC. }, 0);
const incidentCount = checks.filter((check) => !check.status).length;
return incidentCount;
}; };
return ( return (