From a579328b865ef4d5b318404277a706dfbe028477 Mon Sep 17 00:00:00 2001 From: Jacqueline Date: Sat, 25 May 2024 12:08:26 -0700 Subject: [PATCH 1/6] Added button for updating subjects --- client/src/modules/Admin/Components/Admin.tsx | 38 ++++++++- server/scripts/populate-subjects.ts | 82 ++++++++++--------- server/src/admin/admin.controller.ts | 22 ++++- server/src/admin/admin.data-access.ts | 18 ++-- server/src/admin/admin.router.ts | 40 ++++++--- 5 files changed, 134 insertions(+), 66 deletions(-) diff --git a/client/src/modules/Admin/Components/Admin.tsx b/client/src/modules/Admin/Components/Admin.tsx index ff76f116..d6a5497b 100644 --- a/client/src/modules/Admin/Components/Admin.tsx +++ b/client/src/modules/Admin/Components/Admin.tsx @@ -27,6 +27,7 @@ export const Admin = () => { const [loadingSemester, setLoadingSemester] = useState(0) const [loadingProfs, setLoadingProfs] = useState(0) const [resettingProfs, setResettingProfs] = useState(0) + const [updatingSubjects, setUpdatingSubjects] = useState(0) const [addSemester, setAddSemester] = useState('') const [isAdminModalOpen, setIsAdminModalOpen] = useState(false) @@ -53,7 +54,7 @@ export const Admin = () => { // splits the reviews into three categories: approved (visible on the website), // pending (awaiting approval), and reported (hidden and awaiting approval) useEffect(() => { - async function loadReviews() { + async function loadReviews() { const pending = await axios.post('/api/admin/reviews/get/pending', { token: token, }) @@ -107,7 +108,7 @@ export const Admin = () => { review, pendingReviews ) - setPendingReviews(updatedUnapprovedReviews) + setPendingReviews(updatedUnapprovedReviews) } else { const updatedReportedReviews = removeReviewFromList( review, @@ -123,7 +124,7 @@ export const Admin = () => { // Call when admin would like to mass-approve all of the currently pending reviews. async function approveAllReviews(reviews: Review[]) { - const response = await axios.post('/api/admin/reviews/approve/all', {token: token}) + const response = await axios.post('/api/admin/reviews/approve/all', { token: token }) if (response.status === 200) { setPendingReviews([]) } else { @@ -235,6 +236,20 @@ export const Admin = () => { }) } + function updateSubjects() { + setDisableInit(true); + setUpdatingSubjects(1); + axios.post('/api/admin/subjects/update', { token: token }).then((response) => { + if (response.status === 200) { + console.log('Updated all subject names'); + setDisableInit(false); + setUpdatingSubjects(2); + } else { + console.log('Error at updateSubjects'); + } + }) + } + // handle the first click to the "Initialize Database" button. Show an alert // and update state to remember the next click will be a double click. function firstClickHandler() { @@ -319,6 +334,14 @@ export const Admin = () => { > Reset Professors + {renderInitButton(doubleClick)} @@ -357,6 +380,15 @@ export const Admin = () => {

Professor data import to Classes is complete!

+ + + +