Skip to content

Commit

Permalink
reorganize api files
Browse files Browse the repository at this point in the history
  • Loading branch information
geoffrey-wu committed Jun 20, 2023
1 parent 2feaee0 commit 55c0b70
Show file tree
Hide file tree
Showing 15 changed files with 434 additions and 384 deletions.
4 changes: 2 additions & 2 deletions client/geoword/division.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const packetTitle = titleCase(packetName);

document.getElementById('packet-name').textContent = packetTitle;

fetch('/geoword/api/get-divisions?' + new URLSearchParams({ packetName }))
fetch('/api/geoword/get-divisions?' + new URLSearchParams({ packetName }))
.then(response => response.json())
.then(data => {
const { divisions } = data;
Expand All @@ -18,7 +18,7 @@ fetch('/geoword/api/get-divisions?' + new URLSearchParams({ packetName }))

document.getElementById('form').addEventListener('submit', async event => {
const division = document.getElementById('division').value;
fetch('/geoword/api/record-division', {
fetch('/api/geoword/record-division', {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
Expand Down
10 changes: 5 additions & 5 deletions client/geoword/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ let tossupsHeard = 0;

document.getElementById('geoword-stats').href = '/geoword/stats/' + packetName;

fetch('/geoword/api/get-question-count?' + new URLSearchParams({ packetName }))
fetch('/api/geoword/get-question-count?' + new URLSearchParams({ packetName }))
.then(response => response.json())
.then(data => {
packetLength = data.questionCount;
document.getElementById('packet-length').textContent = packetLength;
});

fetch('/geoword/api/get-progress?' + new URLSearchParams({ packetName }))
fetch('/api/geoword/get-progress?' + new URLSearchParams({ packetName }))
.then(response => response.json())
.then(data => {
({ division, numberCorrect, points, totalCorrectCelerity, tossupsHeard } = data);
Expand All @@ -48,7 +48,7 @@ const incorrectAudio = new Audio('/geoword/audio/incorrect.mp3');
const sampleAudio = new Audio('/geoword/audio/sample.mp3');

async function checkGeowordAnswer(givenAnswer, questionNumber) {
return await fetch('/geoword/api/check-answer?' + new URLSearchParams({
return await fetch('/api/geoword/check-answer?' + new URLSearchParams({
givenAnswer,
packetName,
questionNumber,
Expand Down Expand Up @@ -106,7 +106,7 @@ function next() {
}

function recordProtest(packetName, questionNumber) {
fetch('/geoword/api/record-protest?', {
fetch('/api/geoword/record-protest?', {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
Expand All @@ -123,7 +123,7 @@ function recordProtest(packetName, questionNumber) {
}

function recordBuzz(packetName, questionNumber, celerity, points, givenAnswer) {
fetch('/geoword/api/record-buzz?' + new URLSearchParams({
fetch('/api/geoword/record-buzz?' + new URLSearchParams({
packetName,
questionNumber,
celerity,
Expand Down
2 changes: 1 addition & 1 deletion client/geoword/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ getAccountUsername().then(username => {
}
});

fetch('/geoword/api/packet-list')
fetch('/api/geoword/packet-list')
.then(response => response.json())
.then(data => {
const { packetList } = data;
Expand Down
2 changes: 1 addition & 1 deletion client/geoword/leaderboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const packetTitle = titleCase(packetName);
document.getElementById('packet-name').textContent = packetTitle;
document.getElementById('division').textContent = division;

fetch('/geoword/api/leaderboard?' + new URLSearchParams({ packetName, division }))
fetch('/api/geoword/leaderboard?' + new URLSearchParams({ packetName, division }))
.then(response => response.json())
.then(data => {
const { leaderboard } = data;
Expand Down
4 changes: 2 additions & 2 deletions client/geoword/stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const packetTitle = titleCase(packetName);

document.getElementById('packet-name').textContent = packetTitle;

fetch('/geoword/api/stats?' + new URLSearchParams({ packetName }))
fetch('/api/geoword/stats?' + new URLSearchParams({ packetName }))
.then(response => response.json())
.then(data => {
const { buzzArray, division, leaderboard } = data;
Expand Down Expand Up @@ -46,7 +46,7 @@ fetch('/geoword/api/stats?' + new URLSearchParams({ packetName }))
});


fetch('/geoword/api/get-divisions?' + new URLSearchParams({ packetName }))
fetch('/api/geoword/get-divisions?' + new URLSearchParams({ packetName }))
.then(response => response.json())
.then(data => {
const { divisions } = data;
Expand Down
7 changes: 7 additions & 0 deletions database/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,12 @@ async function getUserId(username) {
}


async function isAdmin(username) {
const user = await getUser(username);
return user?.admin ?? false;
}


async function recordBonusData(username, data) {
const user_id = await getUserId(username);
const newData = {};
Expand Down Expand Up @@ -428,6 +434,7 @@ export {
getUsername,
getUserField,
getUserId,
isAdmin,
recordBonusData,
recordTossupData,
updateUser,
Expand Down
253 changes: 0 additions & 253 deletions routes/api.js

This file was deleted.

Loading

0 comments on commit 55c0b70

Please sign in to comment.