From 3cb048ea9e0af9edbef84373f32d99eb695a0460 Mon Sep 17 00:00:00 2001 From: mukimovd <41473651-mukimovd@users.noreply.replit.com> Date: Thu, 1 May 2025 03:46:09 +0000 Subject: [PATCH] Enable discussions on various content types and enhance user engagement Refactors comment storage to support generic entities using entityType and entityId fields in storage.ts and schema.ts. Replit-Commit-Author: Agent Replit-Commit-Session-Id: cbacfb18-842a-4116-a907-18c0105ad8ec Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/39b5c689-6e8a-4d5a-9792-69cc81a56534/079d6656-1153-4bbe-8f09-2e865c68b583.jpg --- server/storage.ts | 24 ++++++++---------------- shared/schema.ts | 5 ++++- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/server/storage.ts b/server/storage.ts index 5b9c996..54edb30 100644 --- a/server/storage.ts +++ b/server/storage.ts @@ -319,8 +319,9 @@ As we continue to develop the Tercul platform, we're committed to addressing the this.createComment({ content: "Fascinating exploration of how technology can preserve literary traditions!", userId: user1.id, - workId: 0, // Placeholder for blog posts - parentId: blogPost.id + entityType: "blogPost", + entityId: blogPost.id, + parentId: null }); } @@ -537,28 +538,19 @@ As we continue to develop the Tercul platform, we're committed to addressing the } async getCommentsByEntityId(entityType: string, entityId: number): Promise { - // In our storage model, we have specific fields for workId and translationId, - // but we want to support a more generic entity approach for blog posts, etc. - // For now, we'll handle the mapping between entity types and specific fields - + // If we're using the primary entity fields (workId or translationId) if (entityType === 'work') { return this.getCommentsByWorkId(entityId); } else if (entityType === 'translation') { return this.getCommentsByTranslationId(entityId); - } else if (entityType === 'blogPost') { - // For blog posts, filter comments by their entityType and entityId properties - // This assumes we're storing comment entities with these properties + } else { + // For all other entity types, use the generic entityType and entityId fields return Array.from(this.comments.values()).filter( comment => - // For blog posts, we're storing the references in the parentId field temporarily - // In a real implementation, we would add proper schema fields for this - comment.workId === 0 && // Use a placeholder workId - comment.parentId === entityId + comment.entityType === entityType && + comment.entityId === entityId ); } - - // Default return empty array if entity type is not recognized - return []; } async createComment(insertComment: InsertComment): Promise { diff --git a/shared/schema.ts b/shared/schema.ts index 058c747..02edf22 100644 --- a/shared/schema.ts +++ b/shared/schema.ts @@ -91,11 +91,14 @@ export const bookmarks = pgTable("bookmarks", { export const comments = pgTable("comments", { id: serial("id").primaryKey(), userId: integer("user_id").references(() => users.id).notNull(), - workId: integer("work_id").references(() => works.id).notNull(), + workId: integer("work_id").references(() => works.id), // Optional for non-work comments translationId: integer("translation_id").references(() => translations.id), lineNumber: integer("line_number"), content: text("content").notNull(), parentId: integer("parent_id").references(() => comments.id), + // Adding support for blog posts and other content types + entityType: text("entity_type"), // 'work', 'translation', 'blogPost', etc. + entityId: integer("entity_id"), // ID of the entity createdAt: timestamp("created_at").defaultNow().notNull(), });