adds server and client error handling, clear convos in progress

This commit is contained in:
Daniel Avila 2023-02-08 00:02:29 -05:00
parent 511ac948b4
commit 51d93da3f8
9 changed files with 98 additions and 48 deletions

View file

@ -27,25 +27,25 @@ const Conversation =
module.exports = {
saveConvo: async ({ conversationId, parentMessageId, title }) => {
const messages = await getMessages({ conversationId });
const update = { parentMessageId, messages };
if (title) {
update.title = title;
}
try {
const messages = await getMessages({ conversationId });
const update = { parentMessageId, messages };
if (title) {
update.title = title;
}
await Conversation.findOneAndUpdate(
{ conversationId },
{ $set: update },
{ new: true, upsert: true }
).exec();
return await Conversation.findOneAndUpdate(
{ conversationId },
{ $set: update },
{ new: true, upsert: true }
).exec();
} catch (error) {
console.log(error);
return { message: 'Error saving conversation' };
}
},
getConvos: async () => await Conversation.find({}).exec(),
deleteConvos: async (filter) => {
// const filter = {};
// if (!!conversationId) {
// filter = conversationId;
// }
let deleteCount = await Conversation.deleteMany(filter).exec();
deleteCount.messages = await deleteMessages(filter);