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
c47972febb
commit
50746199d0
1 changed files with 7 additions and 1 deletions
|
|
@ -224,9 +224,15 @@ exports.listSubscriptions = async (req, res) => {
|
||||||
...(options.source && { source: options.source })
|
...(options.source && { source: options.source })
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Convert ObjectId to string for JSON serialization
|
||||||
|
const serializedSubscriptions = subscriptions.map(sub => ({
|
||||||
|
...sub,
|
||||||
|
_id: sub._id.toString()
|
||||||
|
}));
|
||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
success: true,
|
success: true,
|
||||||
subscriptions,
|
subscriptions: serializedSubscriptions,
|
||||||
pagination: {
|
pagination: {
|
||||||
total,
|
total,
|
||||||
limit: options.limit,
|
limit: options.limit,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue