Boss
The boss.controller.ts file manages world boss data and their progress states. It provides endpoints to retrieve all bosses for a world and to update the killed state of a boss.
Note: All boss routes use the
requireAuthmiddleware to ensure the user is authenticated. ThePATCH /api/boss/:idroute also usesrequireRoleto restrict access to users with the roles: OWNER, ADMIN, or SUB_ADMIN. For more details, see the requireAuth and requireRole documentation.
Key Functions
getWorldBosses
Retrieves all bosses for a given world, including their progress.
Flow:
- Extracts the
idparameter from the request at the endpoint/api/boss/:id(whereidis the world ID). - Queries the database for all bosses, including their progress for the specified world.
- Maps the results to include only the relevant progress for each boss.
- Returns a JSON response with the list of bosses and their progress.
setBossKilledState
Updates the killed state of a specific world boss.
Flow:
- Extracts the
idparameter from the request at the endpoint/api/boss/:id(whereidis the progress ID). - Reads the
killedvalue from the request body. - Updates the killed state in the database for the specified boss progress.
- Returns a success response.
Routes
The following routes are defined in boss.routes.ts and connect HTTP requests to the corresponding controller functions:
| Method | Path | Description | Controller Function | Middleware |
|---|---|---|---|---|
| GET | /api/boss/:id | Retrieve all bosses and their progress for a world | getWorldBosses | requireAuth |
| PATCH | /api/boss/:id | Update killed state for a boss in a world | setBossKilledState | requireAuth, requireRole(["OWNER", "ADMIN", "SUB_ADMIN"]) |
Error Handling
- All errors are caught and returned as a
500 Internal Server Errorwith the error details in the response JSON.
Example Requests & Responses
Get World Bosses
Request:
GET /api/boss/:id
Successful Response:
{
"bosses": [
{
"id": "boss1",
"name": "Dragon Lord",
"health": "2500",
"stage": "pre-hardmode",
"worldProgress": {
"id": "progress1",
"bossId": "boss1",
"worldId": "world1",
"killed": false
}
}
// ...more bosses
]
}
Error Response:
{
"error": "Error details"
}
Set Boss Killed State
Request:
PATCH /api/boss/:id
Content-Type: application/json
{
"killed": true | false
}
Successful Response:
{
"success": true
}
Error Response:
{
"error": "Error details"
}
Usage Instructions
- Retrieve Bosses:
Use
/api/boss/:idto get all bosses and their progress for a specific world. - Update Boss State:
Use
PATCH /api/boss/:idwith a JSON body{ "killed": true|false }to update the killed state of a boss.
Dependencies
- Express: Handles HTTP requests and responses.
- Prisma: ORM for PostgreSQL database operations.