added get query to mission store
This commit is contained in:
@@ -1,9 +1,11 @@
|
|||||||
|
import { Prisma } from "@repo/db";
|
||||||
import { MissionOptionalDefaults } from "@repo/db/zod";
|
import { MissionOptionalDefaults } from "@repo/db/zod";
|
||||||
import { create } from "zustand";
|
import { create } from "zustand";
|
||||||
|
|
||||||
interface MissionStore {
|
interface MissionStore {
|
||||||
missions: MissionOptionalDefaults[];
|
missions: MissionOptionalDefaults[];
|
||||||
setMissions: (missions: MissionOptionalDefaults[]) => void;
|
setMissions: (missions: MissionOptionalDefaults[]) => void;
|
||||||
|
getMissions: () => Promise<undefined>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useMissionsStore = create<MissionStore>((set) => ({
|
export const useMissionsStore = create<MissionStore>((set) => ({
|
||||||
@@ -24,4 +26,25 @@ export const useMissionsStore = create<MissionStore>((set) => ({
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
setMissions: (missions) => set({ missions }),
|
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;
|
||||||
|
},
|
||||||
}));
|
}));
|
||||||
|
|||||||
14
apps/dispatch/app/api/mission/route.ts
Normal file
14
apps/dispatch/app/api/mission/route.ts
Normal file
@@ -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);
|
||||||
|
};
|
||||||
Binary file not shown.
Reference in New Issue
Block a user