Skip to content

Commit

Permalink
[#6] answer history (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
kowalczp authored Mar 4, 2021
1 parent 71ff411 commit 2d96e60
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
21 changes: 21 additions & 0 deletions server/src/routes/Answer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import express, { Request, Response } from 'express';
import { Answer, validateAnswer } from '../models/Answer';
const router = express.Router();

router.post('/', async (req: Request, res: Response) => {
try {
const answer = new Answer({
flashcard: req.body.flashcardId,
date: req.body.Date,
isCorrect: req.body.isCorrect
});
const { error } = validateAnswer(req.body);
if (error) {
return res.status(400).send(error.details[0].message);
} else await answer.save();
res.status(201).send('Session data successfully saved');
res.send(answer);
} catch (error) {
res.status(500).send('Something went wrong').end();
}
});
22 changes: 22 additions & 0 deletions server/src/routes/AnswerHistory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import express, { Request, Response } from 'express';
import { AnswerHistory, validateAnswerHistory } from '../models/AnswerHistory';
const router = express.Router();

router.post('/', async (req: Request, res: Response) => {
try {
const answerHistory = new AnswerHistory({
user: req.body.user,
sessionDate: req.body.sessionDate,
flashcardCollection: req.body.flashcardCollection,
answers: req.body.answers
});
const { error } = validateAnswerHistory(req.body);
if (error) {
return res.status(400).send(error.details[0].message);
} else await answerHistory.save();
res.status(201).send('Session data successfully saved');
res.send(answerHistory);
} catch (error) {
res.status(500).send('Something went wrong').end();
}
});

0 comments on commit 2d96e60

Please sign in to comment.