added auto disconnect when changing link
This commit is contained in:
@@ -91,12 +91,14 @@ router.patch("/:id", async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
res.json(updatedConnectedAircraft);
|
||||
// When change is only the estimated logout time, we don't need to emit an event
|
||||
if (Object.keys(aircraftUpdate).length === 1 && aircraftUpdate.esimatedLogoutTime) return;
|
||||
io.to("dispatchers").emit("update-connectedAircraft", updatedConnectedAircraft);
|
||||
io.to(`user:${updatedConnectedAircraft.userId}`).emit(
|
||||
"aircraft-update",
|
||||
updatedConnectedAircraft,
|
||||
);
|
||||
res.json(updatedConnectedAircraft);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
res.status(500).json({ error: "Failed to update connectedAircraft" });
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { prisma } from "@repo/db";
|
||||
import { Prisma, prisma } from "@repo/db";
|
||||
import { Router } from "express";
|
||||
import { pubClient } from "modules/redis";
|
||||
|
||||
@@ -14,4 +14,18 @@ router.get("/", async (req, res) => {
|
||||
res.json(user);
|
||||
});
|
||||
|
||||
router.patch("/:id", async (req, res) => {
|
||||
const { id } = req.params;
|
||||
const disaptcherUpdate = req.body as Prisma.ConnectedDispatcherUpdateInput;
|
||||
|
||||
const newDispatcher = await prisma.connectedDispatcher.update({
|
||||
where: { id: Number(id) },
|
||||
data: {
|
||||
...disaptcherUpdate,
|
||||
},
|
||||
});
|
||||
|
||||
res.json(newDispatcher);
|
||||
});
|
||||
|
||||
export default router;
|
||||
|
||||
@@ -70,6 +70,7 @@ export const handleConnectDispatch =
|
||||
socket.join("dispatchers"); // Dem Dispatcher-Raum beitreten
|
||||
socket.join(`user:${user.id}`); // Dem User-Raum beitreten
|
||||
|
||||
io.to(`user:${user.id}`).emit("dispatchers-update", connectedDispatcherEntry);
|
||||
io.to("dispatchers").emit("dispatchers-update");
|
||||
io.to("pilots").emit("dispatchers-update");
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ export const handleConnectPilot =
|
||||
(socket: Socket, io: Server) =>
|
||||
async ({ logoffTime, stationId }: { logoffTime: string; stationId: string }) => {
|
||||
try {
|
||||
if (!stationId) return Error("Station ID is required");
|
||||
const user: User = socket.data.user; // User ID aus dem JWT-Token
|
||||
const userId = socket.data.user.id; // User ID aus dem JWT-Token
|
||||
|
||||
|
||||
Reference in New Issue
Block a user