changes pilot socket to reperate pilto socket, added pilot stats

This commit is contained in:
PxlLoewe
2025-05-17 23:51:04 -07:00
parent 16e05a08a6
commit 6b58f564b2
16 changed files with 583 additions and 352 deletions

View File

@@ -14,6 +14,8 @@ export const handleConnectPilot =
const user = socket.data.user; // User ID aus dem JWT-Token
const userId = socket.data.user.id; // User ID aus dem JWT-Token
console.log("Pilot connected:", userId);
if (!user) return Error("User not found");
const existingConnection = await prisma.connectedAircraft.findFirst({
@@ -62,8 +64,6 @@ export const handleConnectPilot =
userId: userId,
loginTime: new Date().toISOString(),
stationId: parseInt(stationId),
/* user: { connect: { id: userId } }, // Ensure the user relationship is set
station: { connect: { id: stationId } }, // Ensure the station relationship is set */
},
});
@@ -71,6 +71,8 @@ export const handleConnectPilot =
socket.join(`user:${userId}`); // Join the user-specific room
socket.join(`station:${stationId}`); // Join the station-specific room
console.log(`Pilot in: station:${stationId}`);
io.to("dispatchers").emit("pilots-update");
io.to("pilots").emit("pilots-update");
@@ -83,14 +85,16 @@ export const handleConnectPilot =
socket.on("disconnect", async () => {
console.log("Disconnected from dispatch server");
await prisma.connectedAircraft.update({
where: {
id: connectedAircraftEntry.id,
},
data: {
logoutTime: new Date().toISOString(),
},
});
await prisma.connectedAircraft
.update({
where: {
id: connectedAircraftEntry.id,
},
data: {
logoutTime: new Date().toISOString(),
},
})
.catch(console.error);
io.to("dispatchers").emit("pilots-update");
io.to("pilots").emit("pilots-update");
});