-
Notifications
You must be signed in to change notification settings - Fork 0
Create User & RD API Endpoints #32
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
base: main
Are you sure you want to change the base?
Create User & RD API Endpoints #32
Conversation
alexy-ok
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work, really impressed with how quickly you were able to finish this task.
Just a few small changes that I think could've been caught with some more testing, but overall very satisfied.
server/routes/gcfUser.js
Outdated
| try { | ||
| // Query database | ||
| const data = await db.query(`SELECT * FROM gcf_user`); | ||
| res.status(200).json(keysToCamel(data[0])); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix: For this line, I would remove the [0] as it is returning just one data entry when there are multiple entries
server/routes/gcfUser.js
Outdated
|
|
||
| gcfUserRouter.get("/", async (req, res) => { | ||
| try { | ||
| // Query database |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
chore: delete this comment
| gcfUserRouter.post("/", async (req, res) => { | ||
| try { | ||
| const {id, role, email, first_name, last_name, date_created, created_by} = req.body | ||
| const newGcfUser = await db.query( | ||
| `INSERT INTO gcf_user (id, role, email, first_name, last_name, date_created, created_by) | ||
| VALUES ($1, $2, $3, $4, $5, $6, $7) | ||
| RETURNING *`, | ||
| [id, role, email, first_name, last_name, date_created, created_by] | ||
| ); | ||
| res.status(201).json(keysToCamel(newGcfUser[0])); | ||
| } catch (err) { | ||
| console.error(err); | ||
| res.status(500).send("Internal Server Error"); | ||
| } | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix: Remove id as an insertion value
Taking id as an input is currently messing up how ids are generated. They should be auto-incrementing and handled by postgres.
You should be able to remove id as a value that you are inserting. This way the id is generated during insertion not by the backend but by the database.
server/routes/regionalDirector.js
Outdated
|
|
||
| regionalDirectorRouter.get("/", async (req, res) => { | ||
| try { | ||
| // Query database |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
chore: delete this comment
server/routes/regionalDirector.js
Outdated
| try { | ||
| // Query database | ||
| const data = await db.query(`SELECT * FROM regional_director`); | ||
| res.status(200).json(keysToCamel(data[0])); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix: remove the [0] here
…r both user and regional director
…ttps://github.com/ctc-uci/gcf into GCF27-Create-User-Regional-Director-API-Endpoints Added revisions
Description
Created a Express.js file with routes for interacting with the
gcf_usertableCreated a Express.js file with routes for interacting with the
regional_directortableBoth files have:
Added routes to server/src/app.ts
Tested CRUD routes on Postman
Screenshots/Media
Issues
Closes #27
Additional Notes
We deleted some cronjob stuff in the app.ts, as well as the sampleRouter