# Ticket List

| | |
|---|---|
| **Nav ID** | `ticket-list` |
| **Component** | `AdminTicketListPage.jsx` |
| **Service** | `ticketsApi.js` |

Uses `useMasterData()` for status/type labels.

---

## Endpoints

See prior endpoint docs for `/tickets`.

---

## SQL queries

### List tickets

```sql
SELECT * FROM tickets ORDER BY id DESC;
```

With status filter (`?status_id=1`):

```sql
SELECT * FROM tickets WHERE `status_id` = ? ORDER BY id DESC;
```

### Get one ticket

```sql
SELECT * FROM tickets WHERE id = ? LIMIT 1;
```

### Update ticket (transaction)

Snapshot **before** update:

```sql
INSERT INTO tickets_logs
  (ticket_id, user_id, status_id, ticket_type_id, description, created_at, closed_at)
SELECT id, user_id, status_id, ticket_type_id, description, created_at, closed_at
FROM tickets WHERE id = ? LIMIT 1;

UPDATE tickets SET `description` = ?, `status_id` = ?, `closed_at` = ?
WHERE id = ?;
```

### Delete ticket (transaction)

```sql
INSERT INTO tickets_logs (...) SELECT ... FROM tickets WHERE id = ? LIMIT 1;
DELETE FROM tickets WHERE id = ?;
```

**Controller:** `ticketsController.js`
