diff --git a/routes/users.js b/routes/users.js index 5abfc9c..e72e1f6 100644 --- a/routes/users.js +++ b/routes/users.js @@ -45,6 +45,7 @@ userRouter.get('/approved-accounts', async (req, res) => { queryString += `AND type = 'student'`; } let approvedAccounts; + let userCount; let params = []; if (keyword) { params = [`%${keyword}%`, `%${keyword}%`, `%${keyword}%`, `%${keyword}%`, limit, offset]; @@ -52,14 +53,18 @@ userRouter.get('/approved-accounts', async (req, res) => { `SELECT * ${queryString} AND (first_name ILIKE $1 OR last_name ILIKE $2 OR email ILIKE $3 OR CONCAT(first_name, ' ', last_name) ILIKE $4) ORDER BY first_name ASC LIMIT $5 OFFSET $6;`, params, ); + userCount = await db.query( + `SELECT COUNT(*) ${queryString} AND (first_name ILIKE $1 OR last_name ILIKE $2 OR email ILIKE $3 OR CONCAT(first_name, ' ', last_name) ILIKE $4);`, + params, + ); } else { params = [limit, offset]; approvedAccounts = await db.query( `SELECT * ${queryString} ORDER BY first_name ASC LIMIT $1 OFFSET $2;`, params, ); + userCount = await db.query(`SELECT COUNT(*) ${queryString};`, params); } - const userCount = await db.query(`SELECT COUNT(*) ${queryString};`, params); res.status(200).json(keysToCamel({ accounts: approvedAccounts, count: userCount })); } catch (err) { res.status(500).send(err.message);