fix cron, add pilot time server update
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import { MissionLog, prisma } from "@repo/db";
|
import { MissionLog, prisma } from "@repo/db";
|
||||||
import chron from "cron";
|
import cron from "node-cron";
|
||||||
|
|
||||||
const removeClosedMissions = async () => {
|
const removeClosedMissions = async () => {
|
||||||
const oldMissions = await prisma.mission.findMany({
|
const oldMissions = await prisma.mission.findMany({
|
||||||
@@ -40,12 +40,10 @@ const removeClosedMissions = async () => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const removeClosedMissionsJob = new chron.CronJob(
|
cron.schedule("*/5 * * * *", async () => {
|
||||||
"*/5 * * * *", // Every 5 minutes
|
try {
|
||||||
removeClosedMissions,
|
await removeClosedMissions();
|
||||||
null,
|
} catch (error) {
|
||||||
true,
|
console.error("Error removing closed missions:", error);
|
||||||
"Europe/Berlin",
|
}
|
||||||
);
|
});
|
||||||
|
|
||||||
removeClosedMissionsJob.start();
|
|
||||||
|
|||||||
@@ -32,6 +32,7 @@
|
|||||||
"express": "^5.1.0",
|
"express": "^5.1.0",
|
||||||
"jsonwebtoken": "^9.0.2",
|
"jsonwebtoken": "^9.0.2",
|
||||||
"livekit-server-sdk": "^2.13.0",
|
"livekit-server-sdk": "^2.13.0",
|
||||||
|
"node-cron": "^4.1.0",
|
||||||
"nodemailer": "^7.0.3",
|
"nodemailer": "^7.0.3",
|
||||||
"nodemon": "^3.1.10",
|
"nodemon": "^3.1.10",
|
||||||
"react": "^19.1.0",
|
"react": "^19.1.0",
|
||||||
|
|||||||
@@ -68,7 +68,6 @@ export const handleConnectPilot =
|
|||||||
posH145active: true,
|
posH145active: true,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.join("dispatchers"); // Join the dispatchers room
|
socket.join("dispatchers"); // Join the dispatchers room
|
||||||
socket.join(`user:${userId}`); // Join the user-specific room
|
socket.join(`user:${userId}`); // Join the user-specific room
|
||||||
socket.join(`station:${stationId}`); // Join the station-specific room
|
socket.join(`station:${stationId}`); // Join the station-specific room
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import {
|
|||||||
MissionSdsLog,
|
MissionSdsLog,
|
||||||
MissionStationLog,
|
MissionStationLog,
|
||||||
Prisma,
|
Prisma,
|
||||||
|
PublicUser,
|
||||||
Station,
|
Station,
|
||||||
} from "@repo/db";
|
} from "@repo/db";
|
||||||
import { toast } from "react-hot-toast";
|
import { toast } from "react-hot-toast";
|
||||||
@@ -46,20 +47,32 @@ const FMSStatusHistory = ({
|
|||||||
aircraft: ConnectedAircraft & { Station: Station };
|
aircraft: ConnectedAircraft & { Station: Station };
|
||||||
mission?: Mission;
|
mission?: Mission;
|
||||||
}) => {
|
}) => {
|
||||||
console.log("FMSStatusHistory", mission?.missionLog);
|
|
||||||
const log = ((mission?.missionLog as unknown as MissionLog[]) || [])
|
const log = ((mission?.missionLog as unknown as MissionLog[]) || [])
|
||||||
.filter((entry) => entry.type === "station-log" && entry.data.stationId === aircraft.Station.id)
|
.filter((entry) => entry.type === "station-log" && entry.data.stationId === aircraft.Station.id)
|
||||||
.reverse()
|
.reverse()
|
||||||
.splice(0, 6) as MissionStationLog[];
|
.splice(0, 6) as MissionStationLog[];
|
||||||
|
|
||||||
const aircraftUser =
|
const aircraftUser: PublicUser =
|
||||||
typeof aircraft.publicUser === "string" ? JSON.parse(aircraft.publicUser) : aircraft.publicUser;
|
typeof aircraft.publicUser === "string" ? JSON.parse(aircraft.publicUser) : aircraft.publicUser;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="p-4">
|
<div className="p-4">
|
||||||
<ul className="text-base-content font-semibold">
|
<ul className="text-base-content font-semibold">
|
||||||
<li className="flex items-center gap-2 mb-1">
|
<li className="flex items-center gap-2 mb-1">
|
||||||
<PersonIcon className="w-5 h-5" /> {aircraftUser.fullName} ({aircraftUser.publicId})
|
<p className="flex items-center gap-2 flex-1">
|
||||||
|
<PersonIcon className="w-5 h-5" /> {aircraftUser.fullName} ({aircraftUser.publicId})
|
||||||
|
</p>
|
||||||
|
<p className="text-sm font-thin text-gray-500">
|
||||||
|
{aircraft.esimatedLogoutTime
|
||||||
|
? `Geplante Abmeldung: ${new Date(aircraft.esimatedLogoutTime).toLocaleTimeString(
|
||||||
|
[],
|
||||||
|
{
|
||||||
|
hour: "2-digit",
|
||||||
|
minute: "2-digit",
|
||||||
|
},
|
||||||
|
)}`
|
||||||
|
: "Keine geplante Abmeldung"}
|
||||||
|
</p>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<div className="divider mt-0 mb-0" />
|
<div className="divider mt-0 mb-0" />
|
||||||
|
|||||||
@@ -2,9 +2,11 @@
|
|||||||
import { useSession } from "next-auth/react";
|
import { useSession } from "next-auth/react";
|
||||||
import { usePilotConnectionStore } from "_store/pilot/connectionStore";
|
import { usePilotConnectionStore } from "_store/pilot/connectionStore";
|
||||||
import { useEffect, useRef, useState } from "react";
|
import { useEffect, useRef, useState } from "react";
|
||||||
import { useQuery } from "@tanstack/react-query";
|
import { useMutation, useQuery } from "@tanstack/react-query";
|
||||||
import { getStationsAPI } from "_querys/stations";
|
import { getStationsAPI } from "_querys/stations";
|
||||||
import toast from "react-hot-toast";
|
import toast from "react-hot-toast";
|
||||||
|
import { editConnectedAircraftAPI } from "_querys/aircrafts";
|
||||||
|
import { Prisma } from "@repo/db";
|
||||||
|
|
||||||
export const ConnectionBtn = () => {
|
export const ConnectionBtn = () => {
|
||||||
const modalRef = useRef<HTMLDialogElement>(null);
|
const modalRef = useRef<HTMLDialogElement>(null);
|
||||||
@@ -22,6 +24,15 @@ export const ConnectionBtn = () => {
|
|||||||
queryKey: ["stations"],
|
queryKey: ["stations"],
|
||||||
queryFn: () => getStationsAPI(),
|
queryFn: () => getStationsAPI(),
|
||||||
});
|
});
|
||||||
|
const aircraftMutation = useMutation({
|
||||||
|
mutationFn: ({
|
||||||
|
change,
|
||||||
|
sessionId,
|
||||||
|
}: {
|
||||||
|
sessionId: number;
|
||||||
|
change: Prisma.ConnectedAircraftUpdateInput;
|
||||||
|
}) => editConnectedAircraftAPI(sessionId, change),
|
||||||
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (stations && stations.length > 0 && form.selectedStationId === null) {
|
if (stations && stations.length > 0 && form.selectedStationId === null) {
|
||||||
@@ -100,7 +111,7 @@ export const ConnectionBtn = () => {
|
|||||||
)}
|
)}
|
||||||
<fieldset className="fieldset w-full mt-2">
|
<fieldset className="fieldset w-full mt-2">
|
||||||
<label className="floating-label w-full text-base">
|
<label className="floating-label w-full text-base">
|
||||||
<span>Logoff Zeit (UTC+1)</span>
|
<span>Logoff Zeit (LCL)</span>
|
||||||
<input
|
<input
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
const value = e.target.value;
|
const value = e.target.value;
|
||||||
@@ -109,7 +120,16 @@ export const ConnectionBtn = () => {
|
|||||||
logoffTime: value,
|
logoffTime: value,
|
||||||
});
|
});
|
||||||
if (logoffDebounce) clearTimeout(logoffDebounce);
|
if (logoffDebounce) clearTimeout(logoffDebounce);
|
||||||
const timeout = setTimeout(() => {
|
const timeout = setTimeout(async () => {
|
||||||
|
if (!connection.connectedAircraft) return;
|
||||||
|
await aircraftMutation.mutateAsync({
|
||||||
|
sessionId: connection.connectedAircraft.id,
|
||||||
|
change: {
|
||||||
|
esimatedLogoutTime: value
|
||||||
|
? new Date(new Date().toDateString() + " " + value).toISOString()
|
||||||
|
: null,
|
||||||
|
},
|
||||||
|
});
|
||||||
toast.success("Änderung gespeichert!");
|
toast.success("Änderung gespeichert!");
|
||||||
}, 2000);
|
}, 2000);
|
||||||
setLogoffDebounce(timeout);
|
setLogoffDebounce(timeout);
|
||||||
|
|||||||
9
pnpm-lock.yaml
generated
9
pnpm-lock.yaml
generated
@@ -189,6 +189,9 @@ importers:
|
|||||||
livekit-server-sdk:
|
livekit-server-sdk:
|
||||||
specifier: ^2.13.0
|
specifier: ^2.13.0
|
||||||
version: 2.13.0
|
version: 2.13.0
|
||||||
|
node-cron:
|
||||||
|
specifier: ^4.1.0
|
||||||
|
version: 4.1.0
|
||||||
nodemailer:
|
nodemailer:
|
||||||
specifier: ^7.0.3
|
specifier: ^7.0.3
|
||||||
version: 7.0.3
|
version: 7.0.3
|
||||||
@@ -3500,6 +3503,10 @@ packages:
|
|||||||
sass:
|
sass:
|
||||||
optional: true
|
optional: true
|
||||||
|
|
||||||
|
node-cron@4.1.0:
|
||||||
|
resolution: {integrity: sha512-OS+3ORu+h03/haS6Di8Qr7CrVs4YaKZZOynZwQpyPZDnR3tqRbwJmuP2gVR16JfhLgyNlloAV1VTrrWlRogCFA==}
|
||||||
|
engines: {node: '>=6.0.0'}
|
||||||
|
|
||||||
node-releases@2.0.19:
|
node-releases@2.0.19:
|
||||||
resolution: {integrity: sha512-xxOWJsBKtzAq7DY0J+DTzuz58K8e7sJbdgwkbMWQe8UYB6ekmsQ45q0M/tJDsGaZmbC+l7n57UV8Hl5tHxO9uw==}
|
resolution: {integrity: sha512-xxOWJsBKtzAq7DY0J+DTzuz58K8e7sJbdgwkbMWQe8UYB6ekmsQ45q0M/tJDsGaZmbC+l7n57UV8Hl5tHxO9uw==}
|
||||||
|
|
||||||
@@ -8085,6 +8092,8 @@ snapshots:
|
|||||||
- '@babel/core'
|
- '@babel/core'
|
||||||
- babel-plugin-macros
|
- babel-plugin-macros
|
||||||
|
|
||||||
|
node-cron@4.1.0: {}
|
||||||
|
|
||||||
node-releases@2.0.19: {}
|
node-releases@2.0.19: {}
|
||||||
|
|
||||||
nodemailer@6.10.1:
|
nodemailer@6.10.1:
|
||||||
|
|||||||
Reference in New Issue
Block a user