Compare commits

...

2 Commits

Author SHA1 Message Date
nyaoouo
58ea73a116 fix logical error 2025-06-10 21:12:49 +08:00
nyaoouo
7957dc1e24 Remove booster if ExpiryDate lower than current time 2025-06-10 19:51:00 +08:00

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();