diff --git a/server/storage.ts b/server/storage.ts index f52b7eb..df953af 100644 --- a/server/storage.ts +++ b/server/storage.ts @@ -283,8 +283,10 @@ export class MemStorage implements IStorage { description: "Died in St. Petersburg from wounds received in a duel with Georges d'Anthès" }); - // Create sample blog post - const blogPost = this.createBlogPost({ + // Create sample blog post - work around async issues by creating the object directly + const blogPostId = this.blogPostId++; + const blogPost: BlogPost = { + id: blogPostId, title: "Exploring Russian Poetry in the Digital Age", slug: "exploring-russian-poetry-digital-age", content: ` @@ -308,16 +310,21 @@ As we continue to develop the Tercul platform, we're committed to addressing the `, authorId: user1.id, excerpt: "Exploring how digital platforms can help preserve and promote the rich tradition of Russian poetry in the modern age.", - publishedAt: new Date() - }); + publishedAt: new Date(), + createdAt: new Date() + }; + + // Add the blog post to storage manually to avoid async issues + this.blogPosts.set(blogPostId, blogPost); + console.log('Created blog post with ID:', blogPostId); // Add tags to the blog post - console.log('Adding tags to blog post', blogPost.id); - this.addTagToBlogPost(blogPost.id, poetryTag.id); - this.addTagToBlogPost(blogPost.id, romanticismTag.id); + console.log('Adding tags to blog post', blogPostId); + this.addTagToBlogPost(blogPostId, poetryTag.id); + this.addTagToBlogPost(blogPostId, romanticismTag.id); // Add a comment to the blog post - console.log('Creating comment for blog post', blogPost.id); + console.log('Creating comment for blog post', blogPostId); this.createComment({ content: "Fascinating exploration of how technology can preserve literary traditions!", userId: user1.id, @@ -325,7 +332,7 @@ As we continue to develop the Tercul platform, we're committed to addressing the translationId: null, lineNumber: null, entityType: "blogPost", - entityId: blogPost.id, + entityId: blogPostId, parentId: null }); } @@ -483,15 +490,29 @@ As we continue to develop the Tercul platform, we're committed to addressing the } async getBlogPostTags(postId: number): Promise { + console.log(`Getting tags for blog post ${postId}`); + console.log(`BlogPostTagsRelations map:`, Array.from(this.blogPostTagsRelations.entries())); + const tagIds = this.blogPostTagsRelations.get(postId) || new Set(); - return Array.from(tagIds).map(id => this.tags.get(id)!).filter(Boolean); + console.log(`Tag IDs for blog post ${postId}:`, Array.from(tagIds)); + + const tags = Array.from(tagIds).map(id => this.tags.get(id)!).filter(Boolean); + console.log(`Found ${tags.length} tags for blog post ${postId}:`, tags); + + return tags; } async addTagToBlogPost(postId: number, tagId: number): Promise { + console.log(`Adding tag ${tagId} to blog post ${postId}`); + if (!this.blogPostTagsRelations.has(postId)) { + console.log(`Creating new tag set for blog post ${postId}`); this.blogPostTagsRelations.set(postId, new Set()); } + this.blogPostTagsRelations.get(postId)!.add(tagId); + console.log(`After adding tag, blog post ${postId} has tags:`, + Array.from(this.blogPostTagsRelations.get(postId) || new Set())); } // Bookmark methods