Skip to content

Commit ef3feb6

Browse files
committed
Added findAllMinimalProgress
1 parent 7492352 commit ef3feb6

2 files changed

Lines changed: 57 additions & 5 deletions

File tree

src/lib/api/puzzleServices.spec.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import anyTest, { TestInterface } from 'ava'
22

3-
import { findProgressByIds } from "./puzzleServices"
3+
import {
4+
findProgressByIds,
5+
findAllMinimalProgress
6+
} from "./puzzleServices"
47

58
const test = anyTest as TestInterface<{}>
69

@@ -12,4 +15,14 @@ test("Retrieving infos from several puzzles", async t => {
1215
} catch (e){
1316
console.log(e)
1417
}
15-
})
18+
})
19+
20+
test("Retrieving all minimal puzzle progress", async t => {
21+
try {
22+
const puzzlesProgress = await findAllMinimalProgress(4365603)
23+
24+
t.assert(puzzlesProgress[0] !== null)
25+
} catch (e){
26+
console.log(e)
27+
}
28+
})

src/lib/api/puzzleServices.ts

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import axios from "axios"
22

3-
import { urls } from "../main"
3+
import { getCookies, urls } from "../main"
44

55
/**
6-
* Find puzzle informations and player's completion from an array
6+
* Find puzzle informations and player's completion from an array of number IDs.
77
*
88
* @param {number[]} ids - Every Puzzle IDs you want to inspect
9-
* @param {number} userId - The user ID you want to retrieve the completion
9+
* @param {number} userId - User ID you want to retrieve the completion
1010
*
1111
*/
1212

@@ -24,6 +24,33 @@ export const findProgressByIds = async (ids: number[], userId: number): Promise<
2424
return response["data"]
2525
}
2626

27+
28+
/**
29+
* Find every minimal puzzle progress from a user. You can also use this to get every puzzles of CodinGame
30+
*
31+
* @param {number} userId - User ID you want to retrieve the completion
32+
*
33+
*/
34+
35+
export const findAllMinimalProgress = async (userId: number): Promise<IPuzzleMinimalProgress[]> => {
36+
37+
const cookies: string = getCookies()
38+
39+
const response = await axios({
40+
url: urls.puzzle + "findAllMinimalProgress",
41+
method: "post",
42+
headers: {
43+
"content-type": "application/json;charset=UTF-8",
44+
"cookie": cookies
45+
},
46+
data: [ userId ]
47+
})
48+
49+
return response["data"]
50+
}
51+
52+
53+
2754
export interface IPuzzleProgress {
2855
id: number
2956
level: string
@@ -62,4 +89,16 @@ type topics = {
6289
category: string
6390
value: string
6491
children: topics[] | []
92+
}
93+
94+
export interface IPuzzleMinimalProgress {
95+
id: number
96+
level: string
97+
validatorScore: number
98+
submitted: boolean
99+
creationTime: number
100+
rank: number
101+
solvedCount: number
102+
communityCreation: boolean
103+
feedback: feedbackPuzzle
65104
}

0 commit comments

Comments
 (0)