From 6011a500423547be94323d01d3820bbb82b528e1 Mon Sep 17 00:00:00 2001 From: TheFlow Date: Fri, 24 Oct 2025 10:31:19 +1300 Subject: [PATCH] fix(submissions): remove User model populate calls - User is also a native MongoDB class, not Mongoose model - Removed all .populate() calls for createdBy, lastUpdatedBy, notes.author - These were causing MissingSchemaError for User model - Submissions can be returned without populated user data --- src/controllers/submissions.controller.js | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/controllers/submissions.controller.js b/src/controllers/submissions.controller.js index 5a7421a8..75544092 100644 --- a/src/controllers/submissions.controller.js +++ b/src/controllers/submissions.controller.js @@ -81,10 +81,9 @@ async function getSubmissions(req, res) { if (status) query.status = status; if (publicationId) query.publicationId = publicationId; - // NOTE: BlogPost is a native MongoDB class, not a Mongoose model, - // so we can't use .populate() for blogPostId. Fetch blog post data separately if needed. + // NOTE: BlogPost and User are native MongoDB classes, not Mongoose models, + // so we can't use .populate() for them. Fetch data separately if needed. const submissions = await SubmissionTracking.find(query) - .populate('createdBy', 'email') .sort({ submittedAt: -1, createdAt: -1 }) .limit(parseInt(limit, 10)) .skip(parseInt(offset, 10)); @@ -137,10 +136,7 @@ async function getSubmissionById(req, res) { try { const { id } = req.params; - const submission = await SubmissionTracking.findById(id) - .populate('createdBy', 'email') - .populate('lastUpdatedBy', 'email') - .populate('notes.author', 'email'); + const submission = await SubmissionTracking.findById(id); if (!submission) { return res.status(404).json({ @@ -318,9 +314,7 @@ async function getSubmissionByBlogPost(req, res) { try { const { blogPostId } = req.params; - const submission = await SubmissionTracking.findOne({ blogPostId }) - .populate('createdBy', 'email') - .populate('lastUpdatedBy', 'email'); + const submission = await SubmissionTracking.findOne({ blogPostId }); if (!submission) { return res.status(404).json({