Created
April 13, 2021 08:45
-
-
Save DulalSandip/553612a20566eff1b0f2fb9f22acf3c0 to your computer and use it in GitHub Desktop.
server running continously (app.js)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const couponCodeDiscount = require("./routes/CouponCode.Routes"); | |
app.use("/api", couponCodeDiscount); | |
// checking coupon code expiration time valid or not to reduce server load | |
const checkExpirationTime = () => { | |
CouponCodeDiscount.find({}) | |
.exec() | |
.then((Coupon) => { | |
if (Coupon) { | |
Coupon.map((getCoupon) => { | |
if ( | |
new Date().getTime() >= new Date(getCoupon.expirationTime).getTime() // expirationTime data access from database | |
) { | |
CouponCodeDiscount.findOneAndDelete({ | |
_id: getCoupon._id, | |
}) | |
.exec() | |
.then((deleteCoupon) => { | |
console.log(`Coupon doesnt exists or expired`); | |
}) | |
.catch((error) => { | |
console.log(error, "Error occured on coupon section"); | |
}); | |
} | |
}); | |
} | |
if (!Coupon) { | |
console.log("No Coupon found..."); | |
} | |
}); | |
}; | |
setInterval(checkExpirationTime, 1000); // converting to millisecond |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment