# Question Management

| | |
|---|---|
| **Nav ID** | `question-management` |
| **Component** | `AdminQuestionManagementPage.jsx` |
| **Services** | `formsApi.js` |

Uses `useMasterData()` for `ptw_question_type` options.

---

## Endpoints

See prior docs for `/ptw_questions`, `/ptw_question_options`, `/ptw_section_question_map`.

---

## SQL queries

All question and option endpoints use the **generic CRUD router**.

### List / get questions

```sql
SELECT * FROM `ptw_questions`;

SELECT * FROM `ptw_questions` WHERE `question_id` = ? LIMIT 1;

-- with filter:
SELECT * FROM `ptw_questions` WHERE `question_type_id` = ?;
SELECT * FROM `ptw_questions` WHERE `question` LIKE ?;   -- question_like param
```

### Create question

```sql
INSERT INTO `ptw_questions` (`question`, `question_type_id`, `allows_media`)
VALUES (?, ?, ?);
```

### Update / delete question

```sql
UPDATE `ptw_questions` SET `question` = ?, `allows_media` = ? WHERE `question_id` = ?;

DELETE FROM `ptw_questions` WHERE `question_id` = ?;
```

### Question options

```sql
SELECT * FROM `ptw_question_options` WHERE `question_id` = ?;

INSERT INTO `ptw_question_options` (`question_id`, `_options`) VALUES (?, ?);

DELETE FROM `ptw_question_options` WHERE `question_options_id` = ?;
```

### Optional section mapping (from create flow)

```sql
INSERT INTO `ptw_section_question_map` (`section_id`, `question_id`) VALUES (?, ?);
```

### Sections dropdown

```sql
SELECT * FROM `ptw_section_details`;
```

**Backend:** generic CRUD on `ptw_questions`, `ptw_question_options`; dedicated insert for `ptw_section_question_map`.
