Add logic for remaining calculations

This commit is contained in:
Alex Holliday committed 2024-07-16 10:07:04 -07:00
1 parent 1833b113f9
commit 87c04cd89a
1 file changed
+6 -10
+6 -10
View File
@@ -58,33 +58,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 (