Skip to content

Commit

Permalink
Fixes (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanlyrl authored Jan 27, 2021
1 parent afdceb0 commit 22cf032
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/controllers/ravensQuestController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,18 @@ export const switchTracks = async (req: Request, res: Response): Promise<void> =
};

export const refreshQuestionsAndAnswers = async (req: Request, res: Response): Promise<void> => {
if(req.body) {
console.log('Using questions provided in request body...');
questionsAndAnswers = req.body;
res.sendStatus(200);
} else {
if (req.body.constructor === Object && Object.keys(req.body).length === 0) {
console.log('Attempting to load questions from file...');
const result = await loadQuestionsAndAnswers();
if(result) {
res.sendStatus(200);
} else {
res.sendStatus(500);
}
} else {
console.log('Using questions provided in request body...');
questionsAndAnswers = req.body;
res.sendStatus(200);
}
};

Expand Down Expand Up @@ -137,12 +137,20 @@ export const submitAnswer = async (req: Request, res: Response): Promise<void> =
user.ravensQuestProgress[`track1Progress`] == NUM_QUESTIONS &&
user.ravensQuestProgress[`track2Progress`] == NUM_QUESTIONS;

let nextQuestion;
if(currentQuestion + 1 == NUM_QUESTIONS) {
nextQuestion = null;
} else {
nextQuestion = questionsAndAnswers[currentTrack][currentQuestion + 1]?.question;
}

res.status(200).send({
track: currentTrack,
progress: user.ravensQuestProgress[`track${currentTrack}Progress`] == NUM_QUESTIONS ? "completed" : user.ravensQuestProgress[`track${currentTrack}Progress`],
snowmanUrl: questionsAndAnswers[currentTrack][currentQuestion]?.snowmanUrl,
snowmanName: questionsAndAnswers[currentTrack][currentQuestion]?.snowmanName,
allComplete: allComplete
allComplete: allComplete,
nextQuestion: nextQuestion
});

} else {
Expand Down

0 comments on commit 22cf032

Please sign in to comment.