Made Mission marker DB compatible

This commit is contained in:
PxlLoewe
2025-04-24 22:32:18 -07:00
parent 46cbdf6bb9
commit 5bca37182d
22 changed files with 445 additions and 187 deletions

View File

@@ -0,0 +1,79 @@
import { prisma } from "@repo/db";
import { Router } from "express";
const router = Router();
// Get all missions
router.post("/", async (req, res) => {
try {
const filter = req.body?.filter || {};
const missions = await prisma.mission.findMany({
where: filter,
});
res.json(missions);
} catch (error) {
console.error(error);
res.status(500).json({ error: "Failed to fetch missions" });
}
});
// Get a single mission by ID
router.get("/:id", async (req, res) => {
const { id } = req.params;
try {
const mission = await prisma.mission.findUnique({
where: { id: Number(id) },
});
if (mission) {
res.json(mission);
} else {
res.status(404).json({ error: "Mission not found" });
}
} catch (error) {
console.error(error);
res.status(500).json({ error: "Failed to fetch mission" });
}
});
// Create a new mission
router.put("/", async (req, res) => {
try {
const newMission = await prisma.mission.create({
data: req.body,
});
res.status(201).json(newMission);
} catch (error) {
res.status(500).json({ error: "Failed to create mission" });
}
});
// Update a mission by ID
router.patch("/:id", async (req, res) => {
const { id } = req.params;
try {
const updatedMission = await prisma.mission.update({
where: { id: Number(id) },
data: req.body,
});
res.json(updatedMission);
} catch (error) {
console.error(error);
res.status(500).json({ error: "Failed to update mission" });
}
});
// Delete a mission by ID
router.delete("/:id", async (req, res) => {
const { id } = req.params;
try {
await prisma.mission.delete({
where: { id: Number(id) },
});
res.status(204).send();
} catch (error) {
console.error(error);
res.status(500).json({ error: "Failed to delete mission" });
}
});
export default router;

View File

@@ -1,10 +1,12 @@
import { Router } from "express";
import livekitRouter from "./livekit";
import dispatcherRotuer from "./dispatcher";
import missionRouter from "./mission";
const router = Router();
router.use("/livekit", livekitRouter);
router.use("/dispatcher", dispatcherRotuer);
router.use("/mission", missionRouter);
export default router;