diff --git a/server/routes.ts b/server/routes.ts index 7c492af..963b6fa 100644 --- a/server/routes.ts +++ b/server/routes.ts @@ -329,6 +329,34 @@ export async function registerRoutes(app: Express): Promise { res.status(500).json({ message: "Failed to fetch guards availability" }); } }); + + // Get vehicles available for a location + app.get("/api/vehicles/available", isAuthenticated, async (req, res) => { + try { + const { location } = req.query; + + if (!location) { + return res.status(400).json({ message: "Missing required parameter: location" }); + } + + // Get all vehicles for this location with status 'available' + const availableVehicles = await db + .select() + .from(vehicles) + .where( + and( + eq(vehicles.location, location as any), + eq(vehicles.status, "available") + ) + ) + .orderBy(vehicles.licensePlate); + + res.json(availableVehicles); + } catch (error) { + console.error("Error fetching available vehicles:", error); + res.status(500).json({ message: "Failed to fetch available vehicles" }); + } + }); // ============= VEHICLE ROUTES ============= app.get("/api/vehicles", isAuthenticated, async (req, res) => { @@ -1212,7 +1240,7 @@ export async function registerRoutes(app: Express): Promise { // Assign guard to site/date with specific time slot (supports multi-day assignments) app.post("/api/general-planning/assign-guard", isAuthenticated, async (req, res) => { try { - const { siteId, date, guardId, startTime, durationHours, consecutiveDays = 1 } = req.body; + const { siteId, date, guardId, startTime, durationHours, consecutiveDays = 1, vehicleId } = req.body; if (!siteId || !date || !guardId || !startTime || !durationHours) { return res.status(400).json({ @@ -1317,6 +1345,7 @@ export async function registerRoutes(app: Express): Promise { endTime: shiftEnd, shiftType: site.shiftType || "fixed_post", status: "planned", + vehicleId: vehicleId || null, }).returning(); }