Skip to main content

Overview

The manageZones endpoint provides Create, Read, Update, and Delete operations for parking zones. Zones are used to organize parking spots into logical groups (e.g., “Federico Froebel”, “Interior DUOC”).

Endpoint

POST /manage-zones

Authentication

CORS-enabled endpoint with wildcard origin (*). Should be restricted to admin users in production.

Request Body

All operations require an action parameter. Additional fields depend on the action.
action
string
required
The operation to perform:
  • create: Create a new zone
  • update: Update an existing zone
  • delete: Delete a zone

Create Action

name
string
required
Display name of the zone (e.g., “Federico Froebel”)
id
string
Custom zone ID. If not provided, generates zone_{timestamp}
order
integer
Display order for sorting zones. Defaults to 999 (end of list)
desc
string
Description of the zone. Defaults to empty string
color
string
Color code for UI display. Defaults to "blue"

Update Action

id
string
required
ID of the zone to update
name
string
required
New display name of the zone
order
integer
New display order (optional)
desc
string
New description (optional)
color
string
New color code (optional)

Delete Action

id
string
required
ID of the zone to delete

Response

success
boolean
Indicates whether the operation was successful
message
string
Result message describing the operation
zone
object
The created/updated zone object (not present for delete operations)
error
string
Error message (only present on failure)

Success Responses

  • 200 OK - Operation completed successfully
  • 204 No Content - OPTIONS preflight response

Error Responses

  • 400 Bad Request - Missing required fields or invalid action
  • 500 Internal Server Error - Database or server error

Code Examples

Create Zone

curl -X POST https://YOUR_REGION-YOUR_PROJECT.cloudfunctions.net/manage-zones \
  -H "Content-Type: application/json" \
  -d '{
    "action": "create",
    "name": "Federico Froebel",
    "order": 1,
    "desc": "Outdoor parking area on Federico Froebel street",
    "color": "blue"
  }'

Update Zone

curl -X POST https://YOUR_REGION-YOUR_PROJECT.cloudfunctions.net/manage-zones \
  -H "Content-Type: application/json" \
  -d '{
    "action": "update",
    "id": "zone_1764307623391",
    "name": "Federico Froebel (Updated)",
    "order": 2,
    "color": "green"
  }'

Delete Zone

curl -X POST https://YOUR_REGION-YOUR_PROJECT.cloudfunctions.net/manage-zones \
  -H "Content-Type: application/json" \
  -d '{
    "action": "delete",
    "id": "zone_1764307623391"
  }'

Response Examples

Create Success

{
  "success": true,
  "message": "Zona creada exitosamente",
  "zone": {
    "id": "zone_1704900000000",
    "name": "Federico Froebel",
    "order": 1,
    "desc": "Outdoor parking area on Federico Froebel street",
    "color": "blue"
  }
}

Update Success

{
  "success": true,
  "message": "Zona actualizada exitosamente",
  "zone": {
    "id": "zone_1764307623391",
    "name": "Federico Froebel (Updated)",
    "updated_at": "2026-03-05T10:30:00.000Z",
    "order": 2,
    "color": "green"
  }
}

Delete Success

{
  "success": true,
  "message": "Zona eliminada exitosamente"
}

Error Examples

{
  "error": "El nombre de la zona es requerido"
}
{
  "error": "El ID de la zona es requerido"
}
{
  "error": "Acción no válida: read. Use 'create', 'update' o 'delete'"
}

Firestore Data Structure

Zone documents in parking_zones collection:
{
  id: "zone_1764307623391",
  name: "Federico Froebel",
  order: 1,
  desc: "Outdoor parking area on Federico Froebel street",
  color: "blue",
  created_at: Timestamp,
  updated_at: Timestamp
}

Update Behavior

  • Only provided fields are updated (partial updates)
  • updated_at timestamp is always set
  • Undefined fields are ignored (not deleted)
  • To delete a field, explicitly set it to null or empty string

Zone Deletion Considerations

Deleting a zone does not delete parking spots assigned to that zone. Spots will retain their zone_id reference, which may become orphaned.
Before deleting a zone:
  1. Update all spots to remove zone_id or assign to a different zone
  2. Or implement cascade deletion logic in your application
// Reassign spots before deleting zone
const spots = await fetch('/get-parking-status').then(r => r.json());
const affectedSpots = spots.filter(s => s.zone_id === 'zone_1764307623391');

for (const spot of affectedSpots) {
  await fetch('/create-parking-spot', {
    method: 'POST',
    body: JSON.stringify({
      id: spot.id,
      zone_id: null // Remove zone assignment
    })
  });
}

// Now safe to delete zone
await fetch('/manage-zones', {
  method: 'POST',
  body: JSON.stringify({
    action: 'delete',
    id: 'zone_1764307623391'
  })
});

Build docs developers (and LLMs) love