Skip to content

Instantly share code, notes, and snippets.

View atakangah's full-sized avatar

Andrews Kangah atakangah

View GitHub Profile
@atakangah
atakangah / editroute_3.js
Last active July 12, 2020 11:08
<<Continuation>>An express routing js file to take a student's Id and a course Id from a request body to the api server and remove the associated course with the specified course Id from the student's courses list<<Continuation>>
// Update student data with new data without the deleted course
try {
let ccompleteRes = await Students.updateOne({ 'studentId': studentId }, student[0], { upsert: true }).exec();
/*
* NOTICE THE CALL TO THIS FUNCTION
* I DID NOT USE AWAIT
*/
updateCompletedStudents(courseId, student, res);
@atakangah
atakangah / editroute_2.js
Created July 12, 2020 11:01
<<Continuation>>An express routing js file to take a student's Id and a course Id from a request body to the api server and remove the associated course with the specified course Id from the student's courses list<<Continuation>>
try {
let student = await Students.find({ 'studentId': studentId }).exec();
/*
* After finding the student with the provided studentId,
* Use O(n) algorithm to find the course to complete for student
* It is unlikely for any student to have more than 5 courses in its course list at aytime
* Therefore, O(n) algorithm is ok
*/
@atakangah
atakangah / editroute_1.js
Last active July 12, 2020 11:00
An express routing js file to take a student's Id and a course Id from a request body to the api server and remove the associated course with the specified course Id from the student's courses list
router.post('/complete-student-course', async (req, res) => {
let {studentId, courseId} = req.body;