Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

23-make-backend-routes-for-users #26

Merged
merged 4 commits into from
Dec 18, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions routes/users.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
const express = require('express');
const { keysToCamel } = require('../common/utils');
const { db } = require('../server/db');

const userRouter = express.Router();

userRouter.get('/', async (req, res) => {
try {
const allUsers = await db.query(`SELECT * FROM users;`);
res.status(200).json(keysToCamel(allUsers));
} catch (err) {
console.log(err);
h0ethan04 marked this conversation as resolved.
Show resolved Hide resolved
res.status(500).send(err.message);
}
});


userRouter.get('/pending-accounts', async (req, res) => {
h0ethan04 marked this conversation as resolved.
Show resolved Hide resolved
try {
const pendingAccounts = await db.query(`SELECT * FROM users WHERE approved = FALSE;`);
res.status(200).json(keysToCamel(pendingAccounts));
} catch (err) {
console.log(err);
h0ethan04 marked this conversation as resolved.
Show resolved Hide resolved
res.status(500).send(err.message);
}
});


userRouter.post('/', async (req, res) => {
h0ethan04 marked this conversation as resolved.
Show resolved Hide resolved
h0ethan04 marked this conversation as resolved.
Show resolved Hide resolved
try {
const { id, email, type, approved } = req.params;
h0ethan04 marked this conversation as resolved.
Show resolved Hide resolved
h0ethan04 marked this conversation as resolved.
Show resolved Hide resolved
h0ethan04 marked this conversation as resolved.
Show resolved Hide resolved
h0ethan04 marked this conversation as resolved.
Show resolved Hide resolved
} catch (err) {

}
h0ethan04 marked this conversation as resolved.
Show resolved Hide resolved
h0ethan04 marked this conversation as resolved.
Show resolved Hide resolved
});

userRouter.put('/:uid', async (req, res) => {
h0ethan04 marked this conversation as resolved.
Show resolved Hide resolved
h0ethan04 marked this conversation as resolved.
Show resolved Hide resolved
try {

} catch (err) {
h0ethan04 marked this conversation as resolved.
Show resolved Hide resolved

}
h0ethan04 marked this conversation as resolved.
Show resolved Hide resolved
h0ethan04 marked this conversation as resolved.
Show resolved Hide resolved
});

userRouter.delete('/:uid', async (req, res) => {
h0ethan04 marked this conversation as resolved.
Show resolved Hide resolved
h0ethan04 marked this conversation as resolved.
Show resolved Hide resolved
try {

} catch (err) {
h0ethan04 marked this conversation as resolved.
Show resolved Hide resolved

}
h0ethan04 marked this conversation as resolved.
Show resolved Hide resolved
h0ethan04 marked this conversation as resolved.
Show resolved Hide resolved
});
Loading