|
|
|
|
@@ -13,6 +13,7 @@ import { Router } from "express";
|
|
|
|
|
import { io } from "../index";
|
|
|
|
|
import { sendNtfyMission } from "modules/ntfy";
|
|
|
|
|
import { sendAlert } from "modules/mission";
|
|
|
|
|
import { userInfo } from "os";
|
|
|
|
|
|
|
|
|
|
const router: Router = Router();
|
|
|
|
|
|
|
|
|
|
@@ -192,25 +193,90 @@ router.post("/:id/send-alert", async (req, res) => {
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
router.post("/:id/send-sds", async (req, res) => {
|
|
|
|
|
const sdsMessage = req.body as MissionSdsLog;
|
|
|
|
|
const newMission = await prisma.mission.update({
|
|
|
|
|
where: {
|
|
|
|
|
id: Number(req.params.id),
|
|
|
|
|
},
|
|
|
|
|
data: {
|
|
|
|
|
missionLog: {
|
|
|
|
|
push: sdsMessage as any,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
router.post("/send-sds", async (req, res) => {
|
|
|
|
|
const { sdsMessage, missionId } = req.body as {
|
|
|
|
|
missionId?: number;
|
|
|
|
|
sdsMessage: MissionSdsLog;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
io.to(`station:${sdsMessage.data.stationId}`).emit("sds-message", sdsMessage);
|
|
|
|
|
res.json({
|
|
|
|
|
message: "SDS message sent",
|
|
|
|
|
mission: newMission,
|
|
|
|
|
});
|
|
|
|
|
io.to("dispatchers").emit("update-mission", newMission);
|
|
|
|
|
if (missionId) {
|
|
|
|
|
const newMission = await prisma.mission.update({
|
|
|
|
|
where: {
|
|
|
|
|
id: Number(missionId),
|
|
|
|
|
},
|
|
|
|
|
data: {
|
|
|
|
|
missionLog: {
|
|
|
|
|
push: sdsMessage as any,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
res.json({
|
|
|
|
|
message: "SDS message sent",
|
|
|
|
|
mission: newMission,
|
|
|
|
|
});
|
|
|
|
|
io.to("dispatchers").emit("update-mission", newMission);
|
|
|
|
|
} else {
|
|
|
|
|
res.json({
|
|
|
|
|
message: "SDS message sent",
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
router.post("/:id/hpg-validation-result", async (req, res) => {
|
|
|
|
|
try {
|
|
|
|
|
const missionId = req.params.id;
|
|
|
|
|
const result = req.body as {
|
|
|
|
|
state: HpgValidationState;
|
|
|
|
|
lat: number;
|
|
|
|
|
lng: number;
|
|
|
|
|
alertWhenValid?: boolean;
|
|
|
|
|
userId?: number;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (!result) return;
|
|
|
|
|
|
|
|
|
|
const newMission = await prisma.mission.update({
|
|
|
|
|
where: { id: Number(missionId) },
|
|
|
|
|
data: {
|
|
|
|
|
// save position of new mission
|
|
|
|
|
addressLat: result.state === "POSITION_AMANDED" ? result.lat : undefined,
|
|
|
|
|
addressLng: result.state === "POSITION_AMANDED" ? result.lng : undefined,
|
|
|
|
|
hpgLocationLat: result.lat,
|
|
|
|
|
hpgLocationLng: result.lng,
|
|
|
|
|
hpgValidationState: result.state,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
io.to("dispatchers").emit("update-mission", newMission);
|
|
|
|
|
|
|
|
|
|
const noActionRequired = result.state === "VALID";
|
|
|
|
|
if (noActionRequired) {
|
|
|
|
|
io.to(`user:${result.userId}`).emit("notification", {
|
|
|
|
|
type: "hpg-validation",
|
|
|
|
|
status: "success",
|
|
|
|
|
message: `HPG Validierung erfolgreich`,
|
|
|
|
|
} as NotificationPayload);
|
|
|
|
|
|
|
|
|
|
if (result.alertWhenValid) {
|
|
|
|
|
if (!req.user) return;
|
|
|
|
|
sendAlert(Number(missionId), {}, req.user);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
io.to(`user:${result.userId}`).emit("notification", {
|
|
|
|
|
type: "hpg-validation",
|
|
|
|
|
status: "failed",
|
|
|
|
|
message: result.state,
|
|
|
|
|
} as NotificationPayload);
|
|
|
|
|
}
|
|
|
|
|
res.json({
|
|
|
|
|
message: `HPG Validation result processed`,
|
|
|
|
|
});
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error("Error in HPG validation result:", error);
|
|
|
|
|
res.status(500).json({ error: "Failed to process HPG validation result" });
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
router.post("/:id/validate-hpg", async (req, res) => {
|
|
|
|
|
@@ -255,50 +321,14 @@ router.post("/:id/validate-hpg", async (req, res) => {
|
|
|
|
|
res.json({
|
|
|
|
|
message: "HPG validierung gestartet",
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
io.to(`desktop:${activeAircraftinMission}`).emit(
|
|
|
|
|
"hpg-validation",
|
|
|
|
|
{
|
|
|
|
|
hpgMissionType: mission?.hpgMissionString,
|
|
|
|
|
lat: mission?.addressLat,
|
|
|
|
|
lng: mission?.addressLng,
|
|
|
|
|
},
|
|
|
|
|
async (result: { state: HpgValidationState; lat: number; lng: number }) => {
|
|
|
|
|
console.log("response from user:", result);
|
|
|
|
|
|
|
|
|
|
const newMission = await prisma.mission.update({
|
|
|
|
|
where: { id: Number(id) },
|
|
|
|
|
data: {
|
|
|
|
|
// save position of new mission
|
|
|
|
|
addressLat: result.state === "POSITION_AMANDED" ? result.lat : mission.addressLat,
|
|
|
|
|
addressLng: result.state === "POSITION_AMANDED" ? result.lng : mission.addressLng,
|
|
|
|
|
hpgLocationLat: result.lat,
|
|
|
|
|
hpgLocationLng: result.lng,
|
|
|
|
|
hpgValidationState: result.state,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
io.to("dispatchers").emit("update-mission", newMission);
|
|
|
|
|
|
|
|
|
|
const noActionRequired = result.state === "VALID";
|
|
|
|
|
if (noActionRequired) {
|
|
|
|
|
io.to(`user:${req.user?.id}`).emit("notification", {
|
|
|
|
|
type: "hpg-validation",
|
|
|
|
|
status: "success",
|
|
|
|
|
message: `HPG Validierung erfolgreich`,
|
|
|
|
|
} as NotificationPayload);
|
|
|
|
|
if (config?.alertWhenValid) {
|
|
|
|
|
if (!req.user) return;
|
|
|
|
|
sendAlert(Number(id), {}, req.user);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
io.to(`user:${req.user?.id}`).emit("notification", {
|
|
|
|
|
type: "hpg-validation",
|
|
|
|
|
status: "failed",
|
|
|
|
|
message: `HPG Validation fehlgeschlagen`,
|
|
|
|
|
} as NotificationPayload);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
console.log(
|
|
|
|
|
`HPG Validation for ${user?.publicId} (${mission?.hpgSelectedMissionString}) started`,
|
|
|
|
|
);
|
|
|
|
|
io.to(`desktop:${activeAircraftinMission?.userId}`).emit("hpg-validation", {
|
|
|
|
|
missionId: parseInt(id),
|
|
|
|
|
userId: req.user?.id,
|
|
|
|
|
alertWhenValid: config?.alertWhenValid || false,
|
|
|
|
|
});
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error(error);
|
|
|
|
|
res.json({ error: (error as Error).message || "Failed to validate HPG" });
|
|
|
|
|
|