import { router, publicProcedure, createCallerFactory } from "./server"; export const conversations = router({ fetchAll: publicProcedure.query(async ({ ctx: { db, jwt } }) => { console.log("jwt", jwt); return await db.conversations.findAll({ userId: jwt?.id as string }); }), fetchOne: publicProcedure .input((x) => x as { id: string }) .query(async ({ input: { id }, ctx: { db } }) => { return await db.conversations.findById(id); }), start: publicProcedure.mutation(async ({ ctx: { db, jwt } }) => { const row = { title: "New Conversation", userId: jwt?.id as string, }; return await db.conversations.create(row); }), deleteOne: publicProcedure .input((x) => x as { id: string }) .mutation(async ({ input: { id }, ctx: { db } }) => { await db.conversations.delete(id); return { ok: true }; }), updateTitle: publicProcedure .input( (x) => x as { id: string; title: string; } ) .mutation(async ({ input: { id, title }, ctx: { db } }) => { await db.conversations.update(id, { title }); return { ok: true }; }), fetchMessages: publicProcedure .input((x) => x as { conversationId: string }) .query(async ({ input: { conversationId }, ctx: { db } }) => { return await db.conversations.fetchMessages(conversationId); }), }); export const createCaller = createCallerFactory(conversations);