Skip to content

Latest commit

 

History

History
1238 lines (942 loc) · 19.9 KB

File metadata and controls

1238 lines (942 loc) · 19.9 KB

Getting Started for Development

# First, make sure you are in the `backend` directory
npm install

Create a new .env file within the backend directory

cp .env.example .env

Add the secrets to the .env file. You may be provided a .env file externally.

Start the development server

npm run watch

This will start the server and watch for changes to the TypeScript files. The server will automatically restart when changes are detected.

Entrypoint

The entrypoint for the server is src/app.ts. This file is responsible for setting up the server and routes.

Folder Structure

The folder structure is as follows:

.
├── src
│   ├── controllers
│   ├── db
│   ├── middleware
│   ├── routes
│   ├── services
│   ├── test
│   ├── utils
│   ├── app.ts
├── var
│   ├── db
│       ├── sessions.db
        ├── users.db
├── .env

What do these folders do?

Diagram

  • app.ts: The entrypoint for the server. This file sets up the server and routes. app.ts "uses" routes defined in the routes folder.
  • routes: This folder contains all the routes for the server (such as the endpoint "/endpoint" and whether it is a GET or POST request). The files in this folder "use" controllers defined in the controllers folder.
  • controllers: This folder contains the logic for the routes. The files in this folder "use" services defined in the services folder.
  • services: This folder contains the logic for the controllers. The files in this folder "use" the database defined in the db folder.
  • db: This folder contains the database logic.
  • utils: This folder contains utility functions used across the server.
  • middleware: (Not important) This folder contains middleware functions used across the server.

Api Docs

The API documentation is available at /api-docs endpoint. Also, the API documentation is available at Swagger UI.

CourseView Backend - OpenAPI 3.0

Version 1.0

Path Table

Method Path Description
GET /loggedIn Check if the user is logged in by checking if the connect.sid cookie is present and valid
POST /logout Log the user session out
POST /auth/one-tap/callback A callback endpoint for Google OAuth
POST /auth/basic/callback A callback endpoint for Basic Authentication
GET /getAccountDetails Gets the user related information to show in My Account
POST /saveAccountDetails Save the user related information shown in My Account
GET /arrConfigs Returns an of all available ARR configs
GET /subjects Returns an array of all subjects
GET /courses Returns an array of all courses for subjectId
GET /semesterStrings Returns an array of all semester strings objects
GET /gradeOptions Returns an array of all grade options
GET /userCourse Returns an array of user courses
POST /userCourse Add a user course
DELETE /userCourse Delete a user course
GET /userAssignment Returns an array of user course assignments
POST /userAssignment Add a user course assignment
PUT /userAssignment Put all user course assignments
DELETE /userAssignment Delete a user course assignment
PUT /userSelectedArrConfig Save the user selected ARR Configs
GET /userSelectedArrConfig Get the user selected ARR Configs

Reference Table

Name Path Description
UserSelectedArrConfigs #/components/schemas/UserSelectedArrConfigs
DegreeRequirementAssignment #/components/schemas/DegreeRequirementAssignment
UserCourse #/components/schemas/UserCourse
Subject #/components/schemas/Subject
Section #/components/schemas/Section
Subsection #/components/schemas/Subsection
FixedRequirement #/components/schemas/FixedRequirement
PrefixRequirement #/components/schemas/PrefixRequirement
AnonymousRequirement #/components/schemas/AnonymousRequirement
Course #/components/schemas/Course
Account #/components/schemas/Account
SuccessMessage #/components/schemas/SuccessMessage
FailureMessage #/components/schemas/FailureMessage
AuthSuccess #/components/schemas/AuthSuccess
AuthFailure #/components/schemas/AuthFailure
UserAuth #/components/schemas/UserAuth
cookieAuth #/components/securitySchemes/cookieAuth

Path Details


[GET]/loggedIn

  • Summary
    Check if the user is logged in by checking if the connect.sid cookie is present and valid

Responses

  • 200 Returns an object with a message as "sucesss" or "fail"

application/json

{
  "oneOf": [
    {
      "$ref": "#/components/schemas/AuthSuccess"
    },
    {
      "$ref": "#/components/schemas/AuthFailure"
    }
  ]
}

[POST]/logout

  • Summary
    Log the user session out

