Skip to content

Commit

Permalink
updated to use bulk add/drop students endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
NeemZ16 committed Oct 29, 2024
1 parent 3613a4a commit 2f67d94
Showing 1 changed file with 40 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,11 @@ const CourseUpdatePage = ({ }) => {

const dropSingleStudent = async (email: string) => {
const userID = await getUserId(email)
if (!userID) { return }

if (userID == 0) {
setAlert({ autoDelete: false, type: 'error', message: "userID not found" })
return
}

try {
await RequestService.delete(`/api/course/${courseId}/user-courses/${userID}`)
Expand All @@ -213,18 +217,45 @@ const CourseUpdatePage = ({ }) => {
}
}

const addBulkStudent = async (emails: string[]) => {
try {
const reqBody = {
users: emails
}
const res = await RequestService.post(`/api/course/${courseId}/user-courses/students/add`, reqBody)
setAlert({ autoDelete: true, type: 'success', message: res.success })
} catch (error: any) { // Use any if the error type isn't strictly defined
const message = error.message || "An unknown error occurred"
setAlert({ autoDelete: false, type: 'error', message })
}
}

const dropBulkStudent = async (emails: string[]) => {
try {
const reqBody = {
users: emails
}
const res = await RequestService.post(`/api/course/${courseId}/user-courses/students/drop`, reqBody)
setAlert({ autoDelete: true, type: 'success', message: res.success })
} catch (error: any) { // Use any if the error type isn't strictly defined
const message = error.message || "An unknown error occurred"
setAlert({ autoDelete: false, type: 'error', message })
}
}

const handleAddStudent = () => {
console.log("emails: ", emails);
if (emails.length<1) {
// if no file inputted then addSingleStudent with email
console.log("adding single user")
addSingleStudent(studentEmail)
} else {
// if file inputted then for each email parsed from csv addSingleStudent
// if file inputted then call
console.log("adding multiple users")
emails.forEach(email => {
addSingleStudent(email)
})
// emails.forEach(email => {
// addSingleStudent(email)
// })
addBulkStudent(emails)
}
}

Expand All @@ -236,9 +267,10 @@ const CourseUpdatePage = ({ }) => {
} else {
// if file inputted then for each email parsed from csv dropSingleStudent
console.log("dropping multiple users")
emails.forEach(email => {
dropSingleStudent(email)
})
// emails.forEach(email => {
// dropSingleStudent(email)
// })
dropBulkStudent(emails)
}
}

Expand Down

0 comments on commit 2f67d94

Please sign in to comment.