getNextHourTime zu shared library hinzugefügt
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
"devDependencies": {
|
||||
"@repo/db": "workspace:*",
|
||||
"@repo/typescript-config": "workspace:*",
|
||||
"@repo/shared-components": "workspace:*",
|
||||
"@types/cookie-parser": "^1.4.8",
|
||||
"@types/cors": "^2.8.18",
|
||||
"@types/express": "^5.0.2",
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { getPublicUser, prisma, User } from "@repo/db";
|
||||
import { addRolesToMember, removeRolesFromMember, renameMember } from "modules/discord";
|
||||
import { getNextDateWithTime } from "@repo/shared-components";
|
||||
import { DISCORD_ROLES } from "@repo/db";
|
||||
import { Server, Socket } from "socket.io";
|
||||
|
||||
@@ -45,30 +46,13 @@ export const handleConnectDispatch =
|
||||
}
|
||||
|
||||
let parsedLogoffDate = null;
|
||||
if (logoffTime.length > 0) {
|
||||
const now = new Date();
|
||||
const [hours, minutes] = logoffTime.split(":").map(Number);
|
||||
if (!hours || !minutes) {
|
||||
throw new Error("Invalid logoffTime format");
|
||||
}
|
||||
parsedLogoffDate = new Date(now);
|
||||
parsedLogoffDate.setHours(hours, minutes, 0, 0);
|
||||
|
||||
// If the calculated time is earlier than now, add one day to make it tomorrow
|
||||
if (parsedLogoffDate <= now) {
|
||||
parsedLogoffDate.setDate(parsedLogoffDate.getDate() + 1);
|
||||
}
|
||||
|
||||
// If the calculated time is in the past, add one day to make it in the future
|
||||
if (parsedLogoffDate <= now) {
|
||||
parsedLogoffDate.setDate(parsedLogoffDate.getDate() + 1);
|
||||
}
|
||||
}
|
||||
const [logoffHours, logoffMinutes] = logoffTime.split(":").map(Number);
|
||||
|
||||
const connectedDispatcherEntry = await prisma.connectedDispatcher.create({
|
||||
data: {
|
||||
publicUser: getPublicUser(user) as any,
|
||||
esimatedLogoutTime: parsedLogoffDate?.toISOString() || null,
|
||||
esimatedLogoutTime:
|
||||
logoffHours && logoffMinutes ? getNextDateWithTime(logoffHours, logoffMinutes) : null,
|
||||
lastHeartbeat: new Date().toISOString(),
|
||||
userId: user.id,
|
||||
zone: selectedZone,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { getPublicUser, prisma, User } from "@repo/db";
|
||||
import { addRolesToMember, removeRolesFromMember, renameMember } from "modules/discord";
|
||||
import { getNextDateWithTime } from "@repo/shared-components";
|
||||
import { DISCORD_ROLES } from "@repo/db";
|
||||
import { Server, Socket } from "socket.io";
|
||||
|
||||
@@ -55,22 +56,6 @@ export const handleConnectPilot =
|
||||
});
|
||||
}
|
||||
|
||||
let parsedLogoffDate = null;
|
||||
if (logoffTime.length > 0) {
|
||||
const now = new Date();
|
||||
const [hours, minutes] = logoffTime.split(":").map(Number);
|
||||
if (!hours || !minutes) {
|
||||
throw new Error("Invalid logoffTime format");
|
||||
}
|
||||
parsedLogoffDate = new Date(now);
|
||||
parsedLogoffDate.setHours(hours, minutes, 0, 0);
|
||||
|
||||
// If the calculated time is earlier than now, add one day to make it tomorrow
|
||||
if (parsedLogoffDate <= now) {
|
||||
parsedLogoffDate.setDate(parsedLogoffDate.getDate() + 1);
|
||||
}
|
||||
}
|
||||
|
||||
// Set "now" to 2 hours in the future
|
||||
const nowPlus2h = new Date();
|
||||
nowPlus2h.setHours(nowPlus2h.getHours() + 2);
|
||||
@@ -87,11 +72,13 @@ export const handleConnectPilot =
|
||||
}
|
||||
|
||||
const randomPos = debug ? getRandomGermanPosition() : undefined;
|
||||
const [logoffHours, logoffMinutes] = logoffTime.split(":").map(Number);
|
||||
|
||||
const connectedAircraftEntry = await prisma.connectedAircraft.create({
|
||||
data: {
|
||||
publicUser: getPublicUser(user) as any,
|
||||
esimatedLogoutTime: parsedLogoffDate?.toISOString() || null,
|
||||
esimatedLogoutTime:
|
||||
logoffHours && logoffMinutes ? getNextDateWithTime(logoffHours, logoffMinutes) : null,
|
||||
userId: userId,
|
||||
stationId: parseInt(stationId),
|
||||
lastHeartbeat: debug ? nowPlus2h.toISOString() : undefined,
|
||||
|
||||
@@ -2,9 +2,10 @@
|
||||
"extends": "@repo/typescript-config/base.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "dist",
|
||||
"allowImportingTsExtensions": false,
|
||||
"baseUrl": ".",
|
||||
"jsx": "react"
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "bundler",
|
||||
"noEmit": true,
|
||||
"baseUrl": "."
|
||||
},
|
||||
"include": ["**/*.ts", "./index.ts", "**/*.d.ts"],
|
||||
"exclude": ["node_modules", "dist"]
|
||||
|
||||
Reference in New Issue
Block a user