From d7c6136fcb895862edcce18e2fbe3007737e8c0b Mon Sep 17 00:00:00 2001 From: marco370 <48531002-marco370@users.noreply.replit.com> Date: Wed, 22 Oct 2025 07:50:19 +0000 Subject: [PATCH] Add ability to assign vehicles to guards for specific shifts Adds a new API endpoint to retrieve available vehicles by location and modifies the general planning route to include vehicle assignments for guards. Replit-Commit-Author: Agent Replit-Commit-Session-Id: e5565357-90e1-419f-b9a8-6ee8394636df Replit-Commit-Checkpoint-Type: intermediate_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/6d543d2c-20b9-4ea6-93fe-70fe9b1d9f80/e5565357-90e1-419f-b9a8-6ee8394636df/KiuJzNf --- server/routes.ts | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) 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(); }