# Pages APIs

All routes are prefixed with `pages` as defined in `src/pages/pages.controller.ts`.

## Overview
The Pages module manages static pages (e.g., About, Terms) and FAQs.
- Admin endpoints let SUPER_ADMIN/STAFF list and update pages and add new FAQ items.
- A public endpoint returns content by page type; for `FAQS` it returns an array (Q&A list), for other page types a single document with title/description.

---

## Endpoints

### 1) Create FAQ item
- Method: `POST`
- Path: `/pages/faqs`
- Auth: Bearer
- Roles: `SUPER_ADMIN`, `STAFF`
- Params location: Query string (controller expects query, not body)
- Query (`AddFAQsDto`):
```http
POST /pages/faqs?question=What%20is%20Kynekt%3F&answere=Kynekt
Authorization: Bearer <JWT>
```
- Behavior (`PagesService.createFaqs`): Creates a new FAQ row with `page_type=FAQS`.
- Success Response (200):
```json
{ "message": "New FAQs added successfully" }
```

---

### 2) List pages (admin)
- Method: `GET`
- Path: `/pages`
- Auth: Bearer
- Roles: `SUPER_ADMIN`, `STAFF`
- Query (`PagesListDto`):
```text
page?: number
limit?: number
search?: string  // currently not used in service
```
- Behavior (`PagesService.getAllpagesData`): Returns paginated list sorted using `CommonService.setOptions(page, limit)`.
- Success Response (200):
```json
{
  "message": "Page found successfully",
  "data": [ { "_id": "...", "page_type": "...", ... } ],
  "counts": 42
}
```

---

### 3) Get content by page type (public)
- Method: `GET`
- Path: `/pages/:type`
- Auth: Public
- Params:
  - `type`: page type string (e.g., `FAQS`, `ABOUT_US`, `TERMS_AND_CONDITIONS`, etc.)
- Behavior (`PagesService.getByPageTypes`):
  - If `type === FAQS`: returns an array of `{ question, answere, page_type, _id }`.
  - Else: returns a single page document `{ title, description, page_type, _id }`.
- Success Response (FAQS example):
```json
{
  "message": "Page found successfully",
  "data": [
    { "_id": "...", "question": "What is Kynekt?", "answere": "Kynekt", "page_type": "FAQS" }
  ]
}
```
- Success Response (content page example):
```json
{
  "message": "Page found successfully",
  "data": { "_id": "...", "title": "ABOUT US", "description": "This is the about us page.", "page_type": "ABOUT_US" }
}
```

---

### 4) Update page by id (admin)
- Method: `PUT`
- Path: `/pages/:id`
- Auth: Bearer
- Roles: `SUPER_ADMIN`, `STAFF`
- Body (`EditPagesDto`):
```json
{
  "question": "Updated question?",    // for FAQS only
  "answere": "Updated answer.",       // for FAQS only
  "title": "ABOUT US",
  "description": "Updated description"
}
```
- Behavior (`PagesService.updatePageTypes`):
  - Finds the page by `_id` and updates only provided fields.
- Success Response (200):
```json
{
  "message": "Page updated successfully",
  "data": { "_id": "...", "title": "ABOUT US", "description": "Updated description", ... }
}
```

---

## DTOs
From `src/pages/dto/pages.dto.ts`:
- `PagesListDto`: `page?`, `limit?`, `search?`
- `EditPagesDto`: `question?`, `answere?`, `title?`, `description?`
- `AddFAQsDto`: `question?`, `answere?`

## Notes
- The module seeds default page entries for each `PageType` at service construction via `createTypes()`; if a type doesn't exist, it creates a default row (FAQS gets a sample Q&A; other types get title/description placeholders).
- For `Create FAQ`, parameters are expected in the query string per controller implementation; switch to body in the future if preferred.
- Ensure the `AuthGuard` and `RolesGuard` are wired so `req.user` and role metadata are applied correctly to protected routes.