-
Notifications
You must be signed in to change notification settings - Fork 4
Reviews Notification-Feature #330
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
base: dev
Are you sure you want to change the base?
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
| const zeroRatingsCount = await ReviewFeedback.countDocuments({ | ||
| review_receiver_id: user_settings_id, | ||
| rating: 0, | ||
| }).exec(); |
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.
REVIEW: You are calling ReviewFeedback.countDocuments twice (for totalReviews and zeroRatingsCount).
Consider a single aggregation to compute both in one round-trip for efficiency. You can try $group pipeline to compute totalReviews and zeroRatingsCount in one query and reduce latency.
| rating: formData.rating || "", | ||
| comment: formData.comment || "", | ||
| image: image || "", | ||
| review_date: new Date(), |
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.
REVIEW: Validate rating to number and validate range(if applicable). Reject/throw if invalid.
Ensure receiver id is present and non-empty. Throw error if not present/valid.
Cap comment length (e.g., 512/1024) to avoid abuse.
(Frontend also, try to sanitize comment to prevent injecting malicious js code thru user comments)
Note: These review inputs are applicable to updateReviewFeedback() also.
| const message = `${ | ||
| authUser.user_name || authUser.pi_uid | ||
| } has given you a review on ${new Date().toLocaleString()}`; | ||
| await addNotification(savedReviewFeedback.review_receiver_id, message); |
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.
REVIEW: Use ISO timestamp and avoid using toLocaleString() in backend. Clients can use toLocaleString.
Consider i18n for notification message (if its part of scope)
Modified the Reviewfeedback service file by adding logic to automatically send a notification to the review receiver when a new review is submitted.