Skip to content
This repository has been archived by the owner on Mar 30, 2024. It is now read-only.

Commit

Permalink
delete course sections implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanvpham committed Nov 18, 2021
1 parent 9f6b59e commit a8765fe
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 18 deletions.
25 changes: 22 additions & 3 deletions app/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ var mysql = require("mysql");
const cors = require('cors');

app.use(cors());
app.use(express.json())

var connection = mysql.createConnection({
host: 'localhost',
database: 'courseenrollment',
user: 'root',
password: ''
password: 'asdf1234'
});

//get all students
Expand Down Expand Up @@ -85,6 +86,22 @@ app.get('/courseEnrollment/students/:id', function(req, res){
});
});

app.delete('/courseEnrollment/students/:sectionID/:studentID', function(req, res){
let sql = "DELETE FROM courseenrollment WHERE section_ID = ? AND student_ID = ?";
connection.query(sql, [req.params.sectionID, req.params.studentID], function(err, results){
if (err) throw err;
res.send(results);
});
});

app.delete('/shoppingcart/students/:sectionID/:studentID', function(req, res){
let sql = "DELETE FROM shoppingcart WHERE section_ID = ? AND student_ID = ?";
connection.query(sql, [req.params.sectionID, req.params.studentID], function(err, results){
if (err) throw err;
res.send(results);
});
});

//get all shoppingCart
app.get('/shoppingcart', function(req, res){
let sql = "SELECT * FROM shoppingcart";
Expand Down Expand Up @@ -195,10 +212,12 @@ let data = {
}

// INSERT - courses into shopping cart, adding from search results (based on student id) - not working
app.get('/shoppingcart/:section_ID/:student_ID/:unitsEnrolled/:unitsWaitlisted', (req, res) =>{
app.post('/shoppingcart', (req, res) =>{
const section_ID = req.body.section_ID;
const student_ID = req.body.section_ID
let sql = "INSERT INTO shoppingcart VALUES (?, ?, ?, ?)";
res.send(req.body)
connection.query(sql, [req.params.section_ID, req.params.student_ID, req.params.unitsEnrolled, req.params.unitsWaitlisted],function(err, results){
connection.query(sql, [section_ID, student_ID, 4, 4],function(err, results){
if (err) throw err;
res.send(results);
});
Expand Down
2 changes: 1 addition & 1 deletion app/tempCodeRunnerFile.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
create/shoppingcart
DELETE FROM courseenrollment WHERE section_ID = ? AND student_ID = ?
2 changes: 1 addition & 1 deletion drop.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<a href="index.html" class="nav-item left">MY CLASS SCHEDULE</a>

</div>
<body onload="onLoad()">
<body>
<div class= "row1">
<div class="scol">
<h2>Drop Courses</h2>
Expand Down
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<h2>Your Shopping Cart</h2>
</div>
<div class="scol floatright">
<a href="enroll.html"><button id="enrollBtn">Enroll</button></a>
<a href="enroll.html"><button id="enrollBtn" onclick="enroll()">Enroll</button></a>
</div>
<div class ="subrow">
<div class="col">Open <i class="fas fa-check"></i></i></div>
Expand Down
23 changes: 17 additions & 6 deletions scripts/drop.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

var student = 1;


document.addEventListener('DOMContentLoaded', function () {
fetch('http://localhost:3000/courseenrollment/students/' + student)
.then(response => response.json())
Expand All @@ -24,10 +24,11 @@ async function populateClassSchedule(data) {
var cell5 = row.insertCell(5); // units
var cell6 = row.insertCell(6); // status

cell0.innerHTML = "<input type='checkbox' id='dropCheck'>";
cell0.innerHTML = "<input type='checkbox' id='dropCheck'>";

// Insert data into the new cells
var sectionID = data[i-1].section_ID;
row.id = sectionID
await fetch('http://localhost:3000/coursesection/' + sectionID)
.then(response => response.json())
.then((data) => {
Expand Down Expand Up @@ -93,10 +94,20 @@ async function showConfirmation() {
console.log("showConfirmation");
var confirmation = confirm("Are you sure you want to drop the course(s)?");
if (confirmation) {
// drop courses



var grid = document.getElementById("classSchedule");

var checkBoxes = grid.getElementsByTagName("INPUT");
for (var i = 0; i < checkBoxes.length; i++) {
if (checkBoxes[i].checked) {
console.log(checkBoxes[i].parentNode.parentNode.id)
var sectionID = checkBoxes[i].parentNode.parentNode.id
await fetch('http://localhost:3000/courseEnrollment/students/'+ sectionID +'/' + student,{
method: 'DELETE'
})
.then(res => console.log(res))

}
}


alert("Classes have been dropped.");
Expand Down
14 changes: 13 additions & 1 deletion scripts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ async function populateShoppingCart(data) {

// Insert data into the new cells
var sectionID = data[i-1].section_ID;
row.id = sectionID;
await fetch('http://localhost:3000/coursesection/' + sectionID)
.then(response => response.json())
.then((data) => {
Expand Down Expand Up @@ -90,10 +91,18 @@ async function populateShoppingCart(data) {
});

// Delete button
cell6.innerHTML = "<button id='deleteBtn' onclick='deleteThisRow'>Delete</button>";
cell6.innerHTML = "<button class='deleteBtn' id='" + sectionID + "' onclick='deleteThisRow(this.id)'>Delete</button>";
}
}

async function deleteThisRow(ID){
await fetch('http://localhost:3000/shoppingcart/'+ ID +'/' + student,{
method: 'DELETE'
}).then(res => console.log(res))
window.location.href = 'index.html';

}

async function populateClassSchedule(data) {
var table = document.getElementById("classSchedule");
console.log(data);
Expand Down Expand Up @@ -175,3 +184,6 @@ async function populateClassSchedule(data) {
}
}

async function enroll(){

}
11 changes: 8 additions & 3 deletions scripts/search.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const { Axios } = require("axios");

var student = 1;
function searchButtonPressed() {
// Unhide search results section
searchResults.classList.remove("hidden");
Expand Down Expand Up @@ -122,7 +124,7 @@ async function populateSearchResults(data) {
}
cell4.innerHTML = status;
*/
cell5.innerHTML = "<button id='selectBtn' onclick='addToShoppingCart(" + i + ")'>Select</button>";
cell5.innerHTML = "<button class = 'selectBtn' id='selectBtn " + data[i-1].section_ID + "' onclick='addToShoppingCart(this.id)'>Select</button>";


}
Expand Down Expand Up @@ -151,8 +153,11 @@ async function populateSearchResults(data) {
*/
}

async function addToShoppingCart() {

async function addToShoppingCart(clickID) {
console.log("clicked"+ clickID)
Axios.post('http://localhost:3000/shoppingcart',{section_ID: clickID, student_ID: student}).then(() =>{
console.log("nice")
})
}
/*
function setnumWaitlisted(data) {
Expand Down
4 changes: 2 additions & 2 deletions styles/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ button {
right: 15px;
position: relative;
}
#selectBtn {
.selectBtn {
padding: 0px 0px;
top: 0px;
right: 0px;
height: 20px;
font-size: 15px;
position: relative;
}
#deleteBtn {
.deleteBtn {
padding: 0px 0px;
font-size: 0px;
top: 0px;
Expand Down

0 comments on commit a8765fe

Please sign in to comment.