diff --git a/backend/src/routes/routes.ts b/backend/src/routes/routes.ts index c43e972..ed14369 100644 --- a/backend/src/routes/routes.ts +++ b/backend/src/routes/routes.ts @@ -21,7 +21,6 @@ import { getUserRole, postUser } from './users'; import { EVAN, healthCheck } from './health'; -import { setupData } from './sketch'; import { getRecentChanges } from './recentChanges'; import multer from 'multer'; @@ -46,8 +45,6 @@ router.put('/questions/:questionId/edit', multer().single('questionPNG'), e // Edits a comment router.put('/comments/:commentId/edit', multer().single('commentPNG'), editComments); -router.get('/recent_changes', getRecentChanges); - /* * Patches * ======= @@ -105,6 +102,9 @@ router.post('/courses', postCourse); * */ +// Gets recent changes +router.get('/recent_changes', getRecentChanges); + // Gets a user's role router.get('/users/:userId/role', getUserRole); @@ -139,6 +139,3 @@ router.get('/health', healthCheck); // Evan's Routes router.get('/Evan', EVAN); - -// The sketch route -router.get('/sketch', setupData); diff --git a/backend/src/routes/sketch.ts b/backend/src/routes/sketch.ts deleted file mode 100644 index 73e67bc..0000000 --- a/backend/src/routes/sketch.ts +++ /dev/null @@ -1,322 +0,0 @@ -// Imports -import { Request, Response } from 'express'; // Import Request and Response types -import { getConnection } from '../db'; -import { User as UserDb } from '../db/User'; -import { Course as CourseDb } from '../db/Course'; -import { Exam as ExamDb } from '../db/Exam'; -import { Question as QuestionDb } from '../db/Questions'; -import { Comment as CommentDb } from '../db/Comments'; - -export async function setupData(req: Request, res: Response) { - const db = getConnection(); - - const user = db.getRepository(UserDb); - - const checkData = await user.find(); - - if (checkData.length > 0) { - res.status(400).json('Data already exists'); - return; - } - - const course = db.getRepository(CourseDb); - const exam = db.getRepository(ExamDb); - const question = db.getRepository(QuestionDb); - const comment = db.getRepository(CommentDb); - - // Makes a bunch of users - const users = ['Evan', 'Liv', 'Lakshan', 'Jackson', 'Tristan', 'Pramith', 'Ibrahim']; - - for (const u of users) { - const newUser = new UserDb(); - newUser.userId = u; - await user.save(newUser); - } - - - // Makes a bunch of courses - const courses = [ - { - courseCode: 'ENGG1001', - courseName: 'Programming for Engineers', - courseDescription: 'An introductory course covering basic concepts of software engineering.', - university: 'UQ', - }, - { - courseCode: 'MATH1051', - courseName: 'Calculus & Linear Algebra', - courseDescription: 'A foundational course in calculus covering limits, derivatives, and integrals.', - university: 'UQ', - }, - { - courseCode: 'ENGG1100', - courseName: 'Professional Engineering', - courseDescription: 'An introductory course covering fundamental concepts in engineering principles.', - university: 'UQ', - }, - ]; - - for (const c of courses) { - const newCourse = new CourseDb(); - newCourse.courseCode = c.courseCode; - newCourse.courseName = c.courseName; - newCourse.courseDescription = c.courseDescription; - newCourse.university = c.university; - await course.save(newCourse); - } - - // Makes a bunch of exams - const exams = [ - { - courseCode: 'ENGG1001', - examYear: 2021, - examSemester: 1, - examType: 'Final', - }, - { - courseCode: 'ENGG1001', - examYear: 2022, - examSemester: 1, - examType: 'Final', - }, - { - courseCode: 'ENGG1001', - examYear: 2023, - examSemester: 1, - examType: 'Final', - }, - { - courseCode: 'MATH1051', - examYear: 2021, - examSemester: 1, - examType: 'Midterm', - }, - { - courseCode: 'MATH1051', - examYear: 2021, - examSemester: 1, - examType: 'Final', - }, - { - courseCode: 'MATH1051', - examYear: 2021, - examSemester: 2, - examType: 'Midterm', - }, - { - courseCode: 'MATH1051', - examYear: 2021, - examSemester: 2, - examType: 'Final', - }, - { - courseCode: 'MATH1051', - examYear: 2021, - examSemester: 3, - examType: 'Midterm', - }, - { - courseCode: 'MATH1051', - examYear: 2021, - examSemester: 3, - examType: 'Final', - }, - { - courseCode: 'MATH1051', - examYear: 2022, - examSemester: 1, - examType: 'Midterm', - }, - { - courseCode: 'MATH1051', - examYear: 2022, - examSemester: 1, - examType: 'Final', - }, - { - courseCode: 'MATH1051', - examYear: 2022, - examSemester: 2, - examType: 'Midterm', - }, - { - courseCode: 'MATH1051', - examYear: 2022, - examSemester: 2, - examType: 'Final', - }, - { - courseCode: 'MATH1051', - examYear: 2022, - examSemester: 3, - examType: 'Midterm', - }, - { - courseCode: 'MATH1051', - examYear: 2022, - examSemester: 3, - examType: 'Final', - }, - { - courseCode: 'MATH1051', - examYear: 2023, - examSemester: 1, - examType: 'Midterm', - }, - { - courseCode: 'MATH1051', - examYear: 2023, - examSemester: 1, - examType: 'Final', - }, - { - courseCode: 'MATH1051', - examYear: 2023, - examSemester: 2, - examType: 'Midterm', - }, - { - courseCode: 'MATH1051', - examYear: 2023, - examSemester: 2, - examType: 'Final', - }, - { - courseCode: 'MATH1051', - examYear: 2023, - examSemester: 3, - examType: 'Midterm', - }, - { - courseCode: 'MATH1051', - examYear: 2023, - examSemester: 3, - examType: 'Final', - }, - ]; - - for (const e of exams) { - const newExam = new ExamDb(); - newExam.courseCode = e.courseCode; - newExam.examYear = e.examYear; - newExam.examSemester = e.examSemester; - newExam.examType = e.examType; - await exam.save(newExam); - } - - // Makes a bunch of questions - const questions = [ - { - examId: 1, - questionText: 'Who is the best tutor at UQ?', - questionType: 'Multiple Choice', - }, - { - examId: 2, - questionText: 'Who is not the best tutor at UQ?', - questionType: 'Multiple Choice', - }, - { - examId: 3, - questionText: 'Who is the second best tutor at UQ?', - questionType: 'Multiple Choice', - }, - ]; - - for (const q of questions) { - const newQuestion = new QuestionDb(); - newQuestion.examId = q.examId; - newQuestion.questionText = q.questionText; - newQuestion.questionType = q.questionType; - await question.save(newQuestion); - } - - // Makes a bunch of comments - const comments = [ - { - questionId: 1, - parentCommentId: null, - userId: 'Evan', - commentText: 'Evan Hughes', - }, - { - questionId: 1, - parentCommentId: 1, - userId: 'Liv', - commentText: 'Are you stupid it is clearly Liv Ronda', - }, - { - questionId: 1, - parentCommentId: 2, - userId: 'Jackson', - commentText: 'Bro went to stupid school L', - }, - { - questionId: 1, - parentCommentId: 1, - userId: 'Lakshan', - commentText: 'Fax what a goat', - }, - { - questionId: 2, - parentCommentId: null, - userId: 'Evan', - commentText: 'Not Evan Hughes cause he is the best', - }, - { - questionId: 2, - parentCommentId: 5, - userId: 'Liv', - commentText: 'Facts it is clearly Liv Ronda because she is the worst', - }, - { - questionId: 2, - parentCommentId: 6, - userId: 'Jackson', - commentText: 'ong', - }, - { - questionId: 2, - parentCommentId: 5, - userId: 'Lakshan', - commentText: 'Fax what a goat', - }, - { - questionId: 3, - parentCommentId: null, - userId: 'Evan', - commentText: 'Not Evan Hughes cause he is the best', - }, - { - questionId: 3, - parentCommentId: 9, - userId: 'Evan', - commentText: 'TRUEEE!!!', - }, - { - questionId: 3, - parentCommentId: 10, - userId: 'Evan', - commentText: 'ong', - }, - { - questionId: 3, - parentCommentId: 9, - userId: 'Evan', - commentText: 'Fax what a goat', - }, - ]; - - for (const c of comments) { - const newComment = new CommentDb(); - newComment.questionId = c.questionId; - if (c.parentCommentId) { - newComment.parentCommentId = c.parentCommentId; - } - newComment.userId = c.userId; - newComment.commentText = c.commentText; - await comment.save(newComment); - } - - res.status(200).json(`THIS SHIT SKETCH ASF AND WAS LIV'S IDEA!!!\n`); -} diff --git a/docs/DATABASE.md b/docs/DATABASE.md index 9aebfaf..12b2390 100644 --- a/docs/DATABASE.md +++ b/docs/DATABASE.md @@ -1,26 +1,70 @@ -# TODO - -# Courses -| Name | Type | Description | other | -|----|----|----|----| -| courseCode | VARCHAR(8) | The Course Code for a course i.e. CSSE6400 | key | -| courseName | meow | The name of the course i.e. Software Architecture | None | -| courseDescription | meow | A description for the course | None | - -# Exams -| Name | Type | Description | other | -|----|----|----|----| -| coursecode | VARCHAR(8) | The Course Code for a course i.e. CSSE6400 | reference to courses table | -| examId | Serial | Just the id for the database | key | - -# Questions -| Name | Type | Description | other | -|----|----|----|----| -| examId | Serial | Just the id for the exams database | reference to the exams table | -| questionId | Serial | Just the id for the database | key | - -# Comments -| Name | Type | Description | other | -|----|----|----|----| -| questionId | Serial | Just the id for the questions database | reference to the questions table | -| commentId | Serial | Just the id for the database | key | +# Overview +The backend uses TypeORM to handle setting up the database. This document provides an overview of the database schema setup by TypeORM. +`mockData.sql` contains some mock data used to populate the database for testing and demo purposes. + +## User +This table keeps track of users registered with the system and how they have interacted with other objects. + +| Name | Type | Description | Other | +|-----------|----------|------------------------------------------------------------------------------------------------------------------------------------------------|-------------| +| userId | string | The user's id. Generated by Auth0 and is unique for each user in the Auth0 tenant. | Primary Key | +| role | number | The user's role. 0 is a regular user and 1 is an admin. | | +| picture | string | A url to the user's profile picture. Taken from Auth0 the first time a user logs in. | | +| rated | json | A json blob containing a list of course ratings done by the user, where the rating has the format
`{ courseCode: string, stars: number }`. | | +| upvoted | number[] | A list of comment ids upvoted by the user. | | +| downvoted | number[] | A list of comment ids downvoted by the user. | | + + +## Course +This table keeps track of the courses available in the system. + +| Name | Type | Description | Other | +|-------------------|--------|----------------------------------------------------|-------------| +| courseCode | string | The shortened code for a course i.e. CSSE6400. | Primary Key | +| courseName | string | The name of the course i.e. Software Architecture. | | +| courseDescription | string | A description for the course. | | +| university | string | The university that runs the course. | | +| stars | number | The current rating of the course. | | +| votes | number | The number of ratings a course has received. | | + +## Exam +This table keeps track of the exams available in the system. + +| Name | Type | Description | Other | +|--------------|--------|-------------------------------------------------------------------------------------------------|-------------------------------| +| courseCode | string | The course code of the course the exam belongs to. | Foreign Key course.courseCode | +| examId | number | A unique id for the exam. | Primary Key | +| examYear | number | The year the exam was available. | | +| examSemester | number | The semester the exam was available. 1 is semester 1, 2 is semester 2 and 3 is summer semester. | | +| examType | string | The type of exam i.e. Final, Midsem, Quiz, etc. | | + +## Question +This table keeps track of the questions available in the system. + +| Name | Type | Description | Other | +|--------------|-----------|---------------------------------------------------------------|-------------------------| +| examId | number | The exam id of the exam the question belongs to. | Foreign Key exam.examId | +| questionId | number | A unique id for the question. | Primary Key | +| questionText | string | The question's textual content. | | +| questionPNG | string | The url to an image uploaded to accompany the question. | | +| questionType | string | The type of question i.e. Short Answer, Multiple Choice, etc. | | +| createdAt | timestamp | When the question was created in the system. | | +| updatedAt | timestamp | When the question was updated in the system. | | + +## Comment +This table keeps track of the comments available in the system. + +| Name | Type | Description | Other | +|-----------------|-----------|---------------------------------------------------------|---------------------------------| +| questionId | number | The question id of the question the comment belongs to. | Foreign Key question.questionId | +| userId | string | The user id of the user who made the comment. | Foreign Key user.userId | +| commentId | number | A unique id for the comment. | Primary Key | +| parentCommentId | number | The comment id of the parent, if any. | | +| commentText | string | The comment's textual content. | | +| commentPNG | string | The url to an image uploaded to accompany the comment. | | +| isCorrect | boolean | Whether the question has been verified by course staff. | | +| isDeleted | boolean | Whether the comment has been deleted. | | +| upvotes | number | The number of upvotes the comment has. | | +| downvotes | number | The number of downvotes the comment has. | | +| createdAt | timestamp | When the comment was created in the system. | | +| updatedAt | timestamp | When the comment was updated in the system. | |