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(), });