forked from anuragverma108/SwapReads
-
Notifications
You must be signed in to change notification settings - Fork 0
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
d377142
commit 62bb5c9
Showing
4 changed files
with
59 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import Rating from "../models/Rating.js"; | ||
|
||
|
||
// Function to submit rating | ||
const submitRating = async (req, res) => { | ||
const { rating, feedback } = req.body; | ||
|
||
// Validate rating | ||
if (!rating || rating < 1 || rating > 5) { | ||
return res.status(400).json({ message: "Rating must be between 1 and 5" }); | ||
} | ||
|
||
try { | ||
const newRating = new Rating({ | ||
rating, | ||
feedback, | ||
}); | ||
|
||
await newRating.save(); | ||
res.status(201).json({ message: "Rating submitted successfully", data: newRating }); | ||
} catch (error) { | ||
console.error("Rating submission error:", error); | ||
res.status(500).json({ message: "Could not submit rating" }); | ||
} | ||
}; | ||
|
||
export default submitRating |
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,9 @@ | ||
import mongoose from'mongoose'; | ||
|
||
const RatingSchema = new mongoose.Schema({ | ||
rating: { type: Number, required: true, min: 1, max: 5 }, | ||
feedback: { type: String, maxlength: 500 }, | ||
}, { timestamps: true }); | ||
|
||
const Rating = mongoose.model('Rating', RatingSchema); | ||
export default Rating; |
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