Remove booster if ExpiryDate lower than current time

This commit is contained in:
nyaoouo 2025-06-10 19:51:00 +08:00
parent ef8c81ee9e
commit 7957dc1e24

View File

@ -23,13 +23,21 @@ export const setBoosterController: RequestHandler = async (req, res) => {
res.status(400).send("Invalid ItemType provided.");
return;
}
// Remove if ExpiryDate lower than current time?
const now = Math.floor(Date.now() / 1000);
for (const { ItemType, ExpiryDate } of requests) {
const boosterItem = boosters.find(item => item.ItemType === ItemType);
if (boosterItem) {
boosterItem.ExpiryDate = ExpiryDate;
if (ExpiryDate > now) {
// remove expired boosters
const index = boosters.findIndex(item => item.ItemType === ItemType);
if (index !== -1) {
boosters.splice(index, 1);
}
} else {
boosters.push({ ItemType, ExpiryDate });
const boosterItem = boosters.find(item => item.ItemType === ItemType);
if (boosterItem) {
boosterItem.ExpiryDate = ExpiryDate;
} else {
boosters.push({ ItemType, ExpiryDate });
}
}
}
await inventory.save();