diff --git a/routes/users.js b/routes/users.js index 6826366..eba4bbb 100644 --- a/routes/users.js +++ b/routes/users.js @@ -32,7 +32,7 @@ userRouter.post('/', async (req, res) => { approved, ]); res.status(201).json({ - status: 'Success', + id, }); } catch (err) { res.status(500).json({ @@ -49,7 +49,7 @@ userRouter.put('/:uid', async (req, res) => { `UPDATE users SET approved = TRUE WHERE id = $1 RETURNING *;`, [uid], ); - return res.status(200).send(updatedApproval[0]); + return res.status(200).send(keysToCamel(updatedApproval)); } catch (err) { return res.status(500).send(err.message); } @@ -58,8 +58,8 @@ userRouter.put('/:uid', async (req, res) => { userRouter.delete('/:uid', async (req, res) => { try { const { uid } = req.params; - await db.query(`DELETE FROM users WHERE id = $1;`, [uid]); - res.status(200).send('Deleted user'); + const deletedUser = await db.query(`DELETE FROM users WHERE id = $1 RETURNING *;`, [uid]); + res.status(200).send(keysToCamel(deletedUser)); } catch (err) { res.status(500).send(err.message); } diff --git a/server/queries/users.sql b/server/queries/users.sql deleted file mode 100644 index 1700cdc..0000000 --- a/server/queries/users.sql +++ /dev/null @@ -1,29 +0,0 @@ --- PUT/:uid - Updates an existing user as approved -UPDATE - users -SET - approved = TRUE -WHERE - id = ?; - --- DELETE/:uid - Deletes an existing user given their id -DELETE FROM - users -WHERE - id = ?; - --- GET - Returns all data from the Users table -SELECT * FROM - users; - --- GET/pending-accounts - Returns all data from Users table who are currently pending approval -SELECT * FROM - users -WHERE - approved = FALSE; - --- POST - Adds a new row into Users table -INSERT INTO - users (id, email, "type", approved) -VALUES - (?,?,?,?); \ No newline at end of file