Major bug fix

This commit is contained in:
AndrewTrieu
2023-03-10 16:41:57 +02:00
parent 4c8e7e8588
commit 0fab2411ee
19 changed files with 965 additions and 19 deletions

View File

@@ -14,7 +14,7 @@ const showRegister = ({ render }) => {
render("register.eta");
};
const createUser = async ({ request, response, render }) => {
const register = async ({ request, response, render }) => {
const body = request.body({ type: "form-data" });
const params = await body.value;
const userData = {
@@ -62,4 +62,4 @@ const login = async ({ request, response, state, render }) => {
response.direct("/topics");
};
export { showLogin, showRegister, createUser, login };
export { showLogin, showRegister, register, login };

View File

@@ -12,15 +12,16 @@ const addQuestion = async ({ request, response, params, state, render }) => {
const userId = (await state.session.get("user")).id;
const body = request.body({ type: "form-data" });
const formData = await body.value;
const topicName = (await topicService.getTopicByTopicId(topicId)).name;
const questionData = {
topicId: topicId,
topicName: topicName,
question: formData.get("question_text"),
};
const [passes, errors] = await validasaur.validate(
questionData,
validationRules
);
if (!passes) {
response.status = 422;
questionData.errors = errors;
@@ -36,17 +37,21 @@ const addQuestion = async ({ request, response, params, state, render }) => {
const listQuestions = async ({ params, render }) => {
const topicId = params.tId;
const topicName = (await topicService.getTopicByTopicId(topicId)).name;
render("questions.eta", {
topicId: topicId,
topicName: topicName,
currentQuestions: await questionService.getQuestionsByTopicId(topicId),
});
};
const showQuestion = async ({ params, render }) => {
const questionId = params.qId;
const questionData = await questionService.getQuestionById(questionId);
questionData.answers = await answerService.getAnswersByQuestionId(questionId);
questionData.topicId = params.id;
const questionData = await questionService.getQuestionByQuestionId(
questionId
);
questionData.details = await answerService.getAnswersByQuestionId(questionId);
questionData.topicId = params.tId;
render("question.eta", questionData);
};
@@ -60,7 +65,9 @@ const deleteQuestion = async ({ params, response }) => {
const listQuiz = async ({ params, render }) => {
const topicId = params.tId;
const questionId = params.qId;
const questionData = await questionService.getQuestionById(questionId);
const questionData = await questionService.getQuestionByQuestionId(
questionId
);
const quizData = {
topicId: topicId,
questionId: questionId,
@@ -81,8 +88,8 @@ const getRandQuestion = async ({ params, response }) => {
};
const listQuizTopics = async ({ render }) => {
render("quizTopic.eta", {
allTopics: await topicService.getAllTopics(),
render("quizTopics.eta", {
topics: await topicService.getAllTopics(),
});
};

View File

@@ -25,7 +25,7 @@ const addTopic = async ({ request, response, render, state }) => {
if (!admin) {
topicData.errors = { admin: { error: "You are not an admin!" } };
}
topicData.allTopics = await topicService.getAllTopics();
topicData.topics = await topicService.getAllTopics();
render("topics.eta", topicData);
} else {
await topicService.addTopic(userId, topicData.name);