Clean up, add API

This commit is contained in:
AndrewTrieu
2023-03-10 12:43:41 +02:00
parent 4f94f70a9b
commit 7a76d625e2
10 changed files with 73 additions and 7 deletions

View File

@@ -32,6 +32,14 @@ const getRandQuestion = async (topicId) => {
return result.rows[0];
};
const getRandQuestionAPI = async () => {
const result = await sql`SELECT * FROM questions ORDER BY RANDOM() LIMIT 1`;
if (result.rows.length === 0) {
return null;
}
return result.rows[0];
};
export {
countQuestions,
getQuestionsByTopicId,
@@ -39,4 +47,5 @@ export {
addQuestion,
deleteQuestion,
getRandQuestion,
getRandQuestionAPI,
};