This commit is contained in:
PxlLoewe
2025-07-06 00:36:48 -07:00
parent 2cdbab9f28
commit a9d20e018d
13 changed files with 72 additions and 19 deletions

View File

@@ -282,8 +282,20 @@ router.post("/:id/hpg-validation-result", async (req, res) => {
router.post("/:id/validate-hpg", async (req, res) => { router.post("/:id/validate-hpg", async (req, res) => {
try { try {
const config = await prisma.config.findFirst({
orderBy: {
createdAt: "desc",
},
});
if (config?.disableHPG) {
res.status(400).json({
error: "HPG is disabled",
});
return;
}
const { id } = req.params; const { id } = req.params;
const config = req.body as const body = req.body as
| { | {
alertWhenValid?: boolean; alertWhenValid?: boolean;
} }
@@ -336,7 +348,7 @@ router.post("/:id/validate-hpg", async (req, res) => {
io.to(`desktop:${activeAircraftinMission?.userId}`).emit("hpg-validation", { io.to(`desktop:${activeAircraftinMission?.userId}`).emit("hpg-validation", {
missionId: parseInt(id), missionId: parseInt(id),
userId: req.user?.id, userId: req.user?.id,
alertWhenValid: config?.alertWhenValid || false, alertWhenValid: body?.alertWhenValid || false,
}); });
} catch (error) { } catch (error) {
console.error(error); console.error(error);

View File

@@ -438,10 +438,12 @@ export const MissionForm = () => {
} catch (error) { } catch (error) {
if (error instanceof AxiosError) { if (error instanceof AxiosError) {
toast.error( toast.error(
`Fehler beim Erstellen des Einsatzes: ${error.response?.data.error}`, `Fehler beim Bearbeiten des Einsatzes: ${error.response?.data.error}`,
); );
} else { } else {
toast.error(`Fehler beim Erstellen des Einsatzes: ${(error as Error).message}`); toast.error(
`Fehler beim Bearbeiten des Einsatzes: ${(error as Error).message}`,
);
} }
} }
})} })}

View File

@@ -2,7 +2,7 @@ import { prisma } from "@repo/db";
import { MessageCircleWarning } from "lucide-react"; import { MessageCircleWarning } from "lucide-react";
export const WarningAlert = async () => { export const WarningAlert = async () => {
const config = await prisma.notam.findFirst({ const config = await prisma.config.findFirst({
orderBy: [{ createdAt: "desc" }], orderBy: [{ createdAt: "desc" }],
}); });

View File

@@ -30,7 +30,7 @@ export default async function RootLayout({
}>) { }>) {
const session = await getServerSession(); const session = await getServerSession();
const config = await prisma.notam.findFirst({ const config = await prisma.config.findFirst({
orderBy: [{ createdAt: "desc" }], orderBy: [{ createdAt: "desc" }],
}); });

View File

@@ -1,8 +1,7 @@
"use client"; "use client";
import { zodResolver } from "@hookform/resolvers/zod"; import { zodResolver } from "@hookform/resolvers/zod";
import { Notam } from "@repo/db"; import { ConfigOptionalDefaults, ConfigOptionalDefaultsSchema } from "@repo/db/zod";
import { NotamOptionalDefaults, NotamOptionalDefaultsSchema } from "@repo/db/zod";
import { useForm } from "react-hook-form"; import { useForm } from "react-hook-form";
import { addMessage, disableMessage } from "../action"; import { addMessage, disableMessage } from "../action";
import "react-datepicker/dist/react-datepicker.css"; // <-- Add this line at the top if using react-datepicker import "react-datepicker/dist/react-datepicker.css"; // <-- Add this line at the top if using react-datepicker
@@ -16,8 +15,8 @@ export const MessageForm = ({ tableRef }: { tableRef: RefObject<PaginatedTableRe
tableRef?.current?.refresh(); tableRef?.current?.refresh();
}; };
const form = useForm<NotamOptionalDefaults>({ const form = useForm<ConfigOptionalDefaults>({
resolver: zodResolver(NotamOptionalDefaultsSchema), resolver: zodResolver(ConfigOptionalDefaultsSchema),
}); });
return ( return (

View File

@@ -1,9 +1,9 @@
"use server"; "use server";
import { prisma, Prisma } from "@repo/db"; import { prisma, Prisma } from "@repo/db";
export const addMessage = async (notam: Prisma.NotamCreateInput) => { export const addMessage = async (notam: Prisma.ConfigCreateInput) => {
try { try {
await prisma.notam.create({ await prisma.config.create({
data: notam, data: notam,
}); });
} catch (error) { } catch (error) {
@@ -13,7 +13,7 @@ export const addMessage = async (notam: Prisma.NotamCreateInput) => {
export const disableMessage = async () => { export const disableMessage = async () => {
try { try {
await prisma.notam.create({ await prisma.config.create({
data: {}, data: {},
}); });
} catch (error) { } catch (error) {

View File

@@ -4,7 +4,7 @@ import { Check, MessageSquareWarning, Settings } from "lucide-react";
import { MessageForm } from "./_components/MessageForm"; import { MessageForm } from "./_components/MessageForm";
import { PaginatedTable, PaginatedTableRef } from "_components/PaginatedTable"; import { PaginatedTable, PaginatedTableRef } from "_components/PaginatedTable";
import { ColumnDef } from "@tanstack/react-table"; import { ColumnDef } from "@tanstack/react-table";
import { Notam } from "@repo/db"; import { Config } from "@repo/db";
import { useRef } from "react"; import { useRef } from "react";
export default function MessagePage() { export default function MessagePage() {
@@ -25,7 +25,7 @@ export default function MessagePage() {
</div> </div>
<PaginatedTable <PaginatedTable
ref={tableRef} ref={tableRef}
prismaModel="notam" prismaModel="config"
initialOrderBy={[{ id: "createdAt", desc: true }]} initialOrderBy={[{ id: "createdAt", desc: true }]}
columns={ columns={
[ [
@@ -72,7 +72,7 @@ export default function MessagePage() {
}); });
}, },
}, },
] as ColumnDef<Notam>[] ] as ColumnDef<Config>[]
} }
/> />
</> </>

View File

@@ -2,7 +2,7 @@ import { prisma } from "@repo/db";
import { MessageCircleWarning } from "lucide-react"; import { MessageCircleWarning } from "lucide-react";
export const WarningAlert = async () => { export const WarningAlert = async () => {
const mainMessage = await await prisma.notam.findFirst({ const mainMessage = await await prisma.config.findFirst({
orderBy: { orderBy: {
createdAt: "desc", createdAt: "desc",
}, },

View File

@@ -0,0 +1,19 @@
import { prisma } from "@repo/db";
import { NextResponse } from "next/server";
export async function GET(request: Request): Promise<NextResponse> {
try {
const config = await prisma.config.findFirst({
orderBy: {
createdAt: "desc",
},
});
return NextResponse.json(config, {
status: 200,
});
} catch (error) {
console.error(error);
return NextResponse.json({ error: "Failed to fetch Aircrafts" }, { status: 500 });
}
}

View File

@@ -27,7 +27,7 @@ const RootLayout = async ({
}>) => { }>) => {
const session = await getServerSession(); const session = await getServerSession();
const latestNotam = await prisma.notam.findFirst({ const latestNotam = await prisma.config.findFirst({
orderBy: { createdAt: "desc" }, orderBy: { createdAt: "desc" },
}); });

View File

@@ -7,7 +7,7 @@ enum GlobalColor {
ERROR ERROR
} }
model Notam { model Config {
id Int @id @default(autoincrement()) id Int @id @default(autoincrement())
color GlobalColor? color GlobalColor?
message String @default("") message String @default("")

View File

@@ -0,0 +1 @@
-- This is an empty migration.

View File

@@ -0,0 +1,20 @@
/*
Warnings:
- You are about to drop the `Notam` table. If the table is not empty, all the data it contains will be lost.
*/
-- DropTable
DROP TABLE "Notam";
-- CreateTable
CREATE TABLE "Config" (
"id" SERIAL NOT NULL,
"color" "GlobalColor",
"message" TEXT NOT NULL DEFAULT '',
"maintenanceEnabled" BOOLEAN NOT NULL DEFAULT false,
"disableHPG" BOOLEAN NOT NULL DEFAULT false,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "Config_pkey" PRIMARY KEY ("id")
);