1
+ //graphql query
1
2
const query = `
2
3
query getUserProfile($username: String!) {
3
4
allQuestionsCount {
@@ -28,30 +29,36 @@ const query = `
28
29
}
29
30
}
30
31
` ;
31
- const variables = {
32
- username : "faisalshohagprog"
33
- } ;
34
-
32
+ //Test a menual user
35
33
exports . leet = ( req , res ) => {
36
34
fetch ( 'https://leetcode.com/graphql' , {
37
35
method : 'POST' ,
38
36
headers : {
39
37
'Content-Type' : 'application/json' ,
40
38
'Referer' : 'https://leetcode.com'
41
39
} ,
42
- body : JSON . stringify ( { query : query , variables : variables } ) ,
40
+ body : JSON . stringify ( { query : query , variables : { username : "faisalshohagprog" } } ) ,
43
41
44
42
} )
45
43
. then ( result => result . json ( ) )
46
44
. then ( data => {
47
- res . send ( formatData ( data . data ) ) ;
45
+ if ( data . errors ) {
46
+ res . send ( data ) ;
47
+ } else {
48
+ if ( data . errors ) {
49
+ res . send ( data ) ;
50
+ } else {
51
+ res . send ( formatData ( data . data ) ) ;
52
+ }
53
+ }
48
54
} )
49
55
. catch ( err => {
50
56
console . error ( 'Error' , err ) ;
51
57
52
58
} ) ;
53
59
}
54
60
61
+ // format data
55
62
const formatData = ( data ) => {
56
63
let sendData = {
57
64
totalSolved : data . matchedUser . submitStats . acSubmissionNum [ 0 ] . count ,
@@ -71,6 +78,7 @@ const formatData = (data) => {
71
78
return sendData ;
72
79
}
73
80
81
+ //fetching the data
74
82
exports . leetcode = ( req , res ) => {
75
83
let user = req . params . id ;
76
84
fetch ( 'https://leetcode.com/graphql' , {
0 commit comments