chat-ui / src /routes /+layout.server.ts
victor's picture
victor HF staff
Prettier update (#54)
5da61b4 unverified
raw
history blame
630 Bytes
import type { LayoutServerLoad } from "./$types";
import { collections } from "$lib/server/database";
import type { Conversation } from "$lib/types/Conversation";
export const load: LayoutServerLoad = async (event) => {
const { conversations } = collections;
return {
conversations: await conversations
.find({
sessionId: event.locals.sessionId,
})
.sort({ updatedAt: -1 })
.project<Pick<Conversation, "title" | "_id" | "updatedAt" | "createdAt">>({
title: 1,
_id: 1,
updatedAt: 1,
createdAt: 1,
})
.map((conv) => ({ id: conv._id.toString(), title: conv.title }))
.toArray(),
};
};