-
Notifications
You must be signed in to change notification settings - Fork 30
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
Rahul - Added HGN Form Backend Code #1164
base: development
Are you sure you want to change the base?
Conversation
I have this PR and everything works fine, it was able to connect to the MongoDB database and I was able to run the server.js file. I've included the screen recording below for you to refer to. Screen.Recording.2024-12-07.at.3.48.07.PM.mov |
I’ve tested with frontend PR#2922 and successfully set up the database. I was also able to retrieve questions, and the modified questions were saved as expected. |
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.
Everything works as instructed—MongoDB is populated as expected using seed.js, and the Node.js server runs fine. However, I’ve noticed something that might be an issue (though I could be wrong): you've created a project within a project.
The hgn-form\backend directory is a standalone project with its own dependencies, nested inside HGNRest, which is a monolithic application. In my experience, nesting projects like this is not a good practice because it makes maintenance more difficult. For example, deploying hgn-form\backend would have to be done separately and manually.
I would recommend integrating hgn-form\backend into the main project so its logic can be used as one of the backend services. This would make the architecture cleaner and easier to maintain.
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.
Backend functions as expected! Here are some of my suggested improvements on some of the code. Consider adding middleware validates to prevent invalid data from reaching the database:
if (title) query.title = title; // Add title filter if provided | ||
|
||
const questions = await Question.find(query); // Fetch matching questions | ||
res.json(questions); |
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.
res.json(questions); | |
if (!questions.length) { | |
return res.status(404).json({ message: "No questions found" }); | |
} | |
res.json(questions); |
const Question = require("../models/Question"); | ||
|
||
const router = express.Router(); | ||
|
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.
// Consider adding validation for POST and PUT here | |
const validateQuestion = (req, res, next) => { | |
const { text, page, title } = req.body; | |
if (!text?.trim() || !page || !title?.trim()) { | |
return res.status(400).json({ error: "Invalid question data" }); | |
} | |
next(); | |
}; | |
// router.post("/", validateQuestion, async (req, res) => { | |
//. Existing POST route code here | |
//}); | |
//router.put("/:id", validateQuestion, async (req, res) => { | |
// Existing PUT route here | |
//}); | |
Description
This PR includes the backend code for the HGN Form application, which allows developers to evaluate their skill sets across various parameters, facilitating collaboration by enabling them to offer or request assistance from others. The backend primarily handles fetching the form questions. In owner mode, the questions can be edited directly from the frontend. This backend implementation includes all the necessary routing and logic to serve and update the questions efficiently.
Related PR
To test this backend PR you need to checkout the #2922 frontend PR.
Main changes explained
How to test
git checkout Rahul-HGN-Form-Backend
cd src/hgn-form/backend
npm install
to install the dependenciesnode seed.js
to populate your MongoDB databasenode server.js
to start your backend serverVideo Explanation - How to test this PR
https://www.loom.com/share/e8a28ca8345a4938b8348a208311adb1?sid=321f16bb-0e22-48b5-9b3e-18d78589bdfb