Update auth, question, answer
This commit is contained in:
@@ -6,3 +6,37 @@ const countQuestions = async () => {
|
||||
};
|
||||
|
||||
const getQuestionsByTopicId = async (topicId) => {
|
||||
const result = await sql`SELECT * FROM questions WHERE topic_id = ${topicId}`;
|
||||
return result.rows;
|
||||
};
|
||||
|
||||
const getQuestionByQuestionId = async (questionId) => {
|
||||
const result = await sql`SELECT * FROM questions WHERE id = ${questionId}`;
|
||||
return result.rows[0];
|
||||
};
|
||||
|
||||
const addQuestion = async (userId, topicId, question) => {
|
||||
await sql`INSERT INTO questions (user_id, topic_id, question_text) VALUES (${userId}, ${topicId}, ${question})`;
|
||||
};
|
||||
|
||||
const deleteQuestion = async (questionId) => {
|
||||
await sql`DELETE FROM questions WHERE id = ${questionId}`;
|
||||
};
|
||||
|
||||
const getRandQuestion = async (topicId) => {
|
||||
const result =
|
||||
await sql`SELECT * FROM questions WHERE topic_id = ${topicId} ORDER BY RANDOM() LIMIT 1`;
|
||||
if (result.rows.length === 0) {
|
||||
return null;
|
||||
}
|
||||
return result.rows[0];
|
||||
};
|
||||
|
||||
export {
|
||||
countQuestions,
|
||||
getQuestionsByTopicId,
|
||||
getQuestionByQuestionId,
|
||||
addQuestion,
|
||||
deleteQuestion,
|
||||
getRandQuestion,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user