// gameData.jsx const getQuizData = async (token, gId) => { const request = { method: 'GET', headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${token}`, }, } const response = await fetch(`http://localhost:5005/admin/quiz/${gId}`, request) const data = await response.json(); console.log(data) return data; } const getPoints = async (token, gId) => { const request = { method: 'GET', headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${token}`, }, } const response = await fetch(`http://localhost:5005/admin/quiz/${gId}`, request) const data = await response.json(); console.log(data) const pointsArray = Array(data.questions.length).fill(0); let i = 0 data.questions.map(question => { console.log(question.points) pointsArray[i] = parseInt(question.points) i++ return data }) return pointsArray; } const getQuestionData = async (token, gId, questionId) => { const request = { method: 'GET', headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${token}`, }, } const response = await fetch(`http://localhost:5005/admin/quiz/${gId}`, request) const data = await response.json(); const questions = data.questions console.log(questions) const newArray = questions.filter((item) => { console.log(item.qId) return Math.abs(item.qId - questionId) === 0 }) console.log(newArray) return newArray } const startSession = async (token, quizId) => { const request = { method: 'POST', headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${token}`, }, } const response = await fetch('http://localhost:5005/admin/quiz/' + quizId + '/start', request) if (response.status === 400) { console.log(await response.text()); // add text that quiz is active + sessionID } return response } const stopSession = async (token, quizId) => { const request = { method: 'POST', headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${token}`, }, } const response = await fetch('http://localhost:5005/admin/quiz/' + quizId + '/end', request) if (response.status === 400) { console.log(await response.text()); // add text that quiz is active + sessionID } return response } const advanceSession = async (token, quizId) => { const request = { method: 'POST', headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${token}`, }, } const response = await fetch('http://localhost:5005/admin/quiz/' + quizId + '/advance', request) if (response.status === 400) { console.log(await response.text()); // add text that quiz is active + sessionID } return response } const getSessionStatus = async (token, sessionId) => { const request = { method: 'GET', headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${token}`, }, } const response = await fetch('http://localhost:5005/admin/session/' + sessionId + '/status', request) const data = await response.json(); console.log(data) return data; } const getQuizAdminResult = async (token, sessionId) => { const request = { method: 'GET', headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${token}`, }, } const response = await fetch('http://localhost:5005/admin/session/' + sessionId + '/results', request) if (response.status === 400) { console.log(await response.text()); } const data = await response.json(); console.log(data) return data } export default { getQuizData, getQuestionData, startSession, stopSession, getPoints, advanceSession, getSessionStatus, getQuizAdminResult }