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

Jatin join hgn form with main app #1204

Open
wants to merge 5 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 98 additions & 0 deletions src/controllers/hgnFormController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
const Question = require("../models/hgnform");
const {formquestions}=require('../utilities/hgnformQuestions')

const checkAndPopulateCollection=async () =>{
try {
// Check if the collection exists and has any documents
const count = await Question.countDocuments();
if (count === 0) {
// Insert data into the collection
await Question.insertMany(formquestions);
}
} catch (error) {
console.error('Error checking or inserting data:', error);
}
}
const hgnFormController = function (){
// Function to check and insert data into the collection
const getQuestions=async function(req, res){
try {
await checkAndPopulateCollection();
const { page, title } = req.query; // Retrieve query parameters
const query = {};

if (page) query.page = Number(page); // Add page filter if provided
if (title) query.title = title; // Add title filter if provided

const questions = await Question.find(query); // Fetch matching questions
res.json(questions);
} catch (err) {
console.log(err)
res.status(500).json({ error: err.message });
}
}

const createQuestion=async function(req, res){
const { text, page, title } = req.body;
if (!text || !page || !title) {
return res
.status(400)
.json({ error: "All fields (text, page, title) are required" });
}

try {
const question = new Question({ text, page, title });
await question.save();
res.status(201).json(question);
} catch (err) {
res
.status(500)
.json({ error: "Failed to create question: " + err.message });
}
}

const updateQuestion=async function(req, res){
const { text, page, title } = req.body;

try {
const updatedQuestion = await Question.findByIdAndUpdate(
req.params.id,
{ text, page, title },
{ new: true }
);

if (!updatedQuestion) {
return res.status(404).json({ error: "Question not found" });
}

res.json(updatedQuestion);
} catch (err) {
res
.status(500)
.json({ error: "Failed to update question: " + err.message });
}
}
const deleteQuestion=async function(req, res){
try {
const deletedQuestion = await Question.findByIdAndDelete(req.params.id);

if (!deletedQuestion) {
return res.status(404).json({ error: "Question not found" });
}

res.json({ message: "Question deleted successfully" });
} catch (err) {
res
.status(500)
.json({ error: "Failed to delete question: " + err.message });
}
}
return {
getQuestions,
createQuestion,
updateQuestion,
deleteQuestion,

};
}
module.exports = hgnFormController;
36 changes: 36 additions & 0 deletions src/controllers/hgnFormResponseController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const FormResponse= require('../models/hgnFormResponse');

const hgnFormController = function (){
const submitFormResponse=async function(req, res){
const {userInfo, general, frontend, backend, followUp, user_id}=req.body;
if (!userInfo || !general || !frontend || !backend || !followUp || !user_id) {
return res
.status(400)
.json({ error: "All fields (userInfo, general, frontend, backend) are required" });
}
try {
const formResponse = new FormResponse({ userInfo, general, frontend, backend, followUp, user_id });
await formResponse.save();
res.status(201).json(formResponse);
} catch (err) {
res
.status(500)
.json({ error: "Failed to create formResponse: " + err.message });
}
};

const getAllFormResponses=async function(req, res){
try {
const formResponses = await FormResponse.find();
res.json(formResponses);
} catch (err) {
res.status(500).json({ error: err.message });
}
};

return {
submitFormResponse,
getAllFormResponses
}
}
module.exports = hgnFormController;
79 changes: 79 additions & 0 deletions src/models/hgnFormResponse.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
const mongoose = require('mongoose');

const userInfoSchema = new mongoose.Schema({
name: { type: String, required: true },
email: { type: String, required: true },
github: { type: String },
slack: { type: String },
});

const generalSchema = new mongoose.Schema({
hours: { type: String },
period: { type: String },
standup: { type: String },
location: { type: String },
manager: { type: String },
combined_frontend_backend: { type: String },
combined_skills: { type: String },
mern_skills: { type: String },
leadership_skills: { type: String },
leadership_experience: { type: String },
preferences: [{ type: String }],
availability: {
Monday: { type: String },
Tuesday: { type: String },
Wednesday: { type: String },
Thursday: { type: String },
Friday: { type: String },
Saturday: { type: String },
Sunday: { type: String },
},
});

