Skip to content

Commit 89afef4

Browse files
committed
Added findProgressByPrettyId
1 parent ef3feb6 commit 89afef4

3 files changed

Lines changed: 102 additions & 2 deletions

File tree

src/lib/api/puzzleServices.spec.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import anyTest, { TestInterface } from 'ava'
22

33
import {
44
findProgressByIds,
5-
findAllMinimalProgress
5+
findAllMinimalProgress,
6+
findProgressByPrettyId
67
} from "./puzzleServices"
78

89
const test = anyTest as TestInterface<{}>
@@ -17,6 +18,16 @@ test("Retrieving infos from several puzzles", async t => {
1718
}
1819
})
1920

21+
test("Retrieving infos from a puzzle from its pretty ID", async t => {
22+
try {
23+
const puzzlePrettyInfos = await findProgressByPrettyId("onboarding", 4365603)
24+
25+
t.assert(puzzlePrettyInfos.id === 43)
26+
} catch (e){
27+
console.log(e)
28+
}
29+
})
30+
2031
test("Retrieving all minimal puzzle progress", async t => {
2132
try {
2233
const puzzlesProgress = await findAllMinimalProgress(4365603)

src/lib/api/puzzleServices.ts

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,38 @@ export const findProgressByIds = async (ids: number[], userId: number): Promise<
2525
}
2626

2727

28+
/**
29+
* Find puzzle informations and player's completion from a "pretty ID" which is a string, found in the URL of the puzzle.
30+
*
31+
* ## Requires to log in before.
32+
*
33+
* @param {string} puzzlePrettyId - Puzzle's "pretty ID", found in its URL.
34+
* @param {number} userId - User ID you want to retrieve the completion
35+
*/
36+
37+
export const findProgressByPrettyId = async (puzzlePrettyId: string, userId: number): Promise<IPuzzlePrettyProgress> => {
38+
39+
const cookies: string = getCookies()
40+
41+
const response = await axios({
42+
url: urls.puzzle + "findProgressByPrettyId",
43+
method: "post",
44+
headers: {
45+
"content-type": "application/json;charset=UTF-8",
46+
"cookie": cookies
47+
},
48+
data: [ puzzlePrettyId, userId ]
49+
})
50+
51+
return response["data"]
52+
}
53+
54+
2855
/**
2956
* Find every minimal puzzle progress from a user. You can also use this to get every puzzles of CodinGame
3057
*
58+
* ## Requires to log in before.
59+
*
3160
* @param {number} userId - User ID you want to retrieve the completion
3261
*
3362
*/
@@ -91,6 +120,67 @@ type topics = {
91120
children: topics[] | []
92121
}
93122

123+
export interface IPuzzlePrettyProgress {
124+
id: number
125+
level: string
126+
rank: number
127+
thumbnailBinaryId: number
128+
previewBinaryId: number
129+
coverBinaryId: number
130+
logoBinaryId: number
131+
title: string
132+
titlemap: {
133+
"1": string,
134+
"2": string
135+
}
136+
description: string
137+
statement: string
138+
validatorScore: number
139+
achievementCount: number
140+
doneAchievementCount: number
141+
linkedAchievements: linkedAchievement[]
142+
forumLink: string
143+
solvedCount: number
144+
attemptCount: number
145+
xpPoints: number
146+
feedback: feedbackPuzzle
147+
topics: topics[]
148+
creationTime: number
149+
type: string
150+
prettyId: string
151+
detailsPageUrl: string
152+
replayIds: number[]
153+
contentDetails: puzzleDetails
154+
communityCreation: boolean
155+
}
156+
157+
type linkedAchievement = {
158+
id: string
159+
puzzleId: number
160+
title: string
161+
description: string
162+
points: number
163+
progress: number
164+
progressMax: number
165+
completionTime: number
166+
imageBinaryId: number
167+
level: string
168+
weight: number
169+
}
170+
171+
type puzzleDetails = {
172+
description: string
173+
learnDescription: string
174+
story: string
175+
externalResources: externalResource[]
176+
}
177+
178+
type externalResource = {
179+
publicId: string
180+
url: string
181+
name: string
182+
}
183+
94184
export interface IPuzzleMinimalProgress {
95185
id: number
96186
level: string

src/lib/main.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ export const setCookies = (response: any) => {
2929
export const getCookies = (): string => {
3030
try {
3131
const cookiesStr = fs.readFileSync("./src/config/cookies", "utf-8")
32-
console.log(cookiesStr)
3332
return cookiesStr
3433
} catch (e){
3534
console.log(e)

0 commit comments

Comments
 (0)