coyotte508's picture
coyotte508 HF staff
Split app structure & create convos (#20)
1b66f8d unverified
raw
history blame
657 Bytes
import type { RequestHandler } from './$types';
import { collections } from '$lib/server/database';
import { ObjectId } from 'mongodb';
export const POST: RequestHandler = async (input) => {
const res = await collections.conversations.insertOne({
_id: new ObjectId(),
title:
'Untitled ' +
((await collections.conversations.countDocuments({ sessionId: input.locals.sessionId })) + 1),
messages: [],
createdAt: new Date(),
updatedAt: new Date(),
sessionId: input.locals.sessionId
});
return new Response(
JSON.stringify({
conversationId: res.insertedId.toString()
}),
{ headers: { 'Content-Type': 'application/json' } }
);
};