Closed HTSagara closed 1 month ago
The latest updates on your projects. Learn more about Vercel for Git ↗︎
Name | Status | Preview | Comments | Updated (UTC) |
---|---|---|---|---|
dbms-project | ✅ Ready (Inspect) | Visit Preview | 💬 Add feedback | Oct 18, 2024 10:09pm |
Thanks for the awesome PR @HTSagara Really appreciate your contribution!
Overview
The code base had some redundancy. In this PR I tried to reduce it as much as possible. Most of the changes were made in the server side.
Backend
Utils folder
In the utils folder I added three new files
asyncHandler.js
,dbUtils.js
, andresponseHandler.js
asynceHandler.js
This file exports a function called asyncHandler that wraps asynchronous route handlers in an Express.js application. It ensures that any errors occurring in asynchronous code are caught and handled properly. If an error occurs, it logs the error message and responds with a 500 Internal Server Error, or with a custom error message if provided.
This function was implemented in most of the routes.
dbUtils.js
This file provides utility functions for interacting with the database:
getBuyerById
: Retrieves a buyer's information from the Buyers table by their Buyer_ID.getTransactionsByBuyerId
: Fetches all transactions associated with a given buyer from the Transactions table, identified by their Buyer_ID. Both functions use PostgreSQL queries to interact with the database.responseHandler.js
This file provides utility functions to handle HTTP responses:
send404
: Sends a404 Not Found
response with a custom error message.send500
: Sends a500 Internal Server Error
response with a custom error message.sendSuccess
: Sends a200 OK
response with a custom success data payload. These functions are used to standardize response handling in an Express.js application.Frontend
For the frontend the only change that I made was the suggested one in the issue description. I couldn't find the routes to create a new user so I could not login and test the rest of the frontend. So, I decided to stick with the proposed change.
AdminDashboard.jsx
I created the reusable button component that accepts the prop.