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
This commit is contained in:
mukimovd 2025-05-01 03:46:09 +00:00
parent bfbc4c336e
commit 3cb048ea9e
2 changed files with 12 additions and 17 deletions

View File

@ -319,8 +319,9 @@ As we continue to develop the Tercul platform, we're committed to addressing the
this.createComment({ this.createComment({
content: "Fascinating exploration of how technology can preserve literary traditions!", content: "Fascinating exploration of how technology can preserve literary traditions!",
userId: user1.id, userId: user1.id,
workId: 0, // Placeholder for blog posts entityType: "blogPost",
parentId: blogPost.id 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<Comment[]> { async getCommentsByEntityId(entityType: string, entityId: number): Promise<Comment[]> {
// In our storage model, we have specific fields for workId and translationId, // If we're using the primary entity fields (workId or 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 (entityType === 'work') { if (entityType === 'work') {
return this.getCommentsByWorkId(entityId); return this.getCommentsByWorkId(entityId);
} else if (entityType === 'translation') { } else if (entityType === 'translation') {
return this.getCommentsByTranslationId(entityId); return this.getCommentsByTranslationId(entityId);
} else if (entityType === 'blogPost') { } else {
// For blog posts, filter comments by their entityType and entityId properties // For all other entity types, use the generic entityType and entityId fields
// This assumes we're storing comment entities with these properties
return Array.from(this.comments.values()).filter( return Array.from(this.comments.values()).filter(
comment => comment =>
// For blog posts, we're storing the references in the parentId field temporarily comment.entityType === entityType &&
// In a real implementation, we would add proper schema fields for this comment.entityId === entityId
comment.workId === 0 && // Use a placeholder workId
comment.parentId === entityId
); );
} }
// Default return empty array if entity type is not recognized
return [];
} }
async createComment(insertComment: InsertComment): Promise<Comment> { async createComment(insertComment: InsertComment): Promise<Comment> {

View File

@ -91,11 +91,14 @@ export const bookmarks = pgTable("bookmarks", {
export const comments = pgTable("comments", { export const comments = pgTable("comments", {
id: serial("id").primaryKey(), id: serial("id").primaryKey(),
userId: integer("user_id").references(() => users.id).notNull(), 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), translationId: integer("translation_id").references(() => translations.id),
lineNumber: integer("line_number"), lineNumber: integer("line_number"),
content: text("content").notNull(), content: text("content").notNull(),
parentId: integer("parent_id").references(() => comments.id), 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(), createdAt: timestamp("created_at").defaultNow().notNull(),
}); });