diff --git a/apps/dispatch/app/_store/missionsStore.ts b/apps/dispatch/app/_store/missionsStore.ts index 19ac8c5f..d8e46101 100644 --- a/apps/dispatch/app/_store/missionsStore.ts +++ b/apps/dispatch/app/_store/missionsStore.ts @@ -1,9 +1,11 @@ +import { Prisma } from "@repo/db"; import { MissionOptionalDefaults } from "@repo/db/zod"; import { create } from "zustand"; interface MissionStore { missions: MissionOptionalDefaults[]; setMissions: (missions: MissionOptionalDefaults[]) => void; + getMissions: () => Promise; } export const useMissionsStore = create((set) => ({ @@ -24,4 +26,25 @@ export const useMissionsStore = create((set) => ({ }, ], setMissions: (missions) => set({ missions }), + getMissions: async () => { + const res = await fetch("/api/mission", { + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + OR: [ + { + state: "draft", + }, + { + state: "running", + }, + ], + } as Prisma.MissionWhereInput), + }); + if (!res.ok) return undefined; + const data = await res.json(); + set({ missions: data }); + return undefined; + }, })); diff --git a/apps/dispatch/app/api/mission/route.ts b/apps/dispatch/app/api/mission/route.ts new file mode 100644 index 00000000..0992ef67 --- /dev/null +++ b/apps/dispatch/app/api/mission/route.ts @@ -0,0 +1,14 @@ +import { Prisma, prisma } from "@repo/db"; +import { NextRequest, NextResponse } from "next/server"; + +export const GET = (req: NextRequest) => { + const filter = req.nextUrl.searchParams.get("filter") as + | Prisma.MissionWhereInput + | undefined; + + const missions = prisma.mission.findMany({ + where: filter, + }); + + return NextResponse.json(missions); +}; diff --git a/grafana/grafana.db b/grafana/grafana.db index 3abc571d..442bbdae 100644 Binary files a/grafana/grafana.db and b/grafana/grafana.db differ