[Goto Home](/docs/index.html)

# 🔒 GET `/alerts/single`

## Description

- Returns a single unviewed alert for the authenticated user.
- Finds alerts that the user has **not yet viewed** (not present in `alert-views` collection).
- Returns the most recently created unviewed alert, subject to location filtering:
  - If the alert has a linked **event with a location**, the alert is only returned if that event is within **25 km** of the user's location.
  - If the alert has a linked event with no location, or no linked event at all, it is returned regardless of the user's location.
  - If the alert has a location-gated event but the user has no location set, the alert is excluded.
- Returns `null` if no unviewed alerts exist.

## Response Body

```json
{
  "alert": {
    "_id": "68a2f0f8a64cd0088270de83",
    "title": "New Feature Available!",
    "description": "Check out the new explore tab with enhanced discovery.",
    "buttonLabel": "Explore Now",
    "photo": "https://...",
    "video": null,
    "action": "explore",
    "event": null,
    "reel": null,
    "link": null,
    "createdAt": "2025-10-09T06:17:19.192Z",
    "updatedAt": "2025-10-09T06:17:19.192Z"
  }
}
```

Returns `{ "alert": null }` if no unviewed alerts exist.

---

# 🔒 POST `/alerts/:id/viewed`

## Description

- Marks an alert as viewed by the authenticated user.
- Creates an entry in the `alert-views` collection.
- If the user has already viewed this alert, returns `200` with a message instead of creating a duplicate.
- Does **not** emit a socket notification — socket notification is handled at alert creation time via the admin API.

## Request Params

- `id` – required, MongoDB ObjectId of the alert.

## Response Body

```json
{
  "message": "alert view created successfully"
}
```

## Error Responses

- **400** – `id` is not a valid MongoDB ObjectId.
- **404** – Alert not found.

# Links

[Goto Home](/docs/index.html)
