-
Notifications
You must be signed in to change notification settings - Fork 319
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
533e2f2
commit 45bef13
Showing
7 changed files
with
155 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import Feedback from "../models/feedback.js"; | ||
|
||
// Controller to handle feedback submission | ||
export async function submitFeedback(req, res) { // Changed resp to res | ||
console.log('feedback form getting submit') | ||
try { | ||
// Extract feedback data from the request body | ||
const { | ||
overallExperience, | ||
featuresUsed, | ||
mostHelpfulFeature, | ||
improvement, | ||
newFeatures, | ||
recommendation, | ||
additionalComments | ||
} = req.body; | ||
|
||
// Validate required fields | ||
if (!overallExperience || !featuresUsed || !mostHelpfulFeature || !recommendation) { | ||
return res.status(400).json({ message: 'Please provide all required fields.' }); | ||
} | ||
|
||
// Create a new Feedback instance with the extracted data | ||
const feedback = new Feedback({ | ||
overallExperience, | ||
featuresUsed, | ||
mostHelpfulFeature, | ||
improvement, | ||
newFeatures, | ||
recommendation, | ||
additionalComments | ||
}); | ||
|
||
// Save the feedback data to MongoDB | ||
await feedback.save(); | ||
|
||
// Respond with a success message | ||
res.status(201).json({ message: 'Feedback submitted successfully', feedback }); | ||
} catch (error) { | ||
// Handle errors and send a failure response | ||
console.error('Error saving feedback:', error); | ||
res.status(500).json({ message: 'Failed to submit feedback', error: error.message }); | ||
} | ||
} | ||
|
||
|
||
export async function getFeed(req, res) { | ||
res.send("feedback form") | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,46 @@ | ||
import { mongoose } from "mongoose"; | ||
import mongoose from 'mongoose'; | ||
|
||
const feedbackSchema = new mongoose.Schema( | ||
{ | ||
name: { | ||
type: String, | ||
required: true, | ||
trim: true, | ||
}, | ||
userfeedback: { | ||
type: String, | ||
required: true, | ||
trim: true, | ||
}, | ||
email: { | ||
type: String, | ||
required: true, | ||
}, | ||
rating: { | ||
type: Number, | ||
required: true, | ||
}, | ||
const feedbackSchema = new mongoose.Schema({ | ||
overallExperience: { | ||
type: Number, | ||
required: true, | ||
min: 1, | ||
max: 5 | ||
}, | ||
{ timestamps: true } | ||
); | ||
featuresUsed: { | ||
type: [String], | ||
enum: ['vocabulary', 'grammar', 'pronunciation', 'reading', 'listening'], | ||
required: true | ||
}, | ||
mostHelpfulFeature: { | ||
type: String, | ||
enum: ['vocabulary', 'grammar', 'pronunciation', 'reading', 'listening'], | ||
required: true | ||
}, | ||
improvement: { | ||
type: String, | ||
trim: true | ||
}, | ||
newFeatures: { | ||
type: String, | ||
trim: true | ||
}, | ||
recommendation: { | ||
type: Number, | ||
required: true, | ||
min: 1, | ||
max: 5 | ||
}, | ||
additionalComments: { | ||
type: String, | ||
trim: true | ||
}, | ||
submittedAt: { | ||
type: Date, | ||
default: Date.now | ||
} | ||
}); | ||
|
||
const feedback = mongoose.model(" feedback", feedbackSchema); | ||
const Feedback = mongoose.model("Feedback", feedbackSchema); | ||
|
||
export default feedback; | ||
export default Feedback; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import express from "express"; | ||
import { getFeed, submitFeedback } from "../controllers/feedController.js"; | ||
const router = express.Router(); | ||
|
||
|
||
router.post("/saveFeedback", submitFeedback); | ||
router.get("/saveFeedback", getFeed); | ||
|
||
export default router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters