Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/Praashh/buildml/llms.txt

Use this file to discover all available pages before exploring further.

The userRouter provides four procedures for community statistics, competitive ranking, and personal progress data. getAllUsers, getLeaderboard, and getProfile are public and can be called without authentication. getUserRank requires an active session to identify which user’s rank to compute. All leaderboard and rank calculations derive solvedCount from distinct problemIds with status = "PASS" — a user who submits the same problem multiple times is only counted once.

user.getAllUsers

Returns the total number of registered users on the platform. Useful for social proof displays (“Join 1,200 developers solving ML challenges”). Type: query — Auth: public Input: none
import { api } from '~/trpc/server';

const count = await api.user.getAllUsers();
// count => number, e.g. 1234

Response

(return value)
number
required
Total count of User rows in the database, as returned by Prisma’s user.count().

user.getLeaderboard

Returns all users ranked by the number of unique problems they have solved with a PASS status, sorted descending. Anonymous users (no name set) are displayed as "Anonymous". Type: query — Auth: public Input: none
import { api } from '~/trpc/server';

const leaderboard = await api.user.getLeaderboard();
// leaderboard[0] => top-ranked user

Response

An array of user rank objects, sorted by solvedCount descending:
id
string
required
Unique CUID identifier of the user.
name
string
required
Display name of the user. Falls back to "Anonymous" if the user has no name set.
image
string | null
URL of the user’s profile/avatar image. null if not set.
solvedCount
number
required
Count of distinct problems the user has solved with status = "PASS". Duplicates across multiple passing submissions for the same problem are collapsed.

user.getUserRank

Returns the 1-based leaderboard rank of the currently authenticated user. Rank is determined by sorting all users by solvedCount descending and finding the authenticated user’s position. Type: query — Auth: protected (session required) Input: none
import { api } from '~/trpc/server';

const rank = await api.user.getUserRank();
// rank => 7  (user is 7th on the leaderboard)
// rank => null  (user has no passing submissions yet)

Response

(return value)
number | null
required
The authenticated user’s 1-based leaderboard position, or null if the user is not found in the ranked list (e.g., they have no passing submissions).

user.getProfile

Fetches a detailed profile for any user, including per-difficulty solved counts, total available problems per difficulty, overall solved count, and a daily submission activity history map. If userId is omitted, the current session user’s profile is returned. Type: query — Auth: public Input: { userId?: string }
userId
string
The CUID of the user whose profile to fetch. If omitted, the procedure falls back to ctx.session?.user?.id. Returns null if neither is available.
import { api } from '~/trpc/server';

// Fetch own profile (requires active session)
const profile = await api.user.getProfile({});

// Fetch another user's profile by ID
const profile = await api.user.getProfile({ userId: 'clxyz123...' });

if (!profile) {
  // user not found or no session
}

Response

Returns null if the resolved userId is not found. Otherwise returns:
user
object
required
Basic identity fields for the profile owner.
difficultyCounts
object
required
Number of unique problems the user has solved at each difficulty level. A problem is counted once regardless of how many passing submissions exist for it.
totalCounts
object
required
Total number of problems available on the platform at each difficulty level, derived from prisma.problem.groupBy. Used to render progress bars (e.g., “3 / 10 Easy solved”).
solvedCount
number
required
Total number of unique problems the user has solved across all difficulty levels (Easy + Medium + Hard).
history
Record<string, number>
required
A map of YYYY-MM-DD date strings to the number of passing submissions made on that day. Used to render activity heatmap / contribution graphs.
{
  "2024-11-01": 3,
  "2024-11-04": 1,
  "2024-11-10": 5
}
When userId is omitted and there is no active session, getProfile returns null rather than throwing. Always guard the result before rendering profile UI.

Build docs developers (and LLMs) love