diff --git a/.prettierrc b/.prettierrc index cf5eb531..28e2d060 100644 --- a/.prettierrc +++ b/.prettierrc @@ -2,5 +2,6 @@ "tabWidth": 2, "useTabs": true, "printWidth": 100, - "singleQuote": false + "singleQuote": false, + "plugins": ["prettier-plugin-tailwindcss"] } diff --git a/apps/core-server/modules/chron.ts b/apps/core-server/modules/chron.ts index 7f8764db..8cfe33c6 100644 --- a/apps/core-server/modules/chron.ts +++ b/apps/core-server/modules/chron.ts @@ -2,6 +2,39 @@ import { MissionLog, NotificationPayload, prisma } from "@repo/db"; import { io } from "index"; import cron from "node-cron"; +const removeMission = async (id: number, reason: string) => { + const log: MissionLog = { + type: "completed-log", + auto: true, + timeStamp: new Date().toISOString(), + data: {}, + }; + + const updatedMission = await prisma.mission.update({ + where: { + id: id, + }, + data: { + state: "finished", + missionLog: { + push: log as any, + }, + }, + }); + io.to("dispatchers").emit("new-mission", { updatedMission }); + io.to("dispatchers").emit("notification", { + type: "mission-auto-close", + status: "chron", + message: `Einsatz ${updatedMission.publicId} wurde aufgrund ${reason} geschlossen.`, + data: { + missionId: updatedMission.id, + publicMissionId: updatedMission.publicId, + }, + } as NotificationPayload); + + console.log(`Mission ${updatedMission.id} closed due to inactivity.`); +}; + const removeClosedMissions = async () => { const oldMissions = await prisma.mission.findMany({ where: { @@ -15,18 +48,6 @@ const removeClosedMissions = async () => { const lastAlertTime = lastAlert ? new Date(lastAlert.timeStamp) : null; - const aircraftsInMission = await prisma.connectedAircraft.findMany({ - where: { - stationId: { - in: mission.missionStationIds, - }, - }, - }); - - const allConnectedAircraftsInIdleStatus = aircraftsInMission.every((a) => - ["1", "2", "6"].includes(a.fmsStatus), - ); - const allStationsInMissionChangedFromStatus4to1Or8to1 = mission.missionStationIds.every( (stationId) => { const status4Log = (mission.missionLog as unknown as MissionLog[]).findIndex((l) => { @@ -69,67 +90,24 @@ const removeClosedMissions = async () => { }, ); - const missionHastManualReactivation = (mission.missionLog as unknown as MissionLog[]).some( + const missionHasManualReactivation = (mission.missionLog as unknown as MissionLog[]).some( (l) => l.type === "reopened-log", ); - console.log({ - missionId: mission.publicId, - allConnectedAircraftsInIdleStatus, - lastAlertTime, - allStationsInMissionChangedFromStatus4to1Or8to1, - missionHastManualReactivation, - }); - if ( - !allConnectedAircraftsInIdleStatus // If some aircrafts are still active, do not close the mission - ) - return; - const now = new Date(); + if (missionHasManualReactivation) return; + if (!lastAlertTime) return; // Case 1: Forgotten Mission, last alert more than 3 Hours ago - // Case 2: All stations in mission changed from status 4 to 1 or from status 8 to 1 - if ( - !( - now.getTime() - lastAlertTime.getTime() > 1000 * 60 * 180 || - allStationsInMissionChangedFromStatus4to1Or8to1 - ) || - missionHastManualReactivation - ) - return; + const now = new Date(); + if (now.getTime() - lastAlertTime.getTime() > 1000 * 60 * 180) + return removeMission(mission.id, "inaktivität"); - const log: MissionLog = { - type: "completed-log", - auto: true, - timeStamp: new Date().toISOString(), - data: {}, - }; - - const updatedMission = await prisma.mission.update({ - where: { - id: mission.id, - }, - data: { - state: "finished", - missionLog: { - push: log as any, - }, - }, - }); - io.to("dispatchers").emit("new-mission", { updatedMission }); - io.to("dispatchers").emit("notification", { - type: "mission-auto-close", - status: "chron", - message: `Einsatz ${updatedMission.publicId} wurde aufgrund ${allStationsInMissionChangedFromStatus4to1Or8to1 ? "des Freimeldens aller Stationen" : "von Inaktivität"} geschlossen.`, - data: { - missionId: updatedMission.id, - publicMissionId: updatedMission.publicId, - }, - } as NotificationPayload); - console.log(`Mission ${mission.id} closed due to inactivity.`); + // Case 2: All stations in mission changed from status 4 to 1/6 or from status 8 to 1/6 + if (allStationsInMissionChangedFromStatus4to1Or8to1) + return removeMission(mission.id, "dem freimelden aller Stationen"); }); }; - const removeConnectedAircrafts = async () => { const connectedAircrafts = await prisma.connectedAircraft.findMany({ where: { diff --git a/apps/core-server/package.json b/apps/core-server/package.json index 210ed116..ecee9ece 100644 --- a/apps/core-server/package.json +++ b/apps/core-server/package.json @@ -8,31 +8,30 @@ "start": "tsx index.ts --transpile-only", "build": "tsc" }, - "packageManager": "pnpm@10.11.0", + "packageManager": "pnpm@10.13.1", "devDependencies": { "@repo/db": "workspace:*", "@repo/typescript-config": "workspace:*", - "@types/cors": "^2.8.18", - "@types/express": "^5.0.2", + "@types/cors": "^2.8.19", + "@types/express": "^5.0.3", "@types/node": "^22.15.29", "@types/nodemailer": "^6.4.17", - "concurrently": "^9.1.2", + "concurrently": "^9.2.0", "typescript": "latest" }, "dependencies": { "@socket.io/redis-adapter": "^8.3.0", - "axios": "^1.9.0", "cors": "^2.8.5", - "cron": "^4.3.1", - "discord.js": "^14.19.3", - "dotenv": "^16.5.0", + "cron": "^4.3.2", + "discord.js": "^14.21.0", + "dotenv": "^17.2.0", "express": "^5.1.0", - "node-cron": "^4.1.0", + "node-cron": "^4.2.1", "nodemon": "^3.1.10", "prom-client": "^15.1.3", "react": "^19.1.0", - "redis": "^5.1.1", + "redis": "^5.6.0", "socket.io": "^4.8.1", - "tsx": "^4.19.4" + "tsx": "^4.20.3" } } diff --git a/apps/core-server/routes/helper.ts b/apps/core-server/routes/helper.ts index 2ba6edfc..2bd0f5c2 100644 --- a/apps/core-server/routes/helper.ts +++ b/apps/core-server/routes/helper.ts @@ -19,7 +19,6 @@ router.post("/set-standard-name", async (req, res) => { id: userId, }, }); - console.log(`Setting standard name for user ${userId} (${user?.publicId}) to member ${memberId}`); if (!user) { res.status(404).json({ error: "User not found" }); return; diff --git a/apps/dispatch-server/package.json b/apps/dispatch-server/package.json index 272c5302..678c611d 100644 --- a/apps/dispatch-server/package.json +++ b/apps/dispatch-server/package.json @@ -8,39 +8,39 @@ "start": "tsx index.ts --transpile-only", "build": "tsc" }, - "packageManager": "pnpm@10.11.0", + "packageManager": "pnpm@10.13.1", "devDependencies": { "@repo/db": "workspace:*", "@repo/shared-components": "workspace:*", "@repo/typescript-config": "workspace:*", - "@types/cookie-parser": "^1.4.8", - "@types/cors": "^2.8.18", - "@types/express": "^5.0.2", + "@types/cookie-parser": "^1.4.9", + "@types/cors": "^2.8.19", + "@types/express": "^5.0.3", "@types/node": "^22.15.29", "@types/nodemailer": "^6.4.17", - "concurrently": "^9.1.2", + "concurrently": "^9.2.0", "typescript": "latest" }, "dependencies": { - "@react-email/components": "^0.0.41", - "@redis/json": "^5.1.1", + "@react-email/components": "^0.3.2", + "@redis/json": "^5.6.0", "@socket.io/redis-adapter": "^8.3.0", - "@types/jsonwebtoken": "^9.0.9", - "axios": "^1.9.0", + "@types/jsonwebtoken": "^9.0.10", + "axios": "^1.10.0", "cookie-parser": "^1.4.7", "cors": "^2.8.5", - "cron": "^4.3.1", - "dotenv": "^16.5.0", + "cron": "^4.3.2", + "dotenv": "^17.2.0", "express": "^5.1.0", "jsonwebtoken": "^9.0.2", - "livekit-server-sdk": "^2.13.0", - "node-cron": "^4.1.0", - "nodemailer": "^7.0.3", + "livekit-server-sdk": "^2.13.1", + "node-cron": "^4.2.1", + "nodemailer": "^7.0.5", "nodemon": "^3.1.10", "prom-client": "^15.1.3", "react": "^19.1.0", - "redis": "^5.1.1", + "redis": "^5.6.0", "socket.io": "^4.8.1", - "tsx": "^4.19.4" + "tsx": "^4.20.3" } } diff --git a/apps/dispatch-server/routes/mission.ts b/apps/dispatch-server/routes/mission.ts index 5542c64a..0f9032ca 100644 --- a/apps/dispatch-server/routes/mission.ts +++ b/apps/dispatch-server/routes/mission.ts @@ -261,9 +261,7 @@ router.post("/:id/hpg-validation-result", async (req, res) => { }, } as NotificationPayload); - console.log("Got positiv validation Result", result.alertWhenValid); if (result.alertWhenValid) { - console.log(req.user); sendAlert(Number(missionId), {}, "HPG"); } } else { diff --git a/apps/dispatch-server/socket-events/connect-dispatch.ts b/apps/dispatch-server/socket-events/connect-dispatch.ts index ddd6528c..06e485fe 100644 --- a/apps/dispatch-server/socket-events/connect-dispatch.ts +++ b/apps/dispatch-server/socket-events/connect-dispatch.ts @@ -45,15 +45,10 @@ export const handleConnectDispatch = }); } - const [logoffHours, logoffMinutes] = logoffTime.split(":").map(Number); - const connectedDispatcherEntry = await prisma.connectedDispatcher.create({ data: { publicUser: getPublicUser(user) as any, - esimatedLogoutTime: - logoffHours !== undefined && logoffMinutes !== undefined - ? getNextDateWithTime(logoffHours, logoffMinutes) - : null, + esimatedLogoutTime: logoffTime.length > 0 ? logoffTime : null, lastHeartbeat: new Date().toISOString(), userId: user.id, zone: selectedZone, diff --git a/apps/dispatch-server/socket-events/connect-pilot.ts b/apps/dispatch-server/socket-events/connect-pilot.ts index 0f9b4118..07c15850 100644 --- a/apps/dispatch-server/socket-events/connect-pilot.ts +++ b/apps/dispatch-server/socket-events/connect-pilot.ts @@ -73,15 +73,11 @@ export const handleConnectPilot = } const randomPos = debug ? getRandomGermanPosition() : undefined; - const [logoffHours, logoffMinutes] = logoffTime.split(":").map(Number); const connectedAircraftEntry = await prisma.connectedAircraft.create({ data: { publicUser: getPublicUser(user) as any, - esimatedLogoutTime: - logoffHours !== undefined && logoffMinutes !== undefined - ? getNextDateWithTime(logoffHours, logoffMinutes) - : null, + esimatedLogoutTime: logoffTime.length > 0 ? logoffTime : null, userId: userId, stationId: parseInt(stationId), lastHeartbeat: debug ? nowPlus2h.toISOString() : undefined, diff --git a/apps/dispatch-server/socket-events/send-message.ts b/apps/dispatch-server/socket-events/send-message.ts index cafa37b2..d6b8a39c 100644 --- a/apps/dispatch-server/socket-events/send-message.ts +++ b/apps/dispatch-server/socket-events/send-message.ts @@ -8,7 +8,6 @@ export const handleSendMessage = { userId, message }: { userId: string; message: string }, cb: (err: { error?: string }) => void, ) => { - console.log("send-message", userId, message); const senderId = socket.data.user.id; const senderUser = await prisma.user.findUnique({ diff --git a/apps/dispatch/app/(app)/dispatch/_components/StationSelect.tsx b/apps/dispatch/app/(app)/dispatch/_components/StationSelect.tsx index 09e3283b..f435050e 100644 --- a/apps/dispatch/app/(app)/dispatch/_components/StationSelect.tsx +++ b/apps/dispatch/app/(app)/dispatch/_components/StationSelect.tsx @@ -107,7 +107,6 @@ export function StationsSelect({ menuPlacement={menuPlacement} isMulti={isMulti} onChange={(v) => { - console.log("Selected values:", v); setValue(v); if (!isMulti) { const singleValue = v as string; diff --git a/apps/dispatch/app/(app)/dispatch/_components/navbar/_components/Connection.tsx b/apps/dispatch/app/(app)/dispatch/_components/navbar/_components/Connection.tsx index 2bb6bbab..c7fe631c 100644 --- a/apps/dispatch/app/(app)/dispatch/_components/navbar/_components/Connection.tsx +++ b/apps/dispatch/app/(app)/dispatch/_components/navbar/_components/Connection.tsx @@ -31,9 +31,9 @@ export const ConnectionBtn = () => { if (!uid) return null; return ( -