get convos endpoint

This commit is contained in:
Danny Avila 2023-02-06 15:17:54 -05:00
parent c821d1eee5
commit 2869638cc0
6 changed files with 50 additions and 5 deletions

View file

@ -38,5 +38,8 @@ module.exports = {
{ $set: update }, { $set: update },
{ new: true, upsert: true } { new: true, upsert: true }
).exec(); ).exec();
} },
getConversations: async () => {
return await Conversation.find({}).exec();
},
}; };

37
package-lock.json generated
View file

@ -21,6 +21,7 @@
"react": "^18.2.0", "react": "^18.2.0",
"react-dom": "^18.2.0", "react-dom": "^18.2.0",
"react-textarea-autosize": "^8.4.0", "react-textarea-autosize": "^8.4.0",
"swr": "^2.0.3",
"url": "^0.11.0" "url": "^0.11.0"
}, },
"devDependencies": { "devDependencies": {
@ -11252,6 +11253,20 @@
"url": "https://github.com/sponsors/ljharb" "url": "https://github.com/sponsors/ljharb"
} }
}, },
"node_modules/swr": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/swr/-/swr-2.0.3.tgz",
"integrity": "sha512-sGvQDok/AHEWTPfhUWXEHBVEXmgGnuahyhmRQbjl9XBYxT/MSlAzvXEKQpyM++bMPaI52vcWS2HiKNaW7+9OFw==",
"dependencies": {
"use-sync-external-store": "^1.2.0"
},
"engines": {
"pnpm": "7"
},
"peerDependencies": {
"react": "^16.11.0 || ^17.0.0 || ^18.0.0"
}
},
"node_modules/tailwindcss": { "node_modules/tailwindcss": {
"version": "3.2.4", "version": "3.2.4",
"resolved": "https://registry.npmjs.org/tailwindcss/-/tailwindcss-3.2.4.tgz", "resolved": "https://registry.npmjs.org/tailwindcss/-/tailwindcss-3.2.4.tgz",
@ -11711,6 +11726,14 @@
} }
} }
}, },
"node_modules/use-sync-external-store": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/use-sync-external-store/-/use-sync-external-store-1.2.0.tgz",
"integrity": "sha512-eEgnFxGQ1Ife9bzYs6VLi8/4X6CObHMw9Qr9tPY43iKwsPw8xE8+EFsf/2cFZ5S3esXgpWgtSCtLNS41F+sKPA==",
"peerDependencies": {
"react": "^16.8.0 || ^17.0.0 || ^18.0.0"
}
},
"node_modules/util": { "node_modules/util": {
"version": "0.10.4", "version": "0.10.4",
"resolved": "https://registry.npmjs.org/util/-/util-0.10.4.tgz", "resolved": "https://registry.npmjs.org/util/-/util-0.10.4.tgz",
@ -20458,6 +20481,14 @@
"integrity": "sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==", "integrity": "sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==",
"dev": true "dev": true
}, },
"swr": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/swr/-/swr-2.0.3.tgz",
"integrity": "sha512-sGvQDok/AHEWTPfhUWXEHBVEXmgGnuahyhmRQbjl9XBYxT/MSlAzvXEKQpyM++bMPaI52vcWS2HiKNaW7+9OFw==",
"requires": {
"use-sync-external-store": "^1.2.0"
}
},
"tailwindcss": { "tailwindcss": {
"version": "3.2.4", "version": "3.2.4",
"resolved": "https://registry.npmjs.org/tailwindcss/-/tailwindcss-3.2.4.tgz", "resolved": "https://registry.npmjs.org/tailwindcss/-/tailwindcss-3.2.4.tgz",
@ -20785,6 +20816,12 @@
"use-isomorphic-layout-effect": "^1.1.1" "use-isomorphic-layout-effect": "^1.1.1"
} }
}, },
"use-sync-external-store": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/use-sync-external-store/-/use-sync-external-store-1.2.0.tgz",
"integrity": "sha512-eEgnFxGQ1Ife9bzYs6VLi8/4X6CObHMw9Qr9tPY43iKwsPw8xE8+EFsf/2cFZ5S3esXgpWgtSCtLNS41F+sKPA==",
"requires": {}
},
"util": { "util": {
"version": "0.10.4", "version": "0.10.4",
"resolved": "https://registry.npmjs.org/util/-/util-0.10.4.tgz", "resolved": "https://registry.npmjs.org/util/-/util-0.10.4.tgz",

View file

@ -33,6 +33,7 @@
"react": "^18.2.0", "react": "^18.2.0",
"react-dom": "^18.2.0", "react-dom": "^18.2.0",
"react-textarea-autosize": "^8.4.0", "react-textarea-autosize": "^8.4.0",
"swr": "^2.0.3",
"url": "^0.11.0" "url": "^0.11.0"
}, },
"devDependencies": { "devDependencies": {

View file

@ -2,7 +2,7 @@ const express = require('express');
const { ask, titleConversation } = require('../app/chatgpt'); const { ask, titleConversation } = require('../app/chatgpt');
const dbConnect = require('../models/dbConnect'); const dbConnect = require('../models/dbConnect');
const { saveMessage } = require('../models/Message'); const { saveMessage } = require('../models/Message');
const { saveConversation } = require('../models/Conversation'); const { saveConversation, getConversations } = require('../models/Conversation');
const crypto = require('crypto'); const crypto = require('crypto');
const path = require('path'); const path = require('path');
const cors = require('cors'); const cors = require('cors');
@ -21,6 +21,10 @@ app.get('/', function (req, res) {
res.sendFile(path.join(projectPath, 'public', 'index.html')); res.sendFile(path.join(projectPath, 'public', 'index.html'));
}); });
app.get('/convos', async (req, res) => {
res.status(200).send(await getConversations());
});
app.post('/ask', async (req, res) => { app.post('/ask', async (req, res) => {
console.log(req.body); console.log(req.body);
const { text, parentMessageId, conversationId } = req.body; const { text, parentMessageId, conversationId } = req.body;

View file

@ -13,8 +13,8 @@ const App = () => {
<Nav /> <Nav />
{/* <div className="flex h-full flex-1 flex-col md:pl-[260px]"> */} {/* <div className="flex h-full flex-1 flex-col md:pl-[260px]"> */}
<div className="flex h-full w-full flex-1 flex-col bg-gray-50 md:pl-[260px]"> <div className="flex h-full w-full flex-1 flex-col bg-gray-50 md:pl-[260px]">
<MobileNav />
{/* <main className="relative h-full w-full transition-width flex flex-col overflow-hidden items-stretch flex-1"> */} {/* <main className="relative h-full w-full transition-width flex flex-col overflow-hidden items-stretch flex-1"> */}
<MobileNav />
<Messages messages={messages} /> <Messages messages={messages} />
<TextChat <TextChat
messages={messages} messages={messages}

View file

@ -58,13 +58,13 @@ export default function Conversation({ id, title = 'New conversation'}) {
y1="11" y1="11"
x2="10" x2="10"
y2="17" y2="17"
></line> />
<line <line
x1="14" x1="14"
y1="11" y1="11"
x2="14" x2="14"
y2="17" y2="17"
></line> />
</svg> </svg>
</button> </button>
</div> </div>