Responses

  • 200 success

application/json

{
  message?: string
}

[POST]/auth/one-tap/callback

  • Summary
    A callback endpoint for Google OAuth

RequestBody

  • application/json
{
  credential?: string
}

Responses

  • 200 The session ID is returned in a cookie named connect.sid. You need to include this cookie in subsequent requests.

application/json

{
  id?: string
  email?: string
  name?: string
}

[POST]/auth/basic/callback

  • Summary
    A callback endpoint for Basic Authentication

RequestBody

  • application/json
{
  credential?: string
}

Responses

  • 200 The session ID is returned in a cookie named connect.sid. You need to include this cookie in subsequent requests.

application/json

{
  id?: string
  email?: string
  name?: string
}

[GET]/getAccountDetails

  • Summary
    Gets the user related information to show in My Account

  • Security
    cookieAuth

Responses

  • 200 Account info

application/json

{
  email?: string
  majors?: string[]
  gradSem?: string
}
  • 401 Unauthorized

application/json

{
  message?: string
  error?: string
}

[POST]/saveAccountDetails

  • Summary
    Save the user related information shown in My Account

  • Security
    cookieAuth

RequestBody

  • application/json
{
  email?: string
  majors?: string[]
  gradSem?: string
}

Responses

  • 200 Saved successfully

application/json

{
  message?: string
}
  • 400 Bad Request

application/json

{
  message?: string
  error?: string
}
  • 401 Unauthorized

application/json

{
  message?: string
  error?: string
}

[GET]/arrConfigs

  • Summary
    Returns an of all available ARR configs

Responses

  • 200 An array of all available ARR configs

application/json

{
  id?: string
  title?: string
  description?: string
  subsections: {
    title?: string
    description?: string
    requirements?: #/components/schemas/FixedRequirement | #/components/schemas/PrefixRequirement | #/components/schemas/AnonymousRequirement[]
  }[]
}[]

[GET]/subjects

  • Summary
    Returns an array of all subjects

Responses

  • 200 array of all subjects

application/json

{
  id?: string
  short?: string
  long?: string
  title?: string
}[]

[GET]/courses

  • Summary
    Returns an array of all courses for subjectId

Parameters(Query)

subjectId: string

Responses

  • 200 Returns an array of all courses for subjectId

application/json

{
  id?: string
  subjectId?: string
  number?: string
  title?: string
  displayTitle?: string
  credits?: string
  titleLong?: string
  subjectLong?: string
  subjectShort?: string
  topic?: string
  description?: string
  hasTopics?: boolean
  corequisites?: string
  prerequisites?: string
  hasRestrictions?: boolean
}[]
  • 400 Bad Request

application/json

{
  message?: string
  error?: string
}

[GET]/semesterStrings

  • Summary
    Returns an array of all semester strings objects

Responses

  • 200 an array of all semester strings

application/json

{
  display?: string
  value?: string
}[]

[GET]/gradeOptions

  • Summary
    Returns an array of all grade options

Responses

  • 200 an array of grade options

application/json

string[]

[GET]/userCourse

  • Summary
    Returns an array of user courses

  • Security
    cookieAuth

Responses

  • 200 an array of user courses

application/json

{
  course: {
    id?: string
    subjectId?: string
    number?: string
    title?: string
    displayTitle?: string
    credits?: string
    titleLong?: string
    subjectLong?: string
    subjectShort?: string
    topic?: string
    description?: string
    hasTopics?: boolean
    corequisites?: string
    prerequisites?: string
    hasRestrictions?: boolean
  }
  semester?: string
  transferred?: boolean
  grade?: string
  professor?: string
  notes?: string
  creditsAwarded?: string
}[]
  • 401 Unauthorized

application/json

{
  message?: string
  error?: string
}

[POST]/userCourse

  • Summary
    Add a user course

  • Security
    cookieAuth

RequestBody

  • application/json
{
  course: {
    id?: string
    subjectId?: string
    number?: string
    title?: string
    displayTitle?: string
    credits?: string
    titleLong?: string
    subjectLong?: string
    subjectShort?: string
    topic?: string
    description?: string
    hasTopics?: boolean
    corequisites?: string
    prerequisites?: string
    hasRestrictions?: boolean
  }
  semester?: string
  transferred?: boolean
  grade?: string
  professor?: string
  notes?: string
  creditsAwarded?: string
}