const frontendSchema = new mongoose.Schema({
overall: { type: String },
HTML: { type: String },
Bootstrap: { type: String },
CSS: { type: String },
React: { type: String },
Redux: { type: String },
WebSocketCom: { type: String },
ResponsiveUI: { type: String },
UnitTest: { type: String },
Documentation: { type: String },
UIUXTools: { type: String },
});

const backendSchema = new mongoose.Schema({
overall: { type: String },
Database: { type: String },
MongoDB: { type: String },
MongoDB_Advanced: { type: String },
TestDrivenDev: { type: String },
Deployment: { type: String },
VersionControl: { type: String },
CodeReview: { type: String },
EnvironmentSetup: { type: String },
AdvancedCoding: { type: String },
AgileDevelopment: { type: String },
});

const followupSchema = new mongoose.Schema({
platform: { type: String },
other_skills: { type: String },
suggestion: { type: String },
additional_info: { type: String },
});

const hgnFormResponseSchema = new mongoose.Schema({
user_id: { type: String, required: true },
userInfo: { type: Object, value: userInfoSchema },
general: { type: Object, value: generalSchema },
frontend: { type: Object, value: frontendSchema },
backend: { type: Object, value: backendSchema },
followUp: { type: Object, value: followupSchema },
});

const formresponses = mongoose.model('HGNFormResponses', hgnFormResponseSchema);

module.exports = formresponses;
9 changes: 9 additions & 0 deletions src/models/hgnform.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const mongoose = require("mongoose");

const QuestionSchema = new mongoose.Schema({
text: { type: String, required: true },
page: { type: Number, required: true },
title: { type: String, required: true },
});

module.exports = mongoose.model("Question", QuestionSchema);
7 changes: 7 additions & 0 deletions src/routes/hgnFormResponseRouter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const express = require("express");
const hgnFormResponseRouter = express.Router();
const controller = require("../controllers/hgnFormResponseController")();
// controler to post data, view data
hgnFormResponseRouter.route("/").post(controller.submitFormResponse).get(controller.getAllFormResponses);

module.exports = hgnFormResponseRouter;
Empty file.
15 changes: 15 additions & 0 deletions src/routes/hgnformRouter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const express = require("express");
const hgnFormRouter = express.Router();
const controller=require('../controllers/hgnFormController')();



hgnFormRouter.route("/")
.get(controller.getQuestions)
.post(controller.createQuestion);

hgnFormRouter.route("/:id")
.put(controller.updateQuestion)
.delete(controller.deleteQuestion);

module.exports = hgnFormRouter;
5 changes: 4 additions & 1 deletion src/startup/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ const currentWarnings = require('../models/currentWarnings');
// Title
const title = require('../models/title');
const blueSquareEmailAssignment = require('../models/BlueSquareEmailAssignment');

const hgnformRouter=require('../routes/hgnformRouter');
const hgnFormResponseRouter=require('../routes/hgnFormResponseRouter');
const weeklySummaryAIPrompt = require('../models/weeklySummaryAIPrompt');
const profileInitialSetuptoken = require('../models/profileInitialSetupToken');
const reason = require('../models/reason');
Expand Down Expand Up @@ -168,6 +169,8 @@ module.exports = function (app) {
app.use('/api', followUpRouter);
app.use('/api', blueSquareEmailAssignmentRouter);
app.use('/api/jobs', jobsRouter);
app.use('/api/questions', hgnformRouter);
app.use('/api/hgnform',hgnFormResponseRouter);
// bm dashboard
app.use('/api/bm', bmLoginRouter);
app.use('/api/bm', bmMaterialsRouter);
Expand Down
46 changes: 46 additions & 0 deletions src/utilities/hgnformQuestions.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading