fix(newsletter): serialize ObjectId to string in API response
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 <noreply@anthropic.com>
This commit is contained in:
parent
c0bc35f2de
commit
6bcda34665
1 changed files with 7 additions and 1 deletions
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue