Fixed Automatische alarmierung nach validierung #45
This commit is contained in:
@@ -9,7 +9,7 @@ export const sendAlert = async (
|
|||||||
}: {
|
}: {
|
||||||
stationId?: number;
|
stationId?: number;
|
||||||
},
|
},
|
||||||
user: User,
|
user: User | "HPG",
|
||||||
): Promise<{
|
): Promise<{
|
||||||
connectedAircrafts: ConnectedAircraft[];
|
connectedAircrafts: ConnectedAircraft[];
|
||||||
mission: Mission;
|
mission: Mission;
|
||||||
@@ -89,23 +89,38 @@ export const sendAlert = async (
|
|||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
// Ignore if the entry already exists
|
// Ignore if the entry already exists
|
||||||
});
|
});
|
||||||
|
if (user === "HPG") {
|
||||||
await prisma.mission.update({
|
await prisma.mission.update({
|
||||||
where: { id: Number(id) },
|
where: { id: Number(id) },
|
||||||
data: {
|
data: {
|
||||||
state: "running",
|
state: "running",
|
||||||
missionLog: {
|
missionLog: {
|
||||||
push: {
|
push: {
|
||||||
type: "alert-log",
|
type: "alert-log",
|
||||||
auto: false,
|
auto: true,
|
||||||
timeStamp: new Date().toISOString(),
|
timeStamp: new Date().toISOString(),
|
||||||
data: {
|
} as any,
|
||||||
stationId: stationId,
|
},
|
||||||
user: getPublicUser(user, { ignorePrivacy: true }),
|
|
||||||
},
|
|
||||||
} 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 };
|
return { connectedAircrafts, mission };
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -250,7 +250,6 @@ router.post("/:id/hpg-validation-result", async (req, res) => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
io.to("dispatchers").emit("update-mission", newMission);
|
io.to("dispatchers").emit("update-mission", newMission);
|
||||||
|
|
||||||
const noActionRequired = result.state === "VALID";
|
const noActionRequired = result.state === "VALID";
|
||||||
if (noActionRequired) {
|
if (noActionRequired) {
|
||||||
io.to(`user:${result.userId}`).emit("notification", {
|
io.to(`user:${result.userId}`).emit("notification", {
|
||||||
@@ -262,9 +261,10 @@ router.post("/:id/hpg-validation-result", async (req, res) => {
|
|||||||
},
|
},
|
||||||
} as NotificationPayload);
|
} as NotificationPayload);
|
||||||
|
|
||||||
|
console.log("Got positiv validation Result", result.alertWhenValid);
|
||||||
if (result.alertWhenValid) {
|
if (result.alertWhenValid) {
|
||||||
if (!req.user) return;
|
console.log(req.user);
|
||||||
sendAlert(Number(missionId), {}, req.user);
|
sendAlert(Number(missionId), {}, "HPG");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
io.to(`user:${result.userId}`).emit("notification", {
|
io.to(`user:${result.userId}`).emit("notification", {
|
||||||
|
|||||||
@@ -165,16 +165,6 @@ export const MissionForm = () => {
|
|||||||
...(mission as unknown as Prisma.MissionCreateInput),
|
...(mission as unknown as Prisma.MissionCreateInput),
|
||||||
hpgSelectedMissionString: szenarioCode,
|
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 {
|
} else {
|
||||||
newMission = await editMissionMutation.mutateAsync({
|
newMission = await editMissionMutation.mutateAsync({
|
||||||
id: Number(editingMissionId),
|
id: Number(editingMissionId),
|
||||||
@@ -189,14 +179,18 @@ export const MissionForm = () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (validationRequired) {
|
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}`);
|
toast.error(`Fehler beim Starten der HPG-Validierung: ${error.message}`);
|
||||||
});
|
});
|
||||||
|
} else if (alertWhenValid) {
|
||||||
|
await sendAlertMutation.mutateAsync(newMission.id);
|
||||||
}
|
}
|
||||||
return newMission;
|
return newMission;
|
||||||
};
|
};
|
||||||
console.log(form.watch("missionStationIds"));
|
|
||||||
return (
|
return (
|
||||||
<form className="space-y-4">
|
<form className="space-y-4">
|
||||||
{/* Koorinaten Section */}
|
{/* Koorinaten Section */}
|
||||||
@@ -421,97 +415,59 @@ export const MissionForm = () => {
|
|||||||
|
|
||||||
<div className="form-control min-h-[140px]">
|
<div className="form-control min-h-[140px]">
|
||||||
<div className="flex gap-2">
|
<div className="flex gap-2">
|
||||||
{editingMissionId ? (
|
<button
|
||||||
<button
|
type="submit"
|
||||||
type="button"
|
className="btn btn-warning"
|
||||||
className="btn btn-primary flex-1"
|
onClick={form.handleSubmit(async (mission: MissionOptionalDefaults) => {
|
||||||
onClick={form.handleSubmit(async (mission: MissionOptionalDefaults) => {
|
try {
|
||||||
try {
|
const newMission = await saveMission(mission, {
|
||||||
console.log("Saving mission", mission.addressOSMways);
|
createNewMission: !editingMissionId,
|
||||||
const newMission = await saveMission(mission);
|
alertWhenValid: true,
|
||||||
toast.success(`Einsatz ${newMission.publicId} aktualisiert`);
|
});
|
||||||
setSearchElements([]); // Reset search elements
|
|
||||||
setEditingMission(null); // Reset editing state
|
setSearchElements([]); // Reset search elements
|
||||||
form.reset(); // Reset the form
|
setEditingMission(null);
|
||||||
setOpen(false);
|
setContextMenu(null);
|
||||||
} catch (error) {
|
toast.success(`Einsatz ${newMission.publicId} erstellt`);
|
||||||
if (error instanceof AxiosError) {
|
form.reset();
|
||||||
toast.error(
|
setOpen(false);
|
||||||
`Fehler beim Bearbeiten des Einsatzes: ${error.response?.data.error}`,
|
} catch (error) {
|
||||||
);
|
if (error instanceof AxiosError) {
|
||||||
} else {
|
toast.error(`Fehler beim Erstellen des Einsatzes: ${error.response?.data.error}`);
|
||||||
toast.error(
|
} else {
|
||||||
`Fehler beim Bearbeiten des Einsatzes: ${(error as Error).message}`,
|
toast.error(`Fehler beim Erstellen des Einsatzes: ${(error as Error).message}`);
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})}
|
}
|
||||||
>
|
})}
|
||||||
Änderungen speichern
|
>
|
||||||
</button>
|
<BellRing className="h-4 w-4" /> Alarmieren
|
||||||
) : (
|
</button>
|
||||||
<>
|
<button
|
||||||
<button
|
type="submit"
|
||||||
type="submit"
|
className="btn btn-primary flex-1"
|
||||||
className="btn btn-warning"
|
onClick={form.handleSubmit(async (mission: MissionOptionalDefaults) => {
|
||||||
onClick={form.handleSubmit(async (mission: MissionOptionalDefaults) => {
|
try {
|
||||||
try {
|
const newMission = await saveMission(mission, {
|
||||||
const newMission = await saveMission(mission, {
|
createNewMission: !editingMissionId,
|
||||||
createNewMission: true,
|
});
|
||||||
alertWhenValid: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
setSearchElements([]); // Reset search elements
|
setSearchElements([]); // Reset search elements
|
||||||
setContextMenu(null);
|
setContextMenu(null);
|
||||||
toast.success(`Einsatz ${newMission.publicId} erstellt`);
|
toast.success(`Einsatz ${newMission.publicId} erstellt`);
|
||||||
form.reset();
|
form.reset();
|
||||||
setOpen(false);
|
setOpen(false);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error instanceof AxiosError) {
|
if (error instanceof AxiosError) {
|
||||||
toast.error(
|
toast.error(`Fehler beim Erstellen des Einsatzes: ${error.response?.data.error}`);
|
||||||
`Fehler beim Erstellen des Einsatzes: ${error.response?.data.error}`,
|
} else {
|
||||||
);
|
toast.error(`Fehler beim Erstellen des Einsatzes: ${(error as Error).message}`);
|
||||||
} else {
|
}
|
||||||
toast.error(
|
}
|
||||||
`Fehler beim Erstellen des Einsatzes: ${(error as Error).message}`,
|
})}
|
||||||
);
|
>
|
||||||
}
|
<BookmarkPlus className="h-5 w-5" />{" "}
|
||||||
}
|
{editingMissionId ? "Einsatz bearbeiten" : "Einsatz Vorbereiten"}
|
||||||
})}
|
</button>
|
||||||
>
|
|
||||||
<BellRing className="h-4 w-4" /> Alarmieren
|
|
||||||
</button>
|
|
||||||
<button
|
|
||||||
type="submit"
|
|
||||||
className="btn btn-primary flex-1"
|
|
||||||
onClick={form.handleSubmit(async (mission: MissionOptionalDefaults) => {
|
|
||||||
try {
|
|
||||||
const newMission = await saveMission(mission, {
|
|
||||||
createNewMission: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
setSearchElements([]); // Reset search elements
|
|
||||||
setContextMenu(null);
|
|
||||||
toast.success(`Einsatz ${newMission.publicId} erstellt`);
|
|
||||||
form.reset();
|
|
||||||
setOpen(false);
|
|
||||||
} catch (error) {
|
|
||||||
if (error instanceof AxiosError) {
|
|
||||||
toast.error(
|
|
||||||
`Fehler beim Erstellen des Einsatzes: ${error.response?.data.error}`,
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
toast.error(
|
|
||||||
`Fehler beim Erstellen des Einsatzes: ${(error as Error).message}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})}
|
|
||||||
>
|
|
||||||
<BookmarkPlus className="h-5 w-5" /> Einsatz vorbereiten
|
|
||||||
</button>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
@@ -741,7 +741,9 @@ const FMSStatusHistory = ({ mission }: { mission: Mission }) => {
|
|||||||
</li>
|
</li>
|
||||||
);
|
);
|
||||||
if (entry.type === "alert-log") {
|
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 (
|
return (
|
||||||
<li key={index} className="flex items-center gap-2">
|
<li key={index} className="flex items-center gap-2">
|
||||||
<span className="text-base-content">
|
<span className="text-base-content">
|
||||||
@@ -756,8 +758,13 @@ const FMSStatusHistory = ({ mission }: { mission: Mission }) => {
|
|||||||
color: FMS_STATUS_TEXT_COLORS[6],
|
color: FMS_STATUS_TEXT_COLORS[6],
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{entry.data.user.firstname?.[0]?.toUpperCase() ?? "?"}
|
{!entry.auto && (
|
||||||
{entry.data.user.lastname?.[0]?.toUpperCase() ?? "?"}
|
<>
|
||||||
|
{entry.data.user.firstname?.[0]?.toUpperCase() ?? "?"}
|
||||||
|
{entry.data.user.lastname?.[0]?.toUpperCase() ?? "?"}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
{entry.auto && "AUTO"}
|
||||||
{alertReceiver && (
|
{alertReceiver && (
|
||||||
<>
|
<>
|
||||||
<svg
|
<svg
|
||||||
|
|||||||
@@ -58,6 +58,11 @@ export interface MissionAlertLog {
|
|||||||
user: PublicUser;
|
user: PublicUser;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
export interface MissionAlertLogAuto {
|
||||||
|
type: "alert-log";
|
||||||
|
auto: true;
|
||||||
|
timeStamp: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface MissionCompletedLog {
|
export interface MissionCompletedLog {
|
||||||
type: "completed-log";
|
type: "completed-log";
|
||||||
@@ -73,5 +78,6 @@ export type MissionLog =
|
|||||||
| MissionMessageLog
|
| MissionMessageLog
|
||||||
| MissionSdsLog
|
| MissionSdsLog
|
||||||
| MissionAlertLog
|
| MissionAlertLog
|
||||||
|
| MissionAlertLogAuto
|
||||||
| MissionCompletedLog
|
| MissionCompletedLog
|
||||||
| MissionVehicleLog;
|
| MissionVehicleLog;
|
||||||
|
|||||||
Reference in New Issue
Block a user