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

Rahul - Added HGN Form Backend Code #1164

Open
wants to merge 1 commit into
base: development
Choose a base branch
from

Conversation

slidracoon72
Copy link

@slidracoon72 slidracoon72 commented Dec 5, 2024

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

  • models/Question.js: Defines the structure of 'Questions'
  • routes/questions.js: Contains the necessary routes for loading and editing questions, facilitating frontend-backend communication.
  • seed.js: Populates the MongoDB database with initial question data.
  • server.js: Establishes the database connection and starts the backend server.

How to test

  1. check into current branch: git checkout Rahul-HGN-Form-Backend
  2. change directory using: cd src/hgn-form/backend
  3. update '.env' file. First, create a sample MongoDB database to test this PR. Then add the URL of your database to MONGO_URI in the '.env' file
  4. run npm install to install the dependencies
  5. run node seed.js to populate your MongoDB database
  6. run node server.js to start your backend server
  7. Ensure the backend is running correctly and that data is successfully stored in your MongoDB database.
  8. Review the code files to verify both the logic and syntax.

Video Explanation - How to test this PR

https://www.loom.com/share/e8a28ca8345a4938b8348a208311adb1?sid=321f16bb-0e22-48b5-9b3e-18d78589bdfb

@slidracoon72 slidracoon72 added the DO NOT MERGE Don't merge PR label Dec 5, 2024
@slidracoon72 slidracoon72 changed the title Added HGN Form Backend Code Rahul - Added HGN Form Backend Code Dec 5, 2024
@one-community one-community added High Priority - Please Review First This is an important PR we'd like to get merged as soon as possible and removed DO NOT MERGE Don't merge PR labels Dec 6, 2024
@ppsahu
Copy link

ppsahu commented Dec 7, 2024

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

@mashpotato9
Copy link

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.

Copy link

@kobakvantrishvili kobakvantrishvili left a 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.
temp2
temp

Copy link

@honglinchen0524 honglinchen0524 left a 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);

Choose a reason for hiding this comment

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

Suggested change
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();

Choose a reason for hiding this comment

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

Suggested change
// 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
//});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
High Priority - Please Review First This is an important PR we'd like to get merged as soon as possible
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants