Fixed Automatische alarmierung nach validierung #45
This commit is contained in:
@@ -9,7 +9,7 @@ export const sendAlert = async (
|
||||
}: {
|
||||
stationId?: number;
|
||||
},
|
||||
user: User,
|
||||
user: User | "HPG",
|
||||
): Promise<{
|
||||
connectedAircrafts: ConnectedAircraft[];
|
||||
mission: Mission;
|
||||
@@ -89,23 +89,38 @@ export const sendAlert = async (
|
||||
.catch((err) => {
|
||||
// Ignore if the entry already exists
|
||||
});
|
||||
|
||||
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,
|
||||
if (user === "HPG") {
|
||||
await prisma.mission.update({
|
||||
where: { id: Number(id) },
|
||||
data: {
|
||||
state: "running",
|
||||
missionLog: {
|
||||
push: {
|
||||
type: "alert-log",
|
||||
auto: true,
|
||||
timeStamp: new Date().toISOString(),
|
||||
} 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 };
|
||||
};
|
||||
|
||||
@@ -250,7 +250,6 @@ router.post("/:id/hpg-validation-result", async (req, res) => {
|
||||
},
|
||||
});
|
||||
io.to("dispatchers").emit("update-mission", newMission);
|
||||
|
||||
const noActionRequired = result.state === "VALID";
|
||||
if (noActionRequired) {
|
||||
io.to(`user:${result.userId}`).emit("notification", {
|
||||
@@ -262,9 +261,10 @@ router.post("/:id/hpg-validation-result", async (req, res) => {
|
||||
},
|
||||
} as NotificationPayload);
|
||||
|
||||
console.log("Got positiv validation Result", result.alertWhenValid);
|
||||
if (result.alertWhenValid) {
|
||||
if (!req.user) return;
|
||||
sendAlert(Number(missionId), {}, req.user);
|
||||
console.log(req.user);
|
||||
sendAlert(Number(missionId), {}, "HPG");
|
||||
}
|
||||
} else {
|
||||
io.to(`user:${result.userId}`).emit("notification", {
|
||||
|
||||
Reference in New Issue
Block a user