-
Notifications
You must be signed in to change notification settings - Fork 2
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
Reviews_BE #66
base: main
Are you sure you want to change the base?
Reviews_BE #66
Conversation
Signed-off-by: gurkiran_singh <gurkiransinghk@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good start but I think there are some issues with the approach. It would help to think through when and how a feature like average review would be used and simplify the manner of fetching it accordingly
if (userId === req.body.userId) { | ||
return res.status(401).json({ | ||
error: "User is not authorized for reviewing their own profile" | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice 👍
server/models/Review.js
Outdated
reviewerUserId: { | ||
type: ObjectId, | ||
ref: "user", | ||
unique: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This means a user can only write one review ever, if you're trying to prevent having multiple reviews of and by the same user you could either do that in the controller or have a separate unique value that combines the two ids
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it.
const { Schema } = mongoose; | ||
const { ObjectId } = Schema; | ||
|
||
const reviewSchema = new mongoose.Schema({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a field for a written review and not require it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I do that
server/controllers/review.js
Outdated
Review.aggregate( | ||
[ | ||
{ $group: { _id: "$userId", avgRating: { $avg: "$rating" } } } | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is getting the average rating of all users, this is not the best approach. I don't think having a specific route for this is ideal, would be better to have a way to populate this value in the profile when fetching the profile
Signed-off-by: gurkiran_singh <gurkiransinghk@gmail.com>
Signed-off-by: gurkiran_singh <gurkiransinghk@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Signed-off-by: gurkiran_singh gurkiransinghk@gmail.com
What this PR does (required):
Screenshots / Videos (required):
N/A
Any information needed to test this feature (required):
Any issues with the current functionality (optional):
No