fixed #105
This commit is contained in:
@@ -14,6 +14,7 @@ export const sendAlert = async (
|
|||||||
connectedAircrafts: ConnectedAircraft[];
|
connectedAircrafts: ConnectedAircraft[];
|
||||||
mission: Mission;
|
mission: Mission;
|
||||||
}> => {
|
}> => {
|
||||||
|
try {
|
||||||
const mission = await prisma.mission.findUnique({
|
const mission = await prisma.mission.findUnique({
|
||||||
where: { id: id },
|
where: { id: id },
|
||||||
});
|
});
|
||||||
@@ -123,4 +124,8 @@ export const sendAlert = async (
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
return { connectedAircrafts, mission };
|
return { connectedAircrafts, mission };
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error sending mission alert:", error);
|
||||||
|
throw new Error("Ein Fehler ist aufgetreten. Bitte melde den Fehler als Bug");
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -50,10 +50,7 @@ const getRthCallsigns = (mission: Mission, stations: Station[]) => {
|
|||||||
return `🚁 RTH${callsigns.length > 1 ? "s" : ""}: ${callsigns.join(" / ")} `;
|
return `🚁 RTH${callsigns.length > 1 ? "s" : ""}: ${callsigns.join(" / ")} `;
|
||||||
};
|
};
|
||||||
|
|
||||||
const getNtfyHeader = (
|
const getNtfyHeader = (mission: Mission, clientStation: Station): NtfyHeader => ({
|
||||||
mission: Mission,
|
|
||||||
clientStation: Station,
|
|
||||||
): NtfyHeader => ({
|
|
||||||
headers: {
|
headers: {
|
||||||
Title: `${clientStation.bosCallsignShort} / ${mission.missionKeywordAbbreviation} / ${mission.missionKeywordCategory}`,
|
Title: `${clientStation.bosCallsignShort} / ${mission.missionKeywordAbbreviation} / ${mission.missionKeywordCategory}`,
|
||||||
Tags: "pager",
|
Tags: "pager",
|
||||||
@@ -76,9 +73,13 @@ export const sendNtfyMission = async (
|
|||||||
clientStation: Station,
|
clientStation: Station,
|
||||||
ntfyRoom: string,
|
ntfyRoom: string,
|
||||||
) => {
|
) => {
|
||||||
axios.post(
|
try {
|
||||||
|
await axios.post(
|
||||||
`https://ntfy.sh/${ntfyRoom}`,
|
`https://ntfy.sh/${ntfyRoom}`,
|
||||||
getNtfyData(mission, stations),
|
getNtfyData(mission, stations),
|
||||||
getNtfyHeader(mission, clientStation),
|
getNtfyHeader(mission, clientStation),
|
||||||
);
|
);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error sending Ntfy mission:", error);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -189,7 +189,11 @@ router.post("/:id/send-alert", async (req, res) => {
|
|||||||
return;
|
return;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
res.status(500).json({ error: "Failed to send mission" });
|
res
|
||||||
|
.status(500)
|
||||||
|
.json({
|
||||||
|
error: `Ein Fehler ist aufgetreten. Bitte melde den Fehler als Bug (${(error as Error).message})`,
|
||||||
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user