closes #136
This commit is contained in:
@@ -6,8 +6,10 @@ export const sendAlert = async (
|
||||
id: number,
|
||||
{
|
||||
stationId,
|
||||
desktopOnly,
|
||||
}: {
|
||||
stationId?: number;
|
||||
desktopOnly?: boolean;
|
||||
},
|
||||
user: User | "HPG",
|
||||
): Promise<{
|
||||
@@ -46,10 +48,13 @@ export const sendAlert = async (
|
||||
});
|
||||
|
||||
for (const aircraft of connectedAircrafts) {
|
||||
io.to(`station:${aircraft.stationId}`).emit("mission-alert", {
|
||||
...mission,
|
||||
Stations,
|
||||
});
|
||||
if (!desktopOnly) {
|
||||
io.to(`station:${aircraft.stationId}`).emit("mission-alert", {
|
||||
...mission,
|
||||
Stations,
|
||||
});
|
||||
}
|
||||
|
||||
io.to(`desktop:${aircraft.userId}`).emit("mission-alert", {
|
||||
missionId: mission.id,
|
||||
});
|
||||
|
||||
@@ -113,9 +113,10 @@ router.delete("/:id", async (req, res) => {
|
||||
|
||||
router.post("/:id/send-alert", async (req, res) => {
|
||||
const { id } = req.params;
|
||||
const { stationId, vehicleName } = req.body as {
|
||||
const { stationId, vehicleName, desktopOnly } = req.body as {
|
||||
stationId?: number;
|
||||
vehicleName?: "RTW" | "POL" | "FW";
|
||||
desktopOnly?: boolean;
|
||||
};
|
||||
|
||||
if (!req.user) {
|
||||
@@ -180,7 +181,11 @@ router.post("/:id/send-alert", async (req, res) => {
|
||||
return;
|
||||
}
|
||||
|
||||
const { connectedAircrafts, mission } = await sendAlert(Number(id), { stationId }, req.user);
|
||||
const { connectedAircrafts, mission } = await sendAlert(
|
||||
Number(id),
|
||||
{ stationId, desktopOnly },
|
||||
req.user,
|
||||
);
|
||||
|
||||
io.to("dispatchers").emit("update-mission", mission);
|
||||
res.status(200).json({
|
||||
@@ -189,11 +194,9 @@ router.post("/:id/send-alert", async (req, res) => {
|
||||
return;
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
res
|
||||
.status(500)
|
||||
.json({
|
||||
error: `Ein Fehler ist aufgetreten. Bitte melde den Fehler als Bug (${(error as Error).message})`,
|
||||
});
|
||||
res.status(500).json({
|
||||
error: `Ein Fehler ist aufgetreten. Bitte melde den Fehler als Bug (${(error as Error).message})`,
|
||||
});
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user