addd HPG state
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { prisma } from "@repo/db";
|
||||
import { HpgValidationState, Prisma, prisma } from "@repo/db";
|
||||
import { Router } from "express";
|
||||
import { io } from "../index";
|
||||
import { sendNtfyMission } from "modules/ntfy";
|
||||
@@ -203,4 +203,75 @@ router.post("/:id/send-alert", async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
router.post("/:id/validate-hpg", async (req, res) => {
|
||||
try {
|
||||
const { id } = req.params;
|
||||
const mission = await prisma.mission.findFirstOrThrow({
|
||||
where: {
|
||||
id: Number(id),
|
||||
},
|
||||
});
|
||||
|
||||
const activeAircraftinMission = await prisma.connectedAircraft.findFirst({
|
||||
where: {
|
||||
stationId: {
|
||||
in: mission?.missionStationIds,
|
||||
},
|
||||
posH145active: true,
|
||||
logoutTime: null,
|
||||
},
|
||||
include: {
|
||||
Station: true,
|
||||
},
|
||||
});
|
||||
|
||||
/* if (activeAircraftinMission.length === 0) {
|
||||
res.status(400).json({ error: "No active aircraft in mission" });
|
||||
return;
|
||||
} */
|
||||
|
||||
res.json({
|
||||
message: "HPG validation started",
|
||||
});
|
||||
|
||||
io.to(`desktop:${activeAircraftinMission}`).emit(
|
||||
"hpg-validation",
|
||||
{
|
||||
hpgMissionType: mission?.hpgMissionString,
|
||||
lat: mission?.addressLat,
|
||||
lng: mission?.addressLng,
|
||||
},
|
||||
async (result: {
|
||||
state: HpgValidationState;
|
||||
lat: number;
|
||||
lng: number;
|
||||
}) => {
|
||||
console.log("response from user:", result);
|
||||
|
||||
const newMission = await prisma.mission.update({
|
||||
where: { id: Number(id) },
|
||||
data: {
|
||||
// save position of new mission
|
||||
addressLat:
|
||||
result.state === "POSITION_AMANDED"
|
||||
? result.lat
|
||||
: mission.addressLat,
|
||||
addressLng:
|
||||
result.state === "POSITION_AMANDED"
|
||||
? result.lng
|
||||
: mission.addressLng,
|
||||
hpgLocationLat: result.lat,
|
||||
hpgLocationLng: result.lng,
|
||||
hpgValidationState: result.state,
|
||||
},
|
||||
});
|
||||
io.to("dispatchers").emit("update-mission", newMission);
|
||||
},
|
||||
);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
res.json({ error: (error as Error).message || "Failed to validate HPG" });
|
||||
}
|
||||
});
|
||||
|
||||
export default router;
|
||||
|
||||
Reference in New Issue
Block a user