From c8fe1a27cc6c344db2e8aa73273244aba0184755 Mon Sep 17 00:00:00 2001 From: chloecheng8 <30807247+chloecheng8@users.noreply.github.com> Date: Sat, 20 Apr 2024 17:39:56 -0700 Subject: [PATCH] added query in pending accounts for admin and student --- routes/users.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/routes/users.js b/routes/users.js index 6abf3dc..5abfc9c 100644 --- a/routes/users.js +++ b/routes/users.js @@ -17,9 +17,14 @@ userRouter.get('/', async (req, res) => { userRouter.get('/pending-accounts', async (req, res) => { try { - const pendingAccounts = await db.query( - `SELECT * FROM users WHERE approved = FALSE ORDER BY first_name ASC;`, - ); + const { accountType } = req.query; + let queryString = 'SELECT * FROM users WHERE approved = FALSE '; + if (accountType === 'admin') { + queryString += `AND type = 'admin'`; + } else if (accountType === 'student') { + queryString += `AND type = 'student'`; + } + const pendingAccounts = await db.query(`${queryString} ORDER BY first_name ASC;`); res.status(200).json(keysToCamel(pendingAccounts)); } catch (err) { res.status(500).send(err.message);