Skip to main content
The incidents table stores all incident reports submitted by guests or staff members. Each incident is assigned to an area and tracks its resolution status.

Table Name

incidents

Schema Fields

id
uuid
required
Primary key, automatically generated
title
text
required
Brief title of the incident (e.g., “Aire no enfría”)
description
text
required
Detailed description of the problem
priority
enum
required
Priority level for the incidentAllowed values:
  • baja - Low priority
  • media - Medium priority
  • alta - High priority
status
text
default:"pendiente"
Current status of the incidentCommon values:
  • pendiente - Awaiting assignment
  • recibida - Accepted by staff
  • en_progreso - Being worked on
  • resuelta - Resolved
area_id
uuid
required
Foreign key reference to areas.id. Determines which department handles this incident.
room_id
uuid
required
Foreign key reference to rooms.id. Indicates where the incident occurred.
assigned_to
uuid
Foreign key reference to profiles.id. The staff member assigned to resolve this incident.
created_at
timestamp
Automatically set when the incident is created
updated_at
timestamp
Automatically updated when the incident is modified

Relationships

  • areas: Many-to-one relationship via area_id
  • rooms: Many-to-one relationship via room_id
  • profiles: Many-to-one relationship via assigned_to
  • incident_resolutions: One-to-many relationship
  • incident_evidence: One-to-many relationship

Query Examples

Create New Incident

Guests create incidents when reporting problems:
const { error } = await supabase.from("incidents").insert({
  title: "Aire acondicionado no funciona",
  description: "El aire acondicionado no enfría la habitación",
  priority: "alta",
  area_id: areaId,
  room_id: roomId,
});
The status field defaults to "pendiente" if not specified.

Fetch Incidents for a Room

Retrieve all incidents reported from a specific room:
const { data, error } = await supabase
  .from("incidents")
  .select("id, title, description, priority, status, created_at, areas(name)")
  .eq("room_id", roomId)
  .order("created_at", { ascending: false });
Source: mobile/components/MyIncidentsView.tsx:106

Assign Incident to Staff

When a staff member accepts an incident:
const { error } = await supabase
  .from("incidents")
  .update({
    status: "recibida",
    assigned_to: userId,
  })
  .eq("id", incidentId);
Source: mobile/app/(guest)/incidents/[id].tsx:147

Update Incident Status

Progress an incident from “recibida” to “en_progreso”:
const { error } = await supabase
  .from("incidents")
  .update({
    status: "en_progreso",
    updated_at: new Date().toISOString(),
  })
  .eq("id", incidentId);
Source: mobile/app/(guest)/incidents/[id].tsx:232

Load Area-Specific Incidents

Staff members see incidents for their assigned area:
const { data, error } = await supabase
  .from("incidents")
  .select(`
    id, title, description, priority, status, created_at, 
    areas(name), 
    rooms(room_code)
  `)
  .eq("status", "pendiente")
  .eq("area_id", areaId)
  .order("created_at", { ascending: false });
Source: mobile/components/EmpleadoBuzonIncidents.tsx:207

Fetch Incident Details

Retrieve complete incident information including resolutions and evidence:
const { data, error } = await supabase
  .from("incidents")
  .select(`
    *, 
    areas(name), 
    rooms(room_code),
    incident_resolutions(description, created_at, resolved_by),
    incident_evidence(image_url)
  `)
  .eq("id", incidentId)
  .single();
Source: mobile/app/(guest)/incidents/[id].tsx:84

Mark Incident as Resolved

await supabase
  .from("incidents")
  .update({ status: "resuelta" })
  .eq("id", incidentId);
Source: mobile/components/ResolveIncidentBottomSheet.tsx:201

Status Workflow

The incident status follows this typical workflow:

Priority Levels

baja
Low Priority
Color: Green (#10B981)Non-urgent issues that can be handled during regular maintenance
media
Medium Priority
Color: Amber (#F59E0B)Issues requiring attention but not immediately critical
alta
High Priority
Color: Red (#EF4444)Critical issues requiring immediate attention

Incident Resolutions

Resolution details when incidents are completed

Areas

Department assignments for incidents

Rooms

Room location data

Users

Staff member assignments

Build docs developers (and LLMs) love