Bug fix
This commit is contained in:
@@ -6,10 +6,10 @@ const validationRules = {
|
||||
option: [validasaur.required, validasaur.minLength(1)],
|
||||
};
|
||||
|
||||
const addAnswer = async ({ request, response, params, state, render }) => {
|
||||
const addAnswer = async ({ request, response, params, context, render }) => {
|
||||
const topicId = params.tId;
|
||||
const questionId = params.qId;
|
||||
const userId = (await state.session.get("user")).id;
|
||||
const userId = (await context.state.session.get("user")).id;
|
||||
const body = request.body({ type: "form" });
|
||||
const formData = await body.value;
|
||||
const answerData = {
|
||||
|
||||
@@ -36,7 +36,7 @@ const register = async ({ request, response, render }) => {
|
||||
}
|
||||
};
|
||||
|
||||
const login = async ({ request, response, state, render }) => {
|
||||
const login = async ({ request, response, context, render }) => {
|
||||
const body = request.body({ type: "form" });
|
||||
const params = await body.value;
|
||||
const userDatabase = await authService.findUser(params.get("email"));
|
||||
@@ -58,7 +58,7 @@ const login = async ({ request, response, state, render }) => {
|
||||
return;
|
||||
}
|
||||
|
||||
await state.session.set("user", user);
|
||||
await context.state.session.set("user", user);
|
||||
response.redirect("/topics");
|
||||
};
|
||||
|
||||
|
||||
@@ -2,15 +2,15 @@ import { countTopics } from "../../services/topicService.js";
|
||||
import { countQuestions } from "../../services/questionService.js";
|
||||
import { countAnswers } from "../../services/answerService.js";
|
||||
|
||||
const showMain = ({ render }) => {
|
||||
const showMain = async ({ render }) => {
|
||||
const statistics = {
|
||||
totalTopics: 0,
|
||||
totalQuestions: 0,
|
||||
totalAnswers: 0,
|
||||
totalTopics: "0",
|
||||
totalQuestions: "0",
|
||||
totalAnswers: "0",
|
||||
};
|
||||
statistics.totalTopics = countTopics();
|
||||
statistics.totalQuestions = countQuestions();
|
||||
statistics.totalAnswers = countAnswers();
|
||||
statistics.totalTopics = await countTopics();
|
||||
statistics.totalQuestions = await countQuestions();
|
||||
statistics.totalAnswers = await countAnswers();
|
||||
|
||||
render("main.eta", statistics);
|
||||
};
|
||||
|
||||
@@ -7,16 +7,16 @@ const validationRules = {
|
||||
question: [validasaur.required, validasaur.minLength(1)],
|
||||
};
|
||||
|
||||
const addQuestion = async ({ request, response, params, state, render }) => {
|
||||
const addQuestion = async ({ request, response, params, context, render }) => {
|
||||
const topicId = params.tId;
|
||||
const userId = (await state.session.get("user")).id;
|
||||
const userId = (await context.state.session.get("user")).id;
|
||||
const body = request.body({ type: "form" });
|
||||
const formData = await body.value;
|
||||
const topicName = (await topicService.getTopicByTopicId(topicId)).name;
|
||||
const questionData = {
|
||||
topicId: topicId,
|
||||
topicName: topicName,
|
||||
question: formData.get("question_text"),
|
||||
question: formData.get("question"),
|
||||
};
|
||||
const [passes, errors] = await validasaur.validate(
|
||||
questionData,
|
||||
@@ -93,11 +93,11 @@ const listQuizTopics = async ({ render }) => {
|
||||
});
|
||||
};
|
||||
|
||||
const storeAnswer = async ({ response, params, state }) => {
|
||||
const storeAnswer = async ({ response, params, context }) => {
|
||||
const topicId = params.tId;
|
||||
const questionId = params.qId;
|
||||
const optionId = params.oId;
|
||||
const userId = (await state.session.get("user")).id;
|
||||
const userId = (await context.state.session.get("user")).id;
|
||||
const correctOptionIds = await answerService.getCorrectOptionIds(questionId);
|
||||
const correct = correctOptionIds.includes(Number(optionId));
|
||||
await answerService.storeAnswer(userId, questionId, optionId);
|
||||
|
||||
@@ -5,9 +5,9 @@ const validationRules = {
|
||||
name: [validasaur.required, validasaur.minLength(1)],
|
||||
};
|
||||
|
||||
const addTopic = async ({ request, response, render, state }) => {
|
||||
const userId = (await state.session.get("user")).id;
|
||||
const admin = (await state.session.get("user")).admin;
|
||||
const addTopic = async ({ request, response, render, context }) => {
|
||||
const userId = (await context.state.session.get("user")).id;
|
||||
const admin = (await context.state.session.get("user")).admin;
|
||||
const body = request.body({ type: "form" });
|
||||
const params = await body.value;
|
||||
const topicData = {
|
||||
@@ -33,17 +33,17 @@ const addTopic = async ({ request, response, render, state }) => {
|
||||
}
|
||||
};
|
||||
|
||||
const deleteTopic = async ({ params, response, state }) => {
|
||||
const deleteTopic = async ({ params, response, context }) => {
|
||||
const topicId = params.tId;
|
||||
const admin = (await state.session.get("user")).admin;
|
||||
const admin = (await context.state.session.get("user")).admin;
|
||||
if (admin) {
|
||||
await topicService.deleteTopic(topicId);
|
||||
}
|
||||
response.redirect("/topics");
|
||||
};
|
||||
|
||||
const listTopics = async ({ render, state }) => {
|
||||
const user = await state.session.get("user");
|
||||
const listTopics = async ({ render, context }) => {
|
||||
const user = await context.state.session.get("user");
|
||||
render("topics.eta", {
|
||||
admin: user.admin,
|
||||
topics: await topicService.getAllTopics(),
|
||||
|
||||
Reference in New Issue
Block a user