-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #367 from Taranpreet10451/PublicReview
Public review
- Loading branch information
Showing
16 changed files
with
784 additions
and
256 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
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
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,29 @@ | ||
const mongoose = require('mongoose'); | ||
|
||
const reviewSchema = new mongoose.Schema({ | ||
user_id: { | ||
type: mongoose.Schema.Types.ObjectId, | ||
ref: 'User', | ||
required: true | ||
}, | ||
product_id: { | ||
type: mongoose.Schema.Types.ObjectId, | ||
ref: 'Product', | ||
required: true | ||
}, | ||
rating: { | ||
type: Number, | ||
required: true, | ||
min: 1, | ||
max: 5 | ||
}, | ||
review_text: { | ||
type: String, | ||
required: true | ||
} | ||
}, { | ||
timestamps: true | ||
}); | ||
|
||
const Review = mongoose.model('Review', reviewSchema); | ||
module.exports = Review; |
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,12 @@ | ||
const mongoose = require('mongoose'); | ||
|
||
const feedbackSchema = new mongoose.Schema({ | ||
student: { type: mongoose.Schema.Types.ObjectId, ref: 'Student' }, | ||
canteen: { type: mongoose.Schema.Types.ObjectId, ref: 'Canteen' }, | ||
comment: String, | ||
rating: Number, | ||
createdAt: { type: Date, default: Date.now } | ||
}); | ||
|
||
const Feedback = mongoose.model('Feedback', feedbackSchema); | ||
module.exports = Feedback; |
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,22 @@ | ||
const express = require('express'); | ||
const router = express.Router(); | ||
const { auth, studentAuth } = require('../middlewares/auth'); | ||
const Review = require('../models/review'); | ||
|
||
// POST /api/v1/reviews - Create a review | ||
router.post('/reviews', auth, studentAuth, async (req, res) => { | ||
try { | ||
const { product_id, rating, review_text } = req.body; | ||
const user_id = req.user.id; // Assuming req.user contains the authenticated user's details | ||
|
||
const newReview = new Review({ user_id, product_id, rating, review_text }); | ||
await newReview.save(); | ||
|
||
res.status(201).json({ success: true, message: 'Review created successfully' }); | ||
} catch (error) { | ||
console.error(error); | ||
res.status(500).json({ success: false, message: 'Error creating review' }); | ||
} | ||
}); | ||
|
||
module.exports = 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
Oops, something went wrong.