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) => {
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 config = req.body as
const body = req.body as
| {
alertWhenValid?: boolean;
}
@@ -336,7 +348,7 @@ router.post("/:id/validate-hpg", async (req, res) => {
io.to(`desktop:${activeAircraftinMission?.userId}`).emit("hpg-validation", {
missionId: parseInt(id),
userId: req.user?.id,
alertWhenValid: config?.alertWhenValid || false,
alertWhenValid: body?.alertWhenValid || false,
});
} catch (error) {
console.error(error);

View File

@@ -438,10 +438,12 @@ export const MissionForm = () => {
} catch (error) {
if (error instanceof AxiosError) {
toast.error(
`Fehler beim Erstellen des Einsatzes: ${error.response?.data.error}`,
`Fehler beim Bearbeiten des Einsatzes: ${error.response?.data.error}`,
);
} 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";
export const WarningAlert = async () => {
const config = await prisma.notam.findFirst({
const config = await prisma.config.findFirst({
orderBy: [{ createdAt: "desc" }],
});

View File

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

View File

@@ -1,8 +1,7 @@
"use client";
import { zodResolver } from "@hookform/resolvers/zod";
import { Notam } from "@repo/db";
import { NotamOptionalDefaults, NotamOptionalDefaultsSchema } from "@repo/db/zod";
import { ConfigOptionalDefaults, ConfigOptionalDefaultsSchema } from "@repo/db/zod";
import { useForm } from "react-hook-form";
import { addMessage, disableMessage } from "../action";
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();
};
const form = useForm<NotamOptionalDefaults>({
resolver: zodResolver(NotamOptionalDefaultsSchema),
const form = useForm<ConfigOptionalDefaults>({
resolver: zodResolver(ConfigOptionalDefaultsSchema),
});
return (

View File

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

View File

@@ -4,7 +4,7 @@ import { Check, MessageSquareWarning, Settings } from "lucide-react";
import { MessageForm } from "./_components/MessageForm";
import { PaginatedTable, PaginatedTableRef } from "_components/PaginatedTable";
import { ColumnDef } from "@tanstack/react-table";
import { Notam } from "@repo/db";
import { Config } from "@repo/db";
import { useRef } from "react";
export default function MessagePage() {
@@ -25,7 +25,7 @@ export default function MessagePage() {
</div>
<PaginatedTable
ref={tableRef}
prismaModel="notam"
prismaModel="config"
initialOrderBy={[{ id: "createdAt", desc: true }]}
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";
export const WarningAlert = async () => {
const mainMessage = await await prisma.notam.findFirst({
const mainMessage = await await prisma.config.findFirst({
orderBy: {
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 latestNotam = await prisma.notam.findFirst({
const latestNotam = await prisma.config.findFirst({
orderBy: { createdAt: "desc" },
});

View File

@@ -7,7 +7,7 @@ enum GlobalColor {
ERROR
}
model Notam {
model Config {
id Int @id @default(autoincrement())
color GlobalColor?
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")
);