@@ -43,14 +43,9 @@ import type {
4343 UserData ,
4444} from '../src/types' ;
4545import { executeGraphQL } from './serverUtils' ;
46+ import { SubmissionArgs , CalendarArgs , ProblemArgs , DiscussCommentsArgs , Variables } from './types' ;
4647
47- type SubmissionArgs = { username : string ; limit ?: number } ;
48- type CalendarArgs = { username : string ; year : number } ;
49- type ProblemArgs = { limit ?: number ; skip ?: number ; tags ?: string ; difficulty ?: string } ;
50- type DiscussCommentsArgs = { topicId : number ; orderBy ?: string ; pageNo ?: number ; numPerPage ?: number } ;
51-
52- type Variables = Record < string , unknown > ;
53-
48+ // Builds GraphQL variables by filtering out undefined, null, and NaN values.
5449function buildVariables ( input : Record < string , unknown > ) : Variables {
5550 const result : Variables = { } ;
5651 for ( const [ key , value ] of Object . entries ( input ) ) {
@@ -61,82 +56,98 @@ function buildVariables(input: Record<string, unknown>): Variables {
6156 return result ;
6257}
6358
59+ // Retrieves the formatted user profile summary.
6460export async function getUserProfileSummary ( username : string ) {
6561 const data = await executeGraphQL ( userProfileQuery , { username } ) ;
6662 return formatUserData ( data as UserData ) ;
6763}
6864
65+ // Retrieves the formatted user badges data.
6966export async function getUserBadges ( username : string ) {
7067 const data = await executeGraphQL ( userProfileQuery , { username } ) ;
7168 return formatBadgesData ( data as UserData ) ;
7269}
7370
71+ // Retrieves the formatted user contest data.
7472export async function getUserContest ( username : string ) {
7573 const data = await executeGraphQL ( contestQuery , { username } ) ;
7674 return formatContestData ( data as UserData ) ;
7775}
7876
77+ // Retrieves the formatted user contest history.
7978export async function getUserContestHistory ( username : string ) {
8079 const data = await executeGraphQL ( contestQuery , { username } ) ;
8180 return formatContestHistoryData ( data as UserData ) ;
8281}
8382
83+ // Retrieves the formatted solved problems statistics.
8484export async function getSolvedProblems ( username : string ) {
8585 const data = await executeGraphQL ( userProfileQuery , { username } ) ;
8686 return formatSolvedProblemsData ( data as UserData ) ;
8787}
8888
89+ // Retrieves recent submissions for a user.
8990export async function getRecentSubmission ( args : SubmissionArgs ) {
9091 const variables = buildVariables ( { username : args . username , limit : args . limit } ) ;
9192 const data = await executeGraphQL ( submissionQuery , variables ) ;
9293 return formatSubmissionData ( data as UserData ) ;
9394}
9495
96+ // Retrieves recent accepted submissions for a user.
9597export async function getRecentAcSubmission ( args : SubmissionArgs ) {
9698 const variables = buildVariables ( { username : args . username , limit : args . limit } ) ;
9799 const data = await executeGraphQL ( AcSubmissionQuery , variables ) ;
98100 return formatAcSubmissionData ( data as UserData ) ;
99101}
100102
103+ // Retrieves the submission calendar for a user in a given year.
101104export async function getSubmissionCalendar ( args : CalendarArgs ) {
102105 const variables = buildVariables ( { username : args . username , year : args . year } ) ;
103106 const data = await executeGraphQL ( userProfileCalendarQuery , variables ) ;
104107 return formatSubmissionCalendarData ( data as UserData ) ;
105108}
106109
110+ // Retrieves the aggregated user profile data.
107111export async function getUserProfileAggregate ( username : string ) {
108112 const data = await executeGraphQL ( getUserProfileQuery , { username } ) ;
109113 return formatUserProfileData ( data ) ;
110114}
111115
116+ // Retrieves the language statistics for a user.
112117export async function getLanguageStats ( username : string ) {
113118 const data = await executeGraphQL ( languageStatsQuery , { username } ) ;
114119 return formatLanguageStats ( data as UserData ) ;
115120}
116121
122+ // Retrieves the skill statistics for a user.
117123export async function getSkillStats ( username : string ) {
118124 const data = await executeGraphQL ( skillStatsQuery , { username } ) ;
119125 return formatSkillStats ( data as UserData ) ;
120126}
121127
128+ // Retrieves the daily problem.
122129export async function getDailyProblem ( ) {
123130 const data = await executeGraphQL ( dailyProblemQuery , { } ) ;
124131 return formatDailyData ( data as DailyProblemData ) ;
125132}
126133
134+ // Retrieves the raw daily problem data.
127135export async function getDailyProblemRaw ( ) {
128136 return executeGraphQL ( dailyProblemQuery , { } ) ;
129137}
130138
139+ // Retrieves a selected problem by title slug.
131140export async function getSelectProblem ( titleSlug : string ) {
132141 const data = await executeGraphQL ( selectProblemQuery , { titleSlug } ) ;
133142 return formatQuestionData ( data as SelectProblemData ) ;
134143}
135144
145+ // Retrieves the raw data for a selected problem by title slug.
136146export async function getSelectProblemRaw ( titleSlug : string ) {
137147 return executeGraphQL ( selectProblemQuery , { titleSlug } ) ;
138148}
139149
150+ // Retrieves a list of problems based on the given arguments.
140151export async function getProblemSet ( args : ProblemArgs ) {
141152 const limit = args . skip !== undefined && args . limit === undefined ? 1 : args . limit ?? 20 ;
142153 const skip = args . skip ?? 0 ;
@@ -155,19 +166,23 @@ export async function getProblemSet(args: ProblemArgs) {
155166 return formatProblemsData ( data as ProblemSetQuestionListData ) ;
156167}
157168
169+ // Retrieves the official solution for a problem.
158170export async function getOfficialSolution ( titleSlug : string ) {
159171 return executeGraphQL ( officialSolutionQuery , { titleSlug } ) ;
160172}
161173
174+ // Retrieves trending discussion topics.
162175export async function getTrendingTopics ( first : number ) {
163176 const data = await executeGraphQL ( trendingDiscussQuery , { first } ) ;
164177 return formatTrendingCategoryTopicData ( data as TrendingDiscussionObject ) ;
165178}
166179
180+ // Retrieves a discussion topic by ID.
167181export async function getDiscussTopic ( topicId : number ) {
168182 return executeGraphQL ( discussTopicQuery , { topicId } ) ;
169183}
170184
185+ // Retrieves comments for a discussion topic.
171186export async function getDiscussComments ( args : DiscussCommentsArgs ) {
172187 const variables = buildVariables ( {
173188 topicId : args . topicId ,
@@ -178,36 +193,44 @@ export async function getDiscussComments(args: DiscussCommentsArgs) {
178193 return executeGraphQL ( discussCommentsQuery , variables ) ;
179194}
180195
196+ // Retrieves raw language statistics for a user.
181197export async function getLanguageStatsRaw ( username : string ) {
182198 return executeGraphQL ( languageStatsQuery , { username } ) ;
183199}
184200
201+ // Retrieves raw submission calendar data for a user.
185202export async function getUserProfileCalendarRaw ( args : CalendarArgs ) {
186203 const variables = buildVariables ( { username : args . username , year : args . year } ) ;
187204 return executeGraphQL ( userProfileCalendarQuery , variables ) ;
188205}
189206
207+ // Retrieves raw user profile data.
190208export async function getUserProfileRaw ( username : string ) {
191209 return executeGraphQL ( getUserProfileQuery , { username } ) ;
192210}
193211
212+ // Retrieves the legacy daily problem data.
194213export async function getDailyProblemLegacy ( ) {
195214 return executeGraphQL ( dailyProblemQuery , { } ) ;
196215}
197216
217+ // Retrieves raw skill statistics for a user.
198218export async function getSkillStatsRaw ( username : string ) {
199219 return executeGraphQL ( skillStatsQuery , { username } ) ;
200220}
201221
222+ // Retrieves the question progress for a user.
202223export async function getUserProgress ( username : string ) {
203224 const data = await executeGraphQL ( userQuestionProgressQuery , { username } ) ;
204225 return formatProgressStats ( data as UserData ) ;
205226}
206227
228+ // Retrieves the contest ranking information for a user.
207229export async function getUserContestRankingInfo ( username : string ) {
208230 return executeGraphQL ( userContestRankingInfoQuery , { username } ) ;
209231}
210232
233+ // Retrieves raw question progress data for a user.
211234export async function getUserProgressRaw ( username : string ) {
212235 return executeGraphQL ( userQuestionProgressQuery , { username } ) ;
213236}
0 commit comments