Responses

  • 200 Added successfully

application/json

{
  message?: string
}
  • 400 Bad Request

application/json

{
  message?: string
  error?: string
}
  • 401 Unauthorized

application/json

{
  message?: string
  error?: string
}

[DELETE]/userCourse

  • Summary
    Delete a user course

  • Security
    cookieAuth

Parameters(Query)

courseId: string

Responses

  • 200 Deleted successfully

application/json

{
  message?: string
}
  • 400 Bad Request

application/json

{
  message?: string
  error?: string
}
  • 401 Unauthorized

application/json

{
  message?: string
  error?: string
}

[GET]/userAssignment

  • Summary
    Returns an array of user course assignments

  • Security
    cookieAuth

Responses

  • 200 an array of user course assignments

application/json

{
  status?: string
  id?: string
  requirement?: #/components/schemas/FixedRequirement | #/components/schemas/PrefixRequirement | #/components/schemas/AnonymousRequirement
  userCourse: {
    course: {
      id?: string
      subjectId?: string
      number?: string
      title?: string
      displayTitle?: string
      credits?: string
      titleLong?: string
      subjectLong?: string
      subjectShort?: string
      topic?: string
      description?: string
      hasTopics?: boolean
      corequisites?: string
      prerequisites?: string
      hasRestrictions?: boolean
    }
    semester?: string
    transferred?: boolean
    grade?: string
    professor?: string
    notes?: string
    creditsAwarded?: string
  }
}[]
  • 401 Unauthorized

application/json

{
  message?: string
  error?: string
}

[POST]/userAssignment

  • Summary
    Add a user course assignment

  • Security
    cookieAuth

RequestBody

  • application/json
{
  status?: string
  id?: string
  requirement?: #/components/schemas/FixedRequirement | #/components/schemas/PrefixRequirement | #/components/schemas/AnonymousRequirement
  userCourse: {
    course: {
      id?: string
      subjectId?: string
      number?: string
      title?: string
      displayTitle?: string
      credits?: string
      titleLong?: string
      subjectLong?: string
      subjectShort?: string
      topic?: string
      description?: string
      hasTopics?: boolean
      corequisites?: string
      prerequisites?: string
      hasRestrictions?: boolean
    }
    semester?: string
    transferred?: boolean
    grade?: string
    professor?: string
    notes?: string
    creditsAwarded?: string
  }
}

Responses

  • 200 Added successfully

application/json

{
  message?: string
}
  • 400 Bad Request

application/json

{
  message?: string
  error?: string
}
  • 401 Unauthorized

application/json

{
  message?: string
  error?: string
}

[PUT]/userAssignment

  • Summary
    Put all user course assignments

  • Security
    cookieAuth

RequestBody

  • application/json
{
  status?: string
  id?: string
  requirement?: #/components/schemas/FixedRequirement | #/components/schemas/PrefixRequirement | #/components/schemas/AnonymousRequirement
  userCourse: {
    course: {
      id?: string
      subjectId?: string
      number?: string
      title?: string
      displayTitle?: string
      credits?: string
      titleLong?: string
      subjectLong?: string
      subjectShort?: string
      topic?: string
      description?: string
      hasTopics?: boolean
      corequisites?: string
      prerequisites?: string
      hasRestrictions?: boolean
    }
    semester?: string
    transferred?: boolean
    grade?: string
    professor?: string
    notes?: string
    creditsAwarded?: string
  }
}[]

Responses

  • 200 Added successfully

application/json

{
  message?: string
}
  • 400 Bad Request

application/json

{
  message?: string
  error?: string
}
  • 401 Unauthorized

application/json

{
  message?: string
  error?: string
}

[DELETE]/userAssignment

  • Summary
    Delete a user course assignment

  • Security
    cookieAuth

Parameters(Query)

assignmentId: string

Responses

  • 200 Deleted successfully

application/json

{
  message?: string
}
  • 400 Bad Request

application/json

{
  message?: string
  error?: string
}
  • 401 Unauthorized

application/json

{
  message?: string
  error?: string
}

[PUT]/userSelectedArrConfig

  • Summary
    Save the user selected ARR Configs

  • Security
    cookieAuth

RequestBody

  • application/json
