# Activity Log

| | |
|---|---|
| **Nav ID** | `activity-log` |
| **Component** | `AdminActivityLogPage.jsx` |
| **Service** | `usersApi.js` → `listUsersLogs` |

---

## Endpoints

### GET `/users_logs`

Read-only audit trail for user create/update/delete actions.

```http
GET /api/ptw/users_logs
Authorization: Bearer <admin_token>
```

**Optional filter**

```http
GET /api/ptw/users_logs?user_id=10
```

**Response:** JSON array of log rows (`log_id`, `user_id`, `action`, timestamps, snapshot fields per schema).

---

## Page flow

1. Load all logs on mount.
2. User enters `user_id` filter → reload with query param.
3. Refresh button re-fetches current filter.

**Backend:** generic CRUD router (read-only in UI; inserts happen from `usersController` on mutations).

---

## SQL queries

### List activity logs

```sql
SELECT * FROM `users_logs`;
```

With user filter (`?user_id=10`):

```sql
SELECT * FROM `users_logs` WHERE `user_id` = ?;
```

### How rows are inserted (on user UPDATE/DELETE)

Not called from this page — written by `snapshotUserLog()` in `auditLogs.js`:

```sql
INSERT INTO users_logs
  (user_id, employee_id, role, status, employee_name, phonenumber,
   department, location, photo, password, action, created_at)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, NOW());
```

The `role`, `status`, `department`, and `location` columns store **denormalized snapshot labels** (not IDs) at the time of the change.
