Skip to content

Conversation

@harrisonharrisonharrison
Copy link
Contributor

Description

  • Created a Express.js file with routes for interacting with the gcf_user table

  • Created a Express.js file with routes for interacting with the regional_director table

  • Both files have:

    • Route for creating a user/RD
    • Route for reading all users/RD
    • Route for reading a user/RD
    • Route for updating a user/RD
    • Route for deleting a user/RD
  • Added routes to server/src/app.ts

    • userRouter for /gcf-users
    • regionalDirectorRouter for /regional-directors
  • Tested CRUD routes on Postman

Screenshots/Media

image - Creating a user for the gcf_user table returns 201 image - Creating another user for gcf_user image - Reading all users returns the first user in the table image - Updating a specified user with a parameter - The body does not need to specify all attributes image - Reading a specific user with a parameter returns the updated user from before image - Deleting a user returns OK

Issues

Closes #27

Additional Notes

We deleted some cronjob stuff in the app.ts, as well as the sampleRouter

Copy link
Member

@alexy-ok alexy-ok left a 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.

try {
// Query database
const data = await db.query(`SELECT * FROM gcf_user`);
res.status(200).json(keysToCamel(data[0]));
Copy link
Member

@alexy-ok alexy-ok Jan 8, 2026

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


gcfUserRouter.get("/", async (req, res) => {
try {
// Query database
Copy link
Member

@alexy-ok alexy-ok Jan 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chore: delete this comment

Comment on lines 8 to 22
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");
}
});
Copy link
Member

@alexy-ok alexy-ok Jan 8, 2026

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.


regionalDirectorRouter.get("/", async (req, res) => {
try {
// Query database
Copy link
Member

@alexy-ok alexy-ok Jan 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chore: delete this comment

try {
// Query database
const data = await db.query(`SELECT * FROM regional_director`);
res.status(200).json(keysToCamel(data[0]));
Copy link
Member

@alexy-ok alexy-ok Jan 8, 2026

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create User & Regional Director API Endpoints

4 participants