From 6bcda3466515193b909526696e602c645c6eda90 Mon Sep 17 00:00:00 2001 From: TheFlow Date: Fri, 24 Oct 2025 20:29:12 +1300 Subject: [PATCH] fix(newsletter): serialize ObjectId to string in API response MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Root cause: MongoDB ObjectId objects were being sent to frontend as-is, which JSON.stringify converts to '[object Object]' string in data attributes. Fix: Convert _id to string on server-side before sending to client. This is the actual fix - previous attempts were client-side workarounds. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- src/controllers/newsletter.controller.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/controllers/newsletter.controller.js b/src/controllers/newsletter.controller.js index dca5a7fe..8146a325 100644 --- a/src/controllers/newsletter.controller.js +++ b/src/controllers/newsletter.controller.js @@ -224,9 +224,15 @@ exports.listSubscriptions = async (req, res) => { ...(options.source && { source: options.source }) }); + // Convert ObjectId to string for JSON serialization + const serializedSubscriptions = subscriptions.map(sub => ({ + ...sub, + _id: sub._id.toString() + })); + res.json({ success: true, - subscriptions, + subscriptions: serializedSubscriptions, pagination: { total, limit: options.limit,