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
This commit is contained in:
parent
52f3aee8e4
commit
d7c6136fcb
@ -329,6 +329,34 @@ export async function registerRoutes(app: Express): Promise<Server> {
|
|||||||
res.status(500).json({ message: "Failed to fetch guards availability" });
|
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 =============
|
// ============= VEHICLE ROUTES =============
|
||||||
app.get("/api/vehicles", isAuthenticated, async (req, res) => {
|
app.get("/api/vehicles", isAuthenticated, async (req, res) => {
|
||||||
@ -1212,7 +1240,7 @@ export async function registerRoutes(app: Express): Promise<Server> {
|
|||||||
// Assign guard to site/date with specific time slot (supports multi-day assignments)
|
// Assign guard to site/date with specific time slot (supports multi-day assignments)
|
||||||
app.post("/api/general-planning/assign-guard", isAuthenticated, async (req, res) => {
|
app.post("/api/general-planning/assign-guard", isAuthenticated, async (req, res) => {
|
||||||
try {
|
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) {
|
if (!siteId || !date || !guardId || !startTime || !durationHours) {
|
||||||
return res.status(400).json({
|
return res.status(400).json({
|
||||||
@ -1317,6 +1345,7 @@ export async function registerRoutes(app: Express): Promise<Server> {
|
|||||||
endTime: shiftEnd,
|
endTime: shiftEnd,
|
||||||
shiftType: site.shiftType || "fixed_post",
|
shiftType: site.shiftType || "fixed_post",
|
||||||
status: "planned",
|
status: "planned",
|
||||||
|
vehicleId: vehicleId || null,
|
||||||
}).returning();
|
}).returning();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user