Badges
Manage and award badges to users for achievements and recognition.
Base Endpoint
Section titled “Base Endpoint”All badge endpoints are prefixed with /badges
Public Endpoints
Section titled “Public Endpoints”Get All Badges
Section titled “Get All Badges”GET /badgesGet all badges.
Authentication: Not required
Query Parameters:
isActive(boolean, optional) - Filter by active status
Response:
{ "badges": [ { "id": "badge-id", "name": "Early Adopter", "slug": "early-adopter", "description": "Joined during beta", "iconUrl": "https://...", "color": "#FF5733", "isActive": true, "awardedCount": 150, "createdAt": "2024-01-01T00:00:00Z" } ]}Get Badge by ID
Section titled “Get Badge by ID”GET /badges/:badgeIdGet a specific badge by ID.
Authentication: Not required
URL Parameters:
badgeId(string) - Badge ID
Response:
{ "id": "badge-id", "name": "Early Adopter", "slug": "early-adopter", "description": "Joined during beta", "iconUrl": "https://...", "color": "#FF5733", "isActive": true, "awardedCount": 150}Get Badge by Slug
Section titled “Get Badge by Slug”GET /badges/slug/:slugGet a badge by its unique slug.
Authentication: Not required
URL Parameters:
slug(string) - Badge slug
Response: Same as get by ID
Get User Badges
Section titled “Get User Badges”GET /badges/users/:userIdGet all badges awarded to a specific user.
Authentication: Not required
URL Parameters:
userId(string) - User ID
Response:
{ "badges": [ { "id": "badge-id", "name": "Early Adopter", "slug": "early-adopter", "description": "Joined during beta", "iconUrl": "https://...", "color": "#FF5733", "awardedAt": "2024-01-05T00:00:00Z", "awardedBy": { "id": "admin-id", "username": "admin" } } ]}Admin Endpoints
Section titled “Admin Endpoints”Create Badge
Section titled “Create Badge”POST /badgesCreate a new badge.
Authentication: Required (Admin or Super Admin)
Request Body:
{ "name": "Contributor", "slug": "contributor", "description": "Contributed code to the project", "iconUrl": "https://...", "color": "#4CAF50", "isActive": true}Response:
{ "id": "badge-id", "name": "Contributor", "slug": "contributor", "createdAt": "2024-01-01T00:00:00Z"}Update Badge
Section titled “Update Badge”PATCH /badges/:badgeIdUpdate a badge.
Authentication: Required (Admin or Super Admin)
URL Parameters:
badgeId(string) - Badge ID
Request Body: (all fields optional)
{ "name": "Updated Name", "description": "Updated description", "color": "#FF5733", "isActive": false}Delete Badge
Section titled “Delete Badge”DELETE /badges/:badgeIdDelete a badge.
Authentication: Required (Admin or Super Admin)
URL Parameters:
badgeId(string) - Badge ID
Note: Deleting a badge also removes it from all users who have been awarded it.
Moderator Endpoints
Section titled “Moderator Endpoints”Award Badge
Section titled “Award Badge”POST /badges/awardAward a badge to a user.
Authentication: Required (Moderator, Admin, or Super Admin)
Request Body:
{ "badgeId": "badge-id", "userId": "user-id", "reason": "Optional reason for awarding"}Response:
{ "message": "Badge awarded successfully", "userBadge": { "id": "user-badge-id", "userId": "user-id", "badgeId": "badge-id", "awardedAt": "2024-01-01T00:00:00Z" }}Revoke Badge
Section titled “Revoke Badge”DELETE /badges/:badgeId/users/:userIdRevoke a badge from a user.
Authentication: Required (Moderator, Admin, or Super Admin)
URL Parameters:
badgeId(string) - Badge IDuserId(string) - User ID
Response:
{ "message": "Badge revoked successfully"}