diff --git a/src/controllers/custom/setBoosterController.ts b/src/controllers/custom/setBoosterController.ts index f19a3093..ceb45e30 100644 --- a/src/controllers/custom/setBoosterController.ts +++ b/src/controllers/custom/setBoosterController.ts @@ -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();