string[]

Responses

  • 200 Added successfully

application/json

{
  message?: string
}
  • 400 Bad Request

application/json

{
  message?: string
  error?: string
}
  • 401 Unauthorized

application/json

{
  message?: string
  error?: string
}

[GET]/userSelectedArrConfig

  • Summary
    Get the user selected ARR Configs

  • Security
    cookieAuth

Responses

  • 200 Array of user selected ARR Config ids

application/json

string[]
  • 401 Unauthorized

application/json

{
  message?: string
  error?: string
}

References

#/components/schemas/UserSelectedArrConfigs

string[]

#/components/schemas/DegreeRequirementAssignment

{
  status?: string
  id?: string
  requirement?: #/components/schemas/FixedRequirement | #/components/schemas/PrefixRequirement | #/components/schemas/AnonymousRequirement
  userCourse: {
    course: {
      id?: string
      subjectId?: string
      number?: string
      title?: string
      displayTitle?: string
      credits?: string
      titleLong?: string
      subjectLong?: string
      subjectShort?: string
      topic?: string
      description?: string
      hasTopics?: boolean
      corequisites?: string
      prerequisites?: string
      hasRestrictions?: boolean
    }
    semester?: string
    transferred?: boolean
    grade?: string
    professor?: string
    notes?: string
    creditsAwarded?: string
  }
}

#/components/schemas/UserCourse

{
  course: {
    id?: string
    subjectId?: string
    number?: string
    title?: string
    displayTitle?: string
    credits?: string
    titleLong?: string
    subjectLong?: string
    subjectShort?: string
    topic?: string
    description?: string
    hasTopics?: boolean
    corequisites?: string
    prerequisites?: string
    hasRestrictions?: boolean
  }
  semester?: string
  transferred?: boolean
  grade?: string
  professor?: string
  notes?: string
  creditsAwarded?: string
}

#/components/schemas/Subject

{
  id?: string
  short?: string
  long?: string
  title?: string
}

#/components/schemas/Section

{
  id?: string
  title?: string
  description?: string
  subsections: {
    title?: string
    description?: string
    requirements?: #/components/schemas/FixedRequirement | #/components/schemas/PrefixRequirement | #/components/schemas/AnonymousRequirement[]
  }[]
}

#/components/schemas/Subsection

{
  title?: string
  description?: string
  requirements?: #/components/schemas/FixedRequirement | #/components/schemas/PrefixRequirement | #/components/schemas/AnonymousRequirement[]
}

#/components/schemas/FixedRequirement

{
  requirementType?: string
  course: {
    id?: string
    subjectId?: string
    number?: string
    title?: string
    displayTitle?: string
    credits?: string
    titleLong?: string
    subjectLong?: string
    subjectShort?: string
    topic?: string
    description?: string
    hasTopics?: boolean
    corequisites?: string
    prerequisites?: string
    hasRestrictions?: boolean
  }
}

#/components/schemas/PrefixRequirement

{
  requirementType?: string
  requirementId?: string
  subjectId?: string
  prefix?: string
  description?: string
  credits?: string
}

#/components/schemas/AnonymousRequirement

{
  requirementType?: string
  designation?: string
  description?: string
  credits?: string
}

#/components/schemas/Course

{
  id?: string
  subjectId?: string
  number?: string
  title?: string
  displayTitle?: string
  credits?: string
  titleLong?: string
  subjectLong?: string
  subjectShort?: string
  topic?: string
  description?: string
  hasTopics?: boolean
  corequisites?: string
  prerequisites?: string
  hasRestrictions?: boolean
}

#/components/schemas/Account

{
  email?: string
  majors?: string[]
  gradSem?: string
}

#/components/schemas/SuccessMessage

{
  message?: string
}

#/components/schemas/FailureMessage

{
  message?: string
  error?: string
}

#/components/schemas/AuthSuccess

{
  message?: string
  user: {
    id?: string
    email?: string
    name?: string
  }
}

#/components/schemas/AuthFailure

{
  message?: string
}

#/components/schemas/UserAuth

{
  id?: string
  email?: string
  name?: string
}

#/components/securitySchemes/cookieAuth

{
  "type": "apiKey",
  "in": "cookie",
  "name": "connect.sid"
}

Based on TypeScript Node Starter and Express Generator