added logbook
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import {
|
||||
getPublicUser,
|
||||
HpgValidationState,
|
||||
MissionAlertLog,
|
||||
MissionSdsLog,
|
||||
MissionStationLog,
|
||||
NotificationPayload,
|
||||
@@ -119,6 +121,11 @@ router.post("/:id/send-alert", async (req, res) => {
|
||||
vehicleName?: "ambulance" | "police" | "firebrigade";
|
||||
};
|
||||
|
||||
if (!req.user) {
|
||||
res.status(401).json({ error: "Unauthorized" });
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
if (vehicleName) {
|
||||
const hpgAircrafts = await prisma.connectedAircraft.findMany({
|
||||
@@ -137,6 +144,17 @@ router.post("/:id/send-alert", async (req, res) => {
|
||||
hpgAmbulanceState: vehicleName === "ambulance" ? "DISPATCHED" : undefined,
|
||||
hpgFireEngineState: vehicleName === "firebrigade" ? "DISPATCHED" : undefined,
|
||||
hpgPoliceState: vehicleName === "police" ? "DISPATCHED" : undefined,
|
||||
missionLog: {
|
||||
push: {
|
||||
type: "alert-log",
|
||||
auto: false,
|
||||
timeStamp: new Date().toISOString(),
|
||||
data: {
|
||||
vehicle: vehicleName,
|
||||
user: getPublicUser(req.user as User),
|
||||
},
|
||||
} as any,
|
||||
},
|
||||
},
|
||||
});
|
||||
hpgAircrafts.forEach((aircraft) => {
|
||||
@@ -156,9 +174,13 @@ router.post("/:id/send-alert", async (req, res) => {
|
||||
io.to("dispatchers").emit("update-mission", newMission);
|
||||
return;
|
||||
}
|
||||
const { connectedAircrafts, mission } = await sendAlert(Number(id), {
|
||||
stationId,
|
||||
});
|
||||
const { connectedAircrafts, mission } = await sendAlert(
|
||||
Number(id),
|
||||
{
|
||||
stationId,
|
||||
},
|
||||
req.user,
|
||||
);
|
||||
|
||||
res.status(200).json({
|
||||
message: `Einsatz gesendet (${connectedAircrafts.length} Nutzer) `,
|
||||
@@ -231,7 +253,7 @@ router.post("/:id/validate-hpg", async (req, res) => {
|
||||
return;
|
||||
}
|
||||
res.json({
|
||||
message: "HPG validation started",
|
||||
message: "HPG validierung gestartet",
|
||||
});
|
||||
|
||||
io.to(`desktop:${activeAircraftinMission}`).emit(
|
||||
@@ -265,7 +287,8 @@ router.post("/:id/validate-hpg", async (req, res) => {
|
||||
message: `HPG Validierung erfolgreich`,
|
||||
} as NotificationPayload);
|
||||
if (config?.alertWhenValid) {
|
||||
sendAlert(Number(id), {});
|
||||
if (!req.user) return;
|
||||
sendAlert(Number(id), {}, req.user);
|
||||
}
|
||||
} else {
|
||||
io.to(`user:${req.user?.id}`).emit("notification", {
|
||||
@@ -276,25 +299,6 @@ router.post("/:id/validate-hpg", async (req, res) => {
|
||||
}
|
||||
},
|
||||
);
|
||||
// TODO: remove this after testing
|
||||
setTimeout(() => {
|
||||
io.to(`user:${req.user?.id}`).emit("notification", {
|
||||
type: "hpg-validation",
|
||||
status: "success",
|
||||
message: "HPG_BUSY",
|
||||
data: {
|
||||
mission,
|
||||
},
|
||||
} as NotificationPayload);
|
||||
io.to(`user:${req.user?.id}`).emit("notification", {
|
||||
type: "hpg-validation",
|
||||
status: "failed",
|
||||
message: `HPG Validation fehlgeschlagen`,
|
||||
data: {
|
||||
mission,
|
||||
},
|
||||
} as NotificationPayload);
|
||||
}, 5000);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
res.json({ error: (error as Error).message || "Failed to validate HPG" });
|
||||
|
||||
Reference in New Issue
Block a user