Skip to content

Commit 992be90

Browse files
authored
Add function to submit rating for challenge (#31)
* Add function to submit rating against /api/v1/challenges/[challenge_id]/ratings
1 parent 0db9b55 commit 992be90

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

main.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
displaySolution,
1616
displayHintUnlock,
1717
displaySolutionUnlock,
18+
submitRating,
1819
} from "./pages/challenge";
1920
import { getScoreboard, getScoreboardDetail, getBrackets } from "./pages/scoreboard";
2021
import { updateSettings, generateToken, deleteToken } from "./pages/settings";
@@ -143,6 +144,7 @@ const pages = {
143144
displayHint,
144145
loadSolution,
145146
displaySolution,
147+
submitRating,
146148
},
147149
challenges: {
148150
getChallenges,

pages/challenge.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,13 @@ export async function displaySolution(solutionId) {
163163
}
164164
}
165165
}
166+
167+
export async function submitRating(challengeId, rating, review) {
168+
const response = await CTFd.fetch(`/api/v1/challenges/${challengeId}/ratings`, {
169+
method: "PUT",
170+
body: JSON.stringify({ value: rating, review: review }),
171+
});
172+
173+
const body = await response.json();
174+
return body["data"];
175+
}

0 commit comments

Comments
 (0)