Skip to content

Commit

Permalink
🛠️ fix: Update Conversation and Message Models to Return Objects Inst…
Browse files Browse the repository at this point in the history
…ead of Using Lean() (danny-avila#3230)
  • Loading branch information
danny-avila authored Jun 29, 2024
1 parent a2fd975 commit a87d4e0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 4 additions & 2 deletions api/models/Conversation.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ module.exports = {
update.conversationId = newConversationId;
}

return await Conversation.findOneAndUpdate({ conversationId: conversationId, user }, update, {
const conversation = await Conversation.findOneAndUpdate({ conversationId, user }, update, {
new: true,
upsert: true,
}).lean();
});

return conversation.toObject();
} catch (error) {
logger.error('[saveConvo] Error saving conversation', error);
return { message: 'Error saving conversation' };
Expand Down
6 changes: 4 additions & 2 deletions api/models/Message.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,12 @@ module.exports = {
update.files = files;
}

return await Message.findOneAndUpdate({ messageId }, update, {
const message = await Message.findOneAndUpdate({ messageId }, update, {
upsert: true,
new: true,
}).lean();
});

return message.toObject();
} catch (err) {
logger.error('Error saving message:', err);
throw new Error('Failed to save message.');
Expand Down

0 comments on commit a87d4e0

Please sign in to comment.