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:
41
backend/utils/rentalStatus.js
Normal file
41
backend/utils/rentalStatus.js
Normal 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,
|
||||
};
|
||||
Reference in New Issue
Block a user