diff --git a/apps/core-server/modules/chron.ts b/apps/core-server/modules/chron.ts index 8cfe33c6..f0cfde22 100644 --- a/apps/core-server/modules/chron.ts +++ b/apps/core-server/modules/chron.ts @@ -98,13 +98,25 @@ const removeClosedMissions = async () => { if (!lastAlertTime) return; + const lastStatus1or6Log = (mission.missionLog as unknown as MissionLog[]) + .filter((l) => { + return ( + l.type === "station-log" && (l.data?.newFMSstatus === "1" || l.data?.newFMSstatus === "6") + ); + }) + .sort((a, b) => new Date(b.timeStamp).getTime() - new Date(a.timeStamp).getTime())[0]; + // Case 1: Forgotten Mission, last alert more than 3 Hours ago const now = new Date(); if (now.getTime() - lastAlertTime.getTime() > 1000 * 60 * 180) return removeMission(mission.id, "inaktivität"); - // Case 2: All stations in mission changed from status 4 to 1/6 or from status 8 to 1/6 - if (allStationsInMissionChangedFromStatus4to1Or8to1) + // Case 2: All stations in mission changed from status 4 to 1/6 or from status 8 to 1/6, Status 1/6 change less more 5 minutes ago + if ( + allStationsInMissionChangedFromStatus4to1Or8to1 && + lastStatus1or6Log && + now.getTime() - new Date(lastStatus1or6Log.timeStamp).getTime() > 1000 * 60 * 5 + ) return removeMission(mission.id, "dem freimelden aller Stationen"); }); };