folx-tv/server/replit_integrations/chat/storage.ts
sebastjanartic 308e602c73 Fix hero card aspect ratio and add horoscope generation functionality
Introduce horoscope generation via OpenAI API, including new API endpoints and database schema. Adjust card components in `home.tsx` to use `aspect-[16/9]` for consistent image sizing, resolving previous height stretching issues. Update dependencies in `package.json`.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 413891e8-d784-4bea-b9f5-91a5a68316b4
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Event-Id: ca1aa952-242c-43c1-9e28-47aed39cee1b
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/f209e72a-0939-48fa-84fc-57854de71967/413891e8-d784-4bea-b9f5-91a5a68316b4/nTLKCC5
Replit-Helium-Checkpoint-Created: true
2026-02-28 20:25:58 +00:00

44 lines
1.7 KiB
TypeScript

import { db } from "../../db";
import { conversations, messages } from "@shared/schema";
import { eq, desc } from "drizzle-orm";
export interface IChatStorage {
getConversation(id: number): Promise<typeof conversations.$inferSelect | undefined>;
getAllConversations(): Promise<(typeof conversations.$inferSelect)[]>;
createConversation(title: string): Promise<typeof conversations.$inferSelect>;
deleteConversation(id: number): Promise<void>;
getMessagesByConversation(conversationId: number): Promise<(typeof messages.$inferSelect)[]>;
createMessage(conversationId: number, role: string, content: string): Promise<typeof messages.$inferSelect>;
}
export const chatStorage: IChatStorage = {
async getConversation(id: number) {
const [conversation] = await db.select().from(conversations).where(eq(conversations.id, id));
return conversation;
},
async getAllConversations() {
return db.select().from(conversations).orderBy(desc(conversations.createdAt));
},
async createConversation(title: string) {
const [conversation] = await db.insert(conversations).values({ title }).returning();
return conversation;
},
async deleteConversation(id: number) {
await db.delete(messages).where(eq(messages.conversationId, id));
await db.delete(conversations).where(eq(conversations.id, id));
},
async getMessagesByConversation(conversationId: number) {
return db.select().from(messages).where(eq(messages.conversationId, conversationId)).orderBy(messages.createdAt);
},
async createMessage(conversationId: number, role: string, content: string) {
const [message] = await db.insert(messages).values({ conversationId, role, content }).returning();
return message;
},
};