Skip to content

Conversation

@Frankdevlopes
Copy link
Collaborator

Modified the Reviewfeedback service file by adding logic to automatically send a notification to the review receiver when a new review is submitted.

@vercel
Copy link

vercel bot commented Nov 5, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
map-of-pi-backend Ready Ready Preview Comment Nov 5, 2025 1:52pm

const zeroRatingsCount = await ReviewFeedback.countDocuments({
review_receiver_id: user_settings_id,
rating: 0,
}).exec();
Copy link
Collaborator

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(),
Copy link
Collaborator

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);
Copy link
Collaborator

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants