Module

Course Controller

This module contains all the controllers for the course model.

The following routes are handled by this controller


GET /courses
GET /courses/:id
POST /courses/new
PATCH /courses/update/:id
DELETE /courses/delete/:id
POST /courses/enroll/:id
POST /courses/cancelenrollment/:id
GET /courses/enrolled
GET /courses/enrolledcourses
GET /courses/enrolledusers/:id
POST /courses/video/upload
GET /courses/video/:id
GET /courses/videos/:courseId
PATCH /courses/video/update/:id
DELETE /courses/video/delete/:videoId
GET /courses/studentreport/:id

View Source API/src/controllers/course.controllers.js, line 1

Methods

# static cancelEnrollment(id) → {Object|boolean|string}

This function cancels a user's enrollment for a course by removing the user's ID from the enrolled_users array of the course.

Parameters:
Name Type Description
id string

The ID of the course to cancel enrollment for.

View Source API/src/controllers/course.controllers.js, line 418

Missing id parameter in request.

BadRequestError

Course with given id not found.

NotFoundError

An error occurred while processing the request.

InternalServerError

Response object.

Object

Response object.success - Indicates whether the operation was successful.

boolean

Response object.data.message - A message indicating the status of the operation.

string

# static createCourse(title, author, description) → {MongooseObject}

This function creates a new course

Parameters:
Name Type Description
title string

Course title

author string

Course author

description string

Course description

View Source API/src/controllers/course.controllers.js, line 61

if an error occured

error

savedCourse

MongooseObject

# static deleteCourse(id) → {string}

Deletes a course.


NOTE: This function does not delete the course data from the database, it only makes it unavailable for users. It does this by setting the isAvailable field to false When making requests to the getCourses route, it'll only filter only the courses with where their value for isAvailable is true

Parameters:
Name Type Description
id string

Id of the course

View Source API/src/controllers/course.controllers.js, line 337

message

string

# static deleteVideo(video_id) → {string}

This function doesn't actually delete the video, it only updates its available status if a videos isAvailable status is set to false, it wont be added when making query requests

Parameters:
Name Type Description
video_id string

id of the video to delete

To Do:
  • delete video from cloudinary
  • delete video from database
  • delete video from course

View Source API/src/controllers/course.controllers.js, line 712

if an error occured

error

if video not found

BadRequestError

message

string

# static enrollCourse(id) → {Object|boolean|string}

When a user enrolls for a course, a course report is created for the user. The course report contains the progress of the user in the course.

Parameters:
Name Type Description
id string

The ID of the course to enroll for.

View Source API/src/controllers/course.controllers.js, line 369

Missing id parameter in request.

BadRequestError

Course with given id not found.

NotFoundError

An error occurred while processing the request.

InternalServerError

Response object.

Object

Response object.success - Indicates whether the operation was successful.

boolean

Response object.data.message - A message indicating the status of the operation.

string

# static getCourseData(id)

Gets all the content of a course, including videos, author, description


Each course has a list of course sections, which are the different sections of the course. Each course section has a list of videos, exercises and text materials. In each course section, the videos, exercises and text materials are stored in a list, the list is stored with a key content. The content is an array of objects, where each object type is either video, exercise or textmaterial.

Parameters:
Name Type Description
id string

id of the course

View Source API/src/controllers/course.controllers.js, line 200

course

# static getCourseVideos(req) → {Array}

Get Course videos Gets all the videos linked to a particular course

Parameters:
Name Type Description
req courseId

id of the course to get

View Source API/src/controllers/course.controllers.js, line 593

  • Array of all the videos within the course
Array

# static getCourses() → {object}

This function gets all the courses available, or gets all the courses that match the query.

The query is passed in the request body, and it is an object with the following structure:

{
     key: value
}

The key is the field to be queried, and the value is the value to be matched.

For example, if you want to get all the courses that have the title "Introduction to Python", you would pass the following object in the request body:

{
     title: "Introduction to Python"
}

