Overview
The Debates API provides functions to create, end, retrieve, and list debate sessions. All mutations require user authentication via Convex Auth.create
Parameters
Name of the first speaker in the debate
Name of the second speaker in the debate
Returns
The unique identifier for the newly created debate
Authentication
Requires authenticated user. ThrowsError("Not authenticated") if user is not logged in.
Behavior
- Sets initial status to
"active" - Records
startedAttimestamp usingDate.now() - Associates debate with current authenticated user’s ID
end
Parameters
The ID of the debate to end
Returns
Returns null on success
Authentication
Requires authenticated user who owns the debate. Throws:Error("Not authenticated")if user is not logged inError("Not found")if debate doesn’t exist or user doesn’t own it
Behavior
- Validates user owns the debate
- Updates debate status to
"ended" - Records
endedAttimestamp - Schedules
internal.claimExtraction.extractto run immediately
get
Parameters
The ID of the debate to retrieve
Returns
The debate object or null if not found
Debate Object Structure
Unique debate identifier
Convex automatic creation timestamp
ID of the user who created the debate
Name of speaker A
Name of speaker B
Current debate status
Unix timestamp when debate started
Unix timestamp when debate ended (optional, only present for ended debates)
list
Parameters
No parameters required.Returns
Array of debate objects owned by the current user, ordered by creation time (descending)
Authentication
Optional. Returns empty array[] if user is not authenticated.
Behavior
- Uses
by_userindex for efficient querying - Returns debates in descending order (newest first)
- Only returns debates owned by the authenticated user
Validation Schema
The debate validator used for type safety:Status Transitions
- Debates start as
"active"when created - Only transition is from
"active"to"ended"via theendmutation - Ended debates cannot be reactivated