# Ticket Logs

| | |
|---|---|
| **Nav ID** | `ticket-logs` |
| **Component** | `AdminTicketLogsPage.jsx` |
| **Service** | `ticketsApi.js` → `listTicketLogs` |

---

## Endpoints

### GET `/tickets_logs`

See prior endpoint docs.

---

## SQL queries

### List all ticket audit rows

```sql
SELECT * FROM `tickets_logs`;
```

### Filter by ticket

```http
GET /api/ptw/tickets_logs?ticket_id=55
```

```sql
SELECT * FROM `tickets_logs` WHERE `ticket_id` = ?;
```

### How log rows are created (automatic, not from this page)

On ticket **update** or **delete**, `snapshotTicketLog()` runs inside a transaction:

```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;
```

Each log row is an **immutable snapshot** of the ticket state immediately before the mutation.

**Backend:** generic CRUD read on `tickets_logs`; writes from `ticketsController.js` via `auditLogs.js`.