If you want to get all the courses that have the title "Introduction to Python" and the author "John Doe", you would pass the following object in the request body:

{
     title: "Introduction to Python",
     author: "John Doe"
}

If you want to get all the courses, then the request body should be empty.

View Source API/src/controllers/course.controllers.js, line 134

courses

object

# static getEnrolledCourses() → {object}

This function returns all the courses that a user is enrolled in. No request parameters are required since the user id is gotten from the request object after the user is authenticated.

View Source API/src/controllers/course.controllers.js, line 452

enrolledCourses

object

# static getEnrolledUsers(id) → {object}

Retrieves a list of all users who have enrolled in the specified course.

Parameters:
Name Type Description
id string

The ID of the course to retrieve enrolled users for.

View Source API/src/controllers/course.controllers.js, line 474

If the course ID is missing from the request parameters.

BadRequestError

If the specified course does not exist.

NotFoundError
  • An object containing a list of enrolled users for the course.
object

# static getStudentReportForCourse(course_id) → {object}

This function gets the course report for a particular student, the student must be enrolled in the course

The student course report contains the following data:

  1. Course details (title, description, category, etc)
  2. Completed exercises
  3. Completed videos
  4. Completed sections (sections that have all their videos completed)
Parameters:
Name Type Description
course_id string

id of the course to get student report for

View Source API/src/controllers/course.controllers.js, line 748

An error occured

InternalServerError

if course not found

BadRequestError

if user not enrolled in course

BadRequestError

course_report

object

# static getVideoData(id) → {Object}

This function returns the data for a specific video, including its title, description, duration, and URL.

Parameters:
Name Type Description
id string

The ID of the video to retrieve

See:
  • Video

View Source API/src/controllers/course.controllers.js, line 629

If the ID is missing from the request parameters

BadRequestError

If the video with the given ID is not found

NotFoundError
  • An object containing the video data, including its title, description, duration, and URL. If the video is not available, the video property will be null.
Object

# static removeVideoFromCourse(video_id, course_id) → {Object}

This function removes a video from a course, it doesn't remove the course from the video, it only removes the video from the course

Parameters:
Name Type Description
video_id string

id of the video

course_id string

id of the course

View Source API/src/controllers/course.controllers.js, line 565

course

Object

# static updateCourse(id) → {string|object}

Updates the course data, including title, author, description


NOTE: This function does not update the course sections, videos, exercises and text materials.
To update the course sections, videos, exercises and text materials, use the following functions:

POST /coursesection/new
PATCH /coursesection/update/:id
DELETE /coursesection/delete/:id
POST /course/video/upload
PATCH /course/video/update/:id
DELETE /course/video/delete/:id
POST /exercise/new
PATCH /exercise/update/:id
DELETE /exercise/delete/:id
POST /textmaterial/new
PATCH /textmaterial/update/:id


NOTE: These routes are subject to change, check the documentation for the latest routes.

Parameters:
Name Type Description
id string

View Source API/src/controllers/course.controllers.js, line 299

if Course not found

BadRequestError

message

string

course

object

# static updateVideo(video_id) → {object}

This function updates the video data


The following fields can be updated:

  1. title
  2. description
  3. author
  4. duration
  5. category
  6. course_id
  7. course_section_id
  8. video_url

The following fields cannot be updated:

  1. isAvailable
    This field is set to false when a video is deleted
Parameters:
Name Type Description
video_id string
req.body object

View Source API/src/controllers/course.controllers.js, line 683

if an error occured

error

if video not found

BadRequestError

video

object

# static uploadVideo(title, description, author, duration, category, course_id, course_section_id) → {object}

This function uploads a video to the database and links the video to a particular course section in a course.

Parameters:
Name Type Description
title string
description string
author string
duration string

| 00:00

category string
course_id string

id of course to add video to

course_section_id string

id of course section to add video to

View Source API/src/controllers/course.controllers.js, line 515

if an error occured

error

video

object