The Friends API powers Sealearn’s social layer. Users can discover other learners by username, send and manage friend requests, inspect anyone’s public profile, and see how their friends stack up in a weekly XP leaderboard. Every endpoint in this group requires a valid JWT — attach the token as aDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/DerBasilisk/SEA-ServicioEvaluaconAsistida/llms.txt
Use this file to discover all available pages before exploring further.
Bearer value in the Authorization header of every request.
All routes are mounted under
/api/friends and protected by the verificarToken middleware. Requests without a valid token receive 401 Unauthorized.The Friendship Model
AFriendship document is created whenever one user sends a friend request to another. Its status field tracks the lifecycle of the relationship.
| Field | Type | Description |
|---|---|---|
_id | ObjectId | Unique document ID — used when accepting or rejecting a request. |
requester | ObjectId → User | The user who sent the request. |
recipient | ObjectId → User | The user who received the request. |
status | "pending" | "accepted" | "rejected" | Current state of the friendship. |
createdAt | Date | Timestamp of when the request was first sent (auto-managed by Mongoose timestamps). |
updatedAt | Date | Timestamp of the last status change. |
{ requester, recipient } prevents duplicate requests between the same pair. If a previously rejected friendship exists and a new request is sent, the server re-uses the existing document and sets its status back to "pending".
Endpoints
GET /api/friends
Returns the list of accepted friends for the authenticated user. Both sides of eachFriendship document are resolved, so it doesn’t matter who originally sent the request.
Response fields per friend object:
true on success.Array of populated User objects.
GET /api/friends/requests
Returns all incoming friend requests that are still in"pending" status for the authenticated user. Only requests where the authenticated user is the recipient are returned.
true on success.Array of Friendship documents with the
requester field populated.GET /api/friends/search
Searches active users byusername or displayName. Results are case-insensitive and limited to 8 matches. The query string must be at least 2 characters; shorter values return an empty array immediately.
Each result includes a friendStatus field so the client can immediately render the correct call-to-action (add, pending, already friends, etc.).
Search term (minimum 2 characters). Matched against both
username and displayName using a case-insensitive regex.true on success.Up to 8 matching User objects.
GET /api/friends/leaderboard
Returns a weekly XP leaderboard that includes the authenticated user and all of their accepted friends. Ranking is based onxpEarned accumulated in the user’s current league room since the week started (Monday 00:00 UTC). Users not yet assigned to a league room for the current week show 0 XP.
true on success.Sorted array of leaderboard entries, highest XP first.
GET /api/friends/profile/:username
Returns the public profile of any user, identified by their username. The response also includes the friendship status between the viewer and the profile owner, enabling the client to show the correct social action button. Achievements, active cosmetic frame, and active background are fully populated.The target user’s username (case-sensitive, exact match).
true on success.Public profile object.
POST /api/friends/request
Sends a friend request to another user identified by their username. If the target previously rejected a request from the authenticated user, the existing document is reused and its status is reset to"pending".
The username of the user to befriend. The lookup is case-insensitive.
true on success.Human-readable confirmation or error detail.
The newly created (or reactivated) Friendship document.
400—usernamenot provided, attempting to add yourself, already friends, or request already pending.404— Username not found.
PUT /api/friends/request/:id/accept
Accepts a pending incoming friend request. The:id parameter is the _id of the Friendship document, which can be found in the response from GET /api/friends/requests. Only the recipient of the request can call this endpoint.
The
_id of the Friendship document to accept.true on success."Solicitud aceptada".PUT /api/friends/request/:id/reject
Rejects a pending incoming friend request. Sets the friendshipstatus to "rejected". Only the recipient can call this endpoint.
The
_id of the Friendship document to reject.true on success."Solicitud rechazada".DELETE /api/friends/:userId
Removes an accepted friendship between the authenticated user and the target. Both directions of theFriendship document are checked, so either party can remove the other.
The MongoDB
_id of the friend to remove.true on success."Amigo eliminado".