You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.4 KiB
TypeScript
50 lines
1.4 KiB
TypeScript
import {
|
|
router,
|
|
publicProcedure,
|
|
createCallerFactory,
|
|
} from "../../trpc/server";
|
|
import { db } from "../../database/index";
|
|
|
|
export const conversations = router({
|
|
fetchAll: publicProcedure.query(async () => {
|
|
return await db.conversations.findAll();
|
|
}),
|
|
fetchOne: publicProcedure
|
|
.input((x) => x as { id: string })
|
|
.query(async ({ input: { id } }) => {
|
|
return await db.conversations.findById(id);
|
|
}),
|
|
start: publicProcedure.mutation(async () => {
|
|
const row = {
|
|
title: "New Conversation",
|
|
userId: "019900bb-61b3-7333-b760-b27784dfe33b",
|
|
};
|
|
return await db.conversations.create(row);
|
|
}),
|
|
deleteOne: publicProcedure
|
|
.input((x) => x as { id: string })
|
|
.mutation(async ({ input: { id } }) => {
|
|
await db.conversations.delete(id);
|
|
return { ok: true };
|
|
}),
|
|
updateTitle: publicProcedure
|
|
.input(
|
|
(x) =>
|
|
x as {
|
|
id: string;
|
|
title: string;
|
|
}
|
|
)
|
|
.mutation(async ({ input: { id, title } }) => {
|
|
await db.conversations.update(id, { title });
|
|
return { ok: true };
|
|
}),
|
|
fetchMessages: publicProcedure
|
|
.input((x) => x as { conversationId: string })
|
|
.query(async ({ input: { conversationId } }) => {
|
|
return await db.conversations.fetchMessages(conversationId);
|
|
}),
|
|
});
|
|
|
|
export const createCaller = createCallerFactory(conversations);
|