removed cron job that made rentals active. Now whether or not the rental is active is determined on the fly

This commit is contained in:
jackiettran
2026-01-02 17:08:49 -05:00
parent bc01c818aa
commit 4209dcc8fc
17 changed files with 142 additions and 162 deletions

View File

@@ -0,0 +1,41 @@
/**
* Utility functions for computing rental status on-the-fly.
* The "active" status is computed based on timestamps rather than stored in the database.
* A rental is considered "active" when it has status "confirmed" and startDateTime has passed.
*/
/**
* Returns the effective/display status of a rental.
* If the rental is "confirmed" and the start time has passed, returns "active".
* Otherwise returns the stored status.
* @param {Object} rental - The rental object with status and startDateTime
* @returns {string} The effective status
*/
function getEffectiveStatus(rental) {
const now = new Date();
if (
rental.status === "confirmed" &&
new Date(rental.startDateTime) <= now
) {
return "active";
}
return rental.status;
}
/**
* Checks if a rental is currently active.
* A rental is active when it's confirmed and the start time has passed.
* @param {Object} rental - The rental object with status and startDateTime
* @returns {boolean} True if the rental is currently active
*/
function isActive(rental) {
const now = new Date();
return (
rental.status === "confirmed" && new Date(rental.startDateTime) <= now
);
}
module.exports = {
getEffectiveStatus,
isActive,
};