Add lots of things
This commit is contained in:
0
drill-and-practice/services/answerService.js
Normal file
0
drill-and-practice/services/answerService.js
Normal file
11
drill-and-practice/services/authService.js
Normal file
11
drill-and-practice/services/authService.js
Normal file
@@ -0,0 +1,11 @@
|
||||
import { sql } from "../database/database.js";
|
||||
|
||||
const findUser = async (email) => {
|
||||
return await sql`SELECT * FROM users WHERE email = ${email}`;
|
||||
};
|
||||
|
||||
const createUser = async (email, password) => {
|
||||
return await sql`INSERT INTO users (email, password) VALUES (${email}, ${password})`;
|
||||
};
|
||||
|
||||
export { findUser, createUser };
|
||||
8
drill-and-practice/services/questionService.js
Normal file
8
drill-and-practice/services/questionService.js
Normal file
@@ -0,0 +1,8 @@
|
||||
import { sql } from "../database/database.js";
|
||||
|
||||
const countQuestions = async () => {
|
||||
const result = await sql`SELECT COUNT(id) FROM questions`;
|
||||
return result.rows[0].count;
|
||||
};
|
||||
|
||||
const getQuestionsByTopicId = async (topicId) => {
|
||||
39
drill-and-practice/services/topicService.js
Normal file
39
drill-and-practice/services/topicService.js
Normal file
@@ -0,0 +1,39 @@
|
||||
import { sql } from "../database/database.js";
|
||||
|
||||
const addTopic = async (userId, name) => {
|
||||
await sql`INSERT INTO topics (user_id, name) VALUES (${userId}, ${name})`;
|
||||
};
|
||||
|
||||
const countTopics = async () => {
|
||||
const result = await sql`SELECT COUNT(id) FROM topics`;
|
||||
return result.rows[0].count;
|
||||
};
|
||||
|
||||
const getAllTopics = async () => {
|
||||
await sql`SELECT * FROM topics ORDER BY name ASC`;
|
||||
return result.rows;
|
||||
};
|
||||
|
||||
const getTopicsByUserId = async (userId) => {
|
||||
const result =
|
||||
await sql`SELECT * FROM topics WHERE user_id = ${userId} ORDER BY name ASC`;
|
||||
return result.rows;
|
||||
};
|
||||
|
||||
const getTopicByTopicId = async (topicId) => {
|
||||
const result = await sql`SELECT * FROM topics WHERE id = ${topicId}`;
|
||||
return result.rows[0];
|
||||
};
|
||||
|
||||
const deleteTopic = async (topicId) => {
|
||||
await sql`DELETE FROM topics WHERE id = ${topicId}`;
|
||||
};
|
||||
|
||||
export {
|
||||
addTopic,
|
||||
countTopics,
|
||||
getAllTopics,
|
||||
getTopicsByUserId,
|
||||
getTopicByTopicId,
|
||||
deleteTopic,
|
||||
};
|
||||
Reference in New Issue
Block a user