From 7682f191c730f483581654609449a80ce08191e8 Mon Sep 17 00:00:00 2001 From: PxlLoewe <72106766+PxlLoewe@users.noreply.github.com> Date: Sun, 6 Jul 2025 14:06:44 -0700 Subject: [PATCH] Fixed Automatische alarmierung nach validierung #45 --- apps/dispatch-server/modules/mission.ts | 51 ++++-- apps/dispatch-server/routes/mission.ts | 6 +- .../_components/pannel/MissionForm.tsx | 158 +++++++----------- .../map/_components/MissionMarkerTabs.tsx | 13 +- .../database/prisma/json/MissionVehicleLog.ts | 6 + 5 files changed, 109 insertions(+), 125 deletions(-) diff --git a/apps/dispatch-server/modules/mission.ts b/apps/dispatch-server/modules/mission.ts index 70f12f72..e79c95a8 100644 --- a/apps/dispatch-server/modules/mission.ts +++ b/apps/dispatch-server/modules/mission.ts @@ -9,7 +9,7 @@ export const sendAlert = async ( }: { stationId?: number; }, - user: User, + user: User | "HPG", ): Promise<{ connectedAircrafts: ConnectedAircraft[]; mission: Mission; @@ -89,23 +89,38 @@ export const sendAlert = async ( .catch((err) => { // Ignore if the entry already exists }); - - await prisma.mission.update({ - where: { id: Number(id) }, - data: { - state: "running", - missionLog: { - push: { - type: "alert-log", - auto: false, - timeStamp: new Date().toISOString(), - data: { - stationId: stationId, - user: getPublicUser(user, { ignorePrivacy: true }), - }, - } as any, + if (user === "HPG") { + await prisma.mission.update({ + where: { id: Number(id) }, + data: { + state: "running", + missionLog: { + push: { + type: "alert-log", + auto: true, + timeStamp: new Date().toISOString(), + } as any, + }, }, - }, - }); + }); + } else { + await prisma.mission.update({ + where: { id: Number(id) }, + data: { + state: "running", + missionLog: { + push: { + type: "alert-log", + auto: false, + timeStamp: new Date().toISOString(), + data: { + stationId: stationId, + user: getPublicUser(user, { ignorePrivacy: true }), + }, + } as any, + }, + }, + }); + } return { connectedAircrafts, mission }; }; diff --git a/apps/dispatch-server/routes/mission.ts b/apps/dispatch-server/routes/mission.ts index 7d9f0494..a58a9d94 100644 --- a/apps/dispatch-server/routes/mission.ts +++ b/apps/dispatch-server/routes/mission.ts @@ -250,7 +250,6 @@ router.post("/:id/hpg-validation-result", async (req, res) => { }, }); io.to("dispatchers").emit("update-mission", newMission); - const noActionRequired = result.state === "VALID"; if (noActionRequired) { io.to(`user:${result.userId}`).emit("notification", { @@ -262,9 +261,10 @@ router.post("/:id/hpg-validation-result", async (req, res) => { }, } as NotificationPayload); + console.log("Got positiv validation Result", result.alertWhenValid); if (result.alertWhenValid) { - if (!req.user) return; - sendAlert(Number(missionId), {}, req.user); + console.log(req.user); + sendAlert(Number(missionId), {}, "HPG"); } } else { io.to(`user:${result.userId}`).emit("notification", { diff --git a/apps/dispatch/app/(app)/dispatch/_components/pannel/MissionForm.tsx b/apps/dispatch/app/(app)/dispatch/_components/pannel/MissionForm.tsx index 1b272c4e..cfb0f371 100644 --- a/apps/dispatch/app/(app)/dispatch/_components/pannel/MissionForm.tsx +++ b/apps/dispatch/app/(app)/dispatch/_components/pannel/MissionForm.tsx @@ -165,16 +165,6 @@ export const MissionForm = () => { ...(mission as unknown as Prisma.MissionCreateInput), hpgSelectedMissionString: szenarioCode, }); - if (validationRequired) { - await startHpgValidation(newMission.id, { - alertWhenValid, - }).catch((error) => { - toast.error(`Fehler beim Starten der HPG-Validierung: ${error.message}`); - }); - } else if (alertWhenValid) { - await sendAlertMutation.mutateAsync(newMission.id); - } - return newMission; } else { newMission = await editMissionMutation.mutateAsync({ id: Number(editingMissionId), @@ -189,14 +179,18 @@ export const MissionForm = () => { }, }); } + if (validationRequired) { - await startHpgValidation(newMission.id, {}).catch((error) => { + await startHpgValidation(newMission.id, { + alertWhenValid, + }).catch((error) => { toast.error(`Fehler beim Starten der HPG-Validierung: ${error.message}`); }); + } else if (alertWhenValid) { + await sendAlertMutation.mutateAsync(newMission.id); } return newMission; }; - console.log(form.watch("missionStationIds")); return (
diff --git a/apps/dispatch/app/_components/map/_components/MissionMarkerTabs.tsx b/apps/dispatch/app/_components/map/_components/MissionMarkerTabs.tsx index bfa0493d..c1f68a05 100644 --- a/apps/dispatch/app/_components/map/_components/MissionMarkerTabs.tsx +++ b/apps/dispatch/app/_components/map/_components/MissionMarkerTabs.tsx @@ -741,7 +741,9 @@ const FMSStatusHistory = ({ mission }: { mission: Mission }) => { ); if (entry.type === "alert-log") { - const alertReceiver = entry.data.station?.bosCallsignShort || entry.data.vehicle; + const alertReceiver = entry.auto + ? null + : entry.data.station?.bosCallsignShort || entry.data.vehicle; return (