added get query to mission store

This commit is contained in:
PxlLoewe
2025-04-21 15:06:14 -07:00
parent 9b4e3085c3
commit 01844e0ad9
3 changed files with 37 additions and 0 deletions

View File

@@ -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<undefined>;
}
export const useMissionsStore = create<MissionStore>((set) => ({
@@ -24,4 +26,25 @@ export const useMissionsStore = create<MissionStore>((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;
},